From 7dbacc72d3a561fad2863ccf74446d48e3bdb4fd Mon Sep 17 00:00:00 2001 From: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:03:14 -0400 Subject: [PATCH] Parameterize the iso_data folder for goalc (#3692) I hope this is everything I needed, and nothing I didn't. ## What's Changed This update adds a command-line parameter to goalc, `--iso-path`. Providing a path to a directory like `D:\Files\Repositories\ArchipelaGOAL\iso_data\jak1` will inform the compiler to use that directory instead. ## Why is this useful? When combined with `--proj-path`, the compiler can be pointed to a completely different project folder, given the `(mi)` command, and immediately begin building from that directory, with everything it needs. This eliminates the need to copy `iso_data` to multiple `data` directories. If a subsequent change to the Launcher is made, each mod could be passed an --iso-path pointing to a single shared folder, allowing mods to each run their own REPL _without_ requiring a copy of `iso_data` in a subfolder. ## Independent testing required! My local repositories are a little suspect, with a mod, a fork of mod-base, and a fork of jak-project, all on the same drive. My decompiler_out and iso_data folders are in the mod repo, not mod-base nor jak-project. So what I did was make the change in the mod-base fork, point `--proj-path and --iso-path` to the mod folders, and then ran `(mi)`. The output showed a build starting with no errors. Then I had to create this PR, which my fork of mod-base is unable to do, so I created a patch file, forked jak-project, then applied the patch there. All this is to say that it would be preferable if someone could apply this code to their own installation and see if it works. Even I wouldn't take my own word for this. --------- Co-authored-by: Tyler Wilding --- .github/workflows/compiler-output-check.yaml | 8 +++---- common/repl/config.h | 1 + common/repl/repl_wrapper.cpp | 24 +++++++++++++------- goalc/main.cpp | 12 ++++++++++ goalc/make/MakeSystem.cpp | 10 ++++++-- goalc/make/MakeSystem.h | 1 + 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/workflows/compiler-output-check.yaml b/.github/workflows/compiler-output-check.yaml index 7daab005da..969ed247c1 100644 --- a/.github/workflows/compiler-output-check.yaml +++ b/.github/workflows/compiler-output-check.yaml @@ -29,8 +29,8 @@ jobs: uses: hendrikmuhs/ccache-action@v1.2.14 with: variant: sccache - key: linux-ubuntu-20.04--Release-linux-clang-asan-${{ github.sha }} - restore-keys: linux-ubuntu-20.04--Release-linux-clang-asan + key: linux-ubuntu-20.04--Release-linux-clang-static-${{ github.sha }} + restore-keys: linux-ubuntu-20.04--Release-linux-clang-static max-size: 1000M - name: CMake Generation (master) @@ -38,7 +38,7 @@ jobs: CC: clang CXX: clang++ run: | - cmake -B build --preset=Release-linux-clang-asan \ + cmake -B build --preset=Release-linux-clang-static \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache @@ -57,7 +57,7 @@ jobs: CC: clang CXX: clang++ run: | - cmake -B build --preset=Release-linux-clang-asan \ + cmake -B build --preset=Release-linux-clang-static \ -DCMAKE_C_COMPILER_LAUNCHER=sccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=sccache diff --git a/common/repl/config.h b/common/repl/config.h index ff1857be72..c0a5334ffa 100644 --- a/common/repl/config.h +++ b/common/repl/config.h @@ -49,6 +49,7 @@ struct Config { {KeyBind::Modifier::CTRL, "N", "Full build of the game", "(mi)"}}; bool per_game_history = true; bool permissive_redefinitions = false; + std::string iso_path; int get_nrepl_port() { if (temp_nrepl_port != -1) { diff --git a/common/repl/repl_wrapper.cpp b/common/repl/repl_wrapper.cpp index fd2b517dec..d85be66fdb 100644 --- a/common/repl/repl_wrapper.cpp +++ b/common/repl/repl_wrapper.cpp @@ -43,6 +43,15 @@ void Wrapper::print_welcome_message(const std::vector& loaded_proje fmt::format(" Project Path: {}\n", fmt::format(fg(fmt::color::gray), file_util::get_jak_project_dir().string())); message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " - :===: -"); + std::string effective_iso_path; + if (repl_config.iso_path.empty()) { + effective_iso_path = file_util::get_file_path({"iso_data"}); + } else { + effective_iso_path = repl_config.iso_path; + } + message += + fmt::format(" ISO Data Path: {}\n", fmt::format(fg(fmt::color::gray), effective_iso_path)); + message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " --. .--: :--. .--"); message += " nREPL:"; if (!nrepl_alive) { message += fmt::format(fg(fmt::color::red), "DISABLED\n"); @@ -50,22 +59,21 @@ void Wrapper::print_welcome_message(const std::vector& loaded_proje message += fmt::format(fg(fmt::color::light_green), " Listening on {}\n", repl_config.get_nrepl_port()); } - message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " --. .--: :--. .--"); + message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .=======. =======."); message += " Source File Search Dirs: "; const auto search_dir_string = fmt::format("{}", fmt::join(repl_config.asm_file_search_dirs, ",")); message += fmt::format("[{}]\n", fmt::format(fg(fmt::color::gray), search_dir_string)); - message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .=======. =======."); - message += fmt::format(" {} or {} for basic help and usage\n", + message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .-=====-. .-=====-"); + message += fmt::format(" {} or {} for basic help and usage\n", fmt::format(fg(fmt::color::cyan), "(repl-help)"), fmt::format(fg(fmt::color::cyan), "(repl-keybinds)")); - message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .-=====-. .-=====-"); - message += - fmt::format(" {} to connect to the game\n", fmt::format(fg(fmt::color::cyan), "(lt)")); message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .-===========-."); - message += fmt::format(" {} to recompile the active project.\n", + message += + fmt::format(" {} to connect to the game\n", fmt::format(fg(fmt::color::cyan), "(lt)")); + message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .-===-."); + message += fmt::format(" {} to recompile the active project.\n", fmt::format(fg(fmt::color::cyan), "(mi)")); - message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .-===-.\n"); message += fmt::format(fmt::emphasis::bold | fg(fmt::color::orange), " .\n"); fmt::print("{}", message); } diff --git a/goalc/main.cpp b/goalc/main.cpp index c5ec7c8d3b..77fe79bfbd 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -37,6 +37,7 @@ int main(int argc, char** argv) { std::string game = "jak1"; int nrepl_port = -1; fs::path project_path_override; + fs::path iso_path_override; // TODO - a lot of these flags could be deprecated and moved into `repl-config.json` CLI::App app{"OpenGOAL Compiler / REPL"}; @@ -49,6 +50,7 @@ int main(int argc, char** argv) { app.add_option("-g,--game", game, "The game name: 'jak1' or 'jak2'"); app.add_option("--proj-path", project_path_override, "Specify the location of the 'data/' folder"); + app.add_option("--iso-path", iso_path_override, "Specify the location of the 'iso_data/' folder"); define_common_cli_arguments(app); app.validate_positionals(); CLI11_PARSE(app, argc, argv); @@ -84,6 +86,16 @@ int main(int argc, char** argv) { // Load the user's REPL config auto repl_config = REPL::load_repl_config(username, game_version, nrepl_port); + // Check for a custom ISO path before we instantiate the compiler. + if (!iso_path_override.empty()) { + if (!fs::exists(iso_path_override)) { + lg::error("Error: iso path override '{}' does not exist", iso_path_override.string()); + return 1; + } + file_util::set_iso_data_dir(iso_path_override); + repl_config.iso_path = iso_path_override.string(); + } + // Init Compiler std::unique_ptr compiler; std::mutex compiler_mutex; diff --git a/goalc/make/MakeSystem.cpp b/goalc/make/MakeSystem.cpp index 982e8e3dd6..dfa29b7d0e 100644 --- a/goalc/make/MakeSystem.cpp +++ b/goalc/make/MakeSystem.cpp @@ -91,8 +91,14 @@ MakeSystem::MakeSystem(const std::optional repl_config, const std: m_goos.set_global_variable_to_symbol("ASSETS", "#t"); - set_constant("*iso-data*", file_util::get_file_path({"iso_data"})); - set_constant("*use-iso-data-path*", false); + if (m_repl_config && !m_repl_config->iso_path.empty()) { + set_constant("*iso-data*", + file_util::get_iso_dir_for_game(m_repl_config->game_version).string()); + set_constant("*use-iso-data-path*", true); + } else { + set_constant("*iso-data*", file_util::get_file_path({"iso_data"})); + set_constant("*use-iso-data-path*", false); + } add_tool(); add_tool(); diff --git a/goalc/make/MakeSystem.h b/goalc/make/MakeSystem.h index cba37ebf77..1eef3174b6 100644 --- a/goalc/make/MakeSystem.h +++ b/goalc/make/MakeSystem.h @@ -1,6 +1,7 @@ #pragma once #include "common/goos/Interpreter.h" +#include "common/util/FileUtil.h" #include "goalc/make/Tool.h"