From 3bc7662cc13ffc484a5d71a97716b4d6a724f127 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sun, 2 Jun 2024 12:51:14 -0400 Subject: [PATCH] repl: cleanup startup logs when opening the REPL --- common/util/FileUtil.cpp | 24 ++++++++++++++++-------- common/util/FileUtil.h | 2 +- goal_src/goal-lib.gc | 3 --- goal_src/goos-lib.gs | 4 ++-- goalc/main.cpp | 37 +++++++++++-------------------------- goalc/make/MakeSystem.cpp | 4 +++- goalc/make/MakeSystem.h | 2 ++ 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/common/util/FileUtil.cpp b/common/util/FileUtil.cpp index b6b4768dcd..f150801cc1 100644 --- a/common/util/FileUtil.cpp +++ b/common/util/FileUtil.cpp @@ -185,9 +185,11 @@ std::optional try_get_jak_project_path() { return try_get_project_path_from_path(get_current_executable_path()); } -std::optional try_get_data_dir() { +std::optional try_get_data_dir(bool skip_logs) { fs::path my_path = get_current_executable_path(); - lg::info("Current executable directory - {}", my_path.string()); + if (!skip_logs) { + lg::debug("Current executable directory - {}", my_path.string()); + } auto data_dir = my_path.parent_path() / "data"; if (fs::exists(data_dir) && fs::is_directory(data_dir)) { return std::make_optional(data_dir); @@ -196,7 +198,7 @@ std::optional try_get_data_dir() { } } -bool setup_project_path(std::optional project_path_override) { +bool setup_project_path(std::optional project_path_override, bool skip_logs) { if (g_file_path_info.initialized) { return true; } @@ -204,16 +206,20 @@ bool setup_project_path(std::optional project_path_override) { if (project_path_override) { g_file_path_info.path_to_data_folder = fs::absolute(project_path_override.value()); g_file_path_info.initialized = true; - lg::info("Using explicitly set project path: {}", - g_file_path_info.path_to_data_folder.string()); + if (!skip_logs) { + lg::debug("Using explicitly set project path: {}", + g_file_path_info.path_to_data_folder.string()); + } return true; } - auto data_path = try_get_data_dir(); + auto data_path = try_get_data_dir(skip_logs); if (data_path) { g_file_path_info.path_to_data_folder = *data_path; g_file_path_info.initialized = true; - lg::info("Using data path: {}", data_path->string()); + if (!skip_logs) { + lg::debug("Using data path: {}", data_path->string()); + } return true; } @@ -221,7 +227,9 @@ bool setup_project_path(std::optional project_path_override) { if (development_repo_path) { g_file_path_info.path_to_data_folder = *development_repo_path; g_file_path_info.initialized = true; - lg::info("Using development repo path: {}", *development_repo_path); + if (!skip_logs) { + lg::debug("Using development repo path: {}", *development_repo_path); + } return true; } diff --git a/common/util/FileUtil.h b/common/util/FileUtil.h index dcaecdd2e8..16875c77bf 100644 --- a/common/util/FileUtil.h +++ b/common/util/FileUtil.h @@ -43,7 +43,7 @@ bool create_dir_if_needed_for_file(const std::string& path); bool create_dir_if_needed_for_file(const fs::path& path); std::string get_current_executable_path(); std::optional try_get_project_path_from_path(const std::string& path); -bool setup_project_path(std::optional project_path_override); +bool setup_project_path(std::optional project_path_override, bool skip_logs = false); void override_user_config_dir(fs::path user_config_dir_override, bool use_overridden_config_dir_for_saves); std::string get_file_path(const std::vector& path); diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index 440c942e7c..6f67b58f6a 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -1263,14 +1263,11 @@ (#cond ((eq? GAME_VERSION 'jak1) (asm-file "goal_src/jak1/compiler-setup.gc") - (seval (fmt #t "Jak 1 Mode\n")) ) ((eq? GAME_VERSION 'jak2) (asm-file "goal_src/jak2/compiler-setup.gc") - (seval (fmt #t "Jak 2 Mode\n")) ) ((eq? GAME_VERSION 'jak3) (asm-file "goal_src/jak3/compiler-setup.gc") - (seval (fmt #t "Jak 3 Mode\n")) ) ) diff --git a/goal_src/goos-lib.gs b/goal_src/goos-lib.gs index 8624807ba5..97a77606cf 100644 --- a/goal_src/goos-lib.gs +++ b/goal_src/goos-lib.gs @@ -471,7 +471,7 @@ ;; *user* is defined when goos starts! (when *user* - (fmt #t "Loading user scripts for user: {}...\n" *user*) + ;; (fmt #t "Loading user scripts for user: {}...\n" *user*) ;; i'm not sure what naming scheme to use here. user//user.gs? ;; the GOAL one is loaded in Compiler.cpp (try-load-file (fmt #f "goal_src/user/{}/user.gs" *user*)) @@ -512,4 +512,4 @@ (define *default-territory* GAME_TERRITORY_SCEA) ;; whether to enable ps3 test levels for jak 2 -(define USE_PS3_LEVELS #f) \ No newline at end of file +(define USE_PS3_LEVELS #f) diff --git a/goalc/main.cpp b/goalc/main.cpp index e8f5c0d446..c5ec7c8d3b 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -18,13 +18,13 @@ #include "third-party/CLI11.hpp" void setup_logging(const bool disable_ansi_colors) { - lg::set_file("compiler"); lg::set_file_level(lg::level::info); lg::set_stdout_level(lg::level::info); lg::set_flush_level(lg::level::info); if (disable_ansi_colors) { lg::disable_ansi_colors(); } + lg::set_file("compiler"); lg::initialize(); } @@ -39,13 +39,11 @@ int main(int argc, char** argv) { fs::path project_path_override; // TODO - a lot of these flags could be deprecated and moved into `repl-config.json` - // TODO - auto-find the user if there is only one folder within `user/` CLI::App app{"OpenGOAL Compiler / REPL"}; app.add_option("-c,--cmd", cmd, "Specify a command to run, no REPL is launched in this mode"); app.add_option("-u,--user", username, "Specify the username to use for your user profile in 'goal_src/user/'"); - app.add_option("-p,--port", nrepl_port, - "Specify the nREPL port. Defaults to 8181 for Jak 1 and 8182 for Jak 2"); + app.add_option("-p,--port", nrepl_port, "Specify the nREPL port. Defaults to 8181"); app.add_flag("--user-auto", auto_find_user, "Attempt to automatically deduce the user, overrides '--user'"); app.add_option("-g,--game", game, "The game name: 'jak1' or 'jak2'"); @@ -56,28 +54,17 @@ int main(int argc, char** argv) { CLI11_PARSE(app, argc, argv); GameVersion game_version = game_name_to_version(game); - if (nrepl_port == -1) { - switch (game_version) { - default: - case GameVersion::Jak1: - nrepl_port = 8181; - break; - case GameVersion::Jak2: - nrepl_port = 8182; - break; - } - } if (!project_path_override.empty()) { if (!fs::exists(project_path_override)) { lg::error("Error: project path override '{}' does not exist", project_path_override.string()); return 1; } - if (!file_util::setup_project_path(project_path_override)) { + if (!file_util::setup_project_path(project_path_override, true)) { lg::error("Could not setup project path!"); return 1; } - } else if (!file_util::setup_project_path(std::nullopt)) { + } else if (!file_util::setup_project_path(std::nullopt, true)) { return 1; } @@ -88,8 +75,6 @@ int main(int argc, char** argv) { return 1; } - lg::info("OpenGOAL Compiler {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); - // Figure out the username if (auto_find_user) { username = REPL::find_repl_username(); @@ -97,7 +82,7 @@ int main(int argc, char** argv) { // Load the user's startup file auto startup_file = REPL::load_user_startup_file(username, game_version); // Load the user's REPL config - auto repl_config = REPL::load_repl_config(username, game_version); + auto repl_config = REPL::load_repl_config(username, game_version, nrepl_port); // Init Compiler std::unique_ptr compiler; @@ -126,16 +111,16 @@ int main(int argc, char** argv) { // Initialize nREPL server socket std::function shutdown_callback = [&]() { return status == ReplStatus::WANT_EXIT; }; - ReplServer repl_server(shutdown_callback, nrepl_port); - bool repl_server_ok = repl_server.init_server(); + ReplServer repl_server(shutdown_callback, repl_config.get_nrepl_port()); + bool nrepl_server_ok = repl_server.init_server(true); std::thread nrepl_thread; // the compiler may throw an exception if it fails to load its standard library. try { compiler = std::make_unique( game_version, std::make_optional(repl_config), username, - std::make_unique(username, repl_config, startup_file)); + std::make_unique(username, repl_config, startup_file, nrepl_server_ok)); // Start nREPL Server if it spun up successfully - if (repl_server_ok) { + if (nrepl_server_ok) { nrepl_thread = std::thread([&]() { while (!shutdown_callback()) { auto resp = repl_server.get_msg(); @@ -161,7 +146,7 @@ int main(int argc, char** argv) { } compiler = std::make_unique( game_version, std::make_optional(repl_config), username, - std::make_unique(username, repl_config, startup_file)); + std::make_unique(username, repl_config, startup_file, nrepl_server_ok)); status = ReplStatus::OK; } // process user input @@ -180,7 +165,7 @@ int main(int argc, char** argv) { // TODO - investigate why there is such a delay when exitting // Cleanup - if (repl_server_ok) { + if (nrepl_server_ok) { repl_server.shutdown_server(); nrepl_thread.join(); } diff --git a/goalc/make/MakeSystem.cpp b/goalc/make/MakeSystem.cpp index 2a0e2d8475..982e8e3dd6 100644 --- a/goalc/make/MakeSystem.cpp +++ b/goalc/make/MakeSystem.cpp @@ -119,8 +119,9 @@ void MakeSystem::load_project_file(const std::string& file_path) { auto data = m_goos.reader.read_from_file({file_path}); // interpret it, which will call various handlers. m_goos.eval(data, m_goos.global_environment.as_env_ptr()); - lg::print("Loaded project {} with {} steps in {} ms\n", file_path, m_output_to_step.size(), + lg::debug("Loaded project {} with {} steps in {} ms\n", file_path, m_output_to_step.size(), (int)timer.getMs()); + m_loaded_projects.push_back(file_path); } goos::Object MakeSystem::handle_defstep(const goos::Object& form, @@ -187,6 +188,7 @@ goos::Object MakeSystem::handle_defstep(const goos::Object& form, * */ void MakeSystem::clear_project() { + m_loaded_projects.clear(); m_output_to_step.clear(); } diff --git a/goalc/make/MakeSystem.h b/goalc/make/MakeSystem.h index 413a072596..cba37ebf77 100644 --- a/goalc/make/MakeSystem.h +++ b/goalc/make/MakeSystem.h @@ -70,6 +70,7 @@ class MakeSystem { } void clear_project(); + std::vector get_loaded_projects() const { return m_loaded_projects; } /*! * Get the prefix that the project has requested for all compiler outputs @@ -91,6 +92,7 @@ class MakeSystem { goos::Interpreter m_goos; std::optional m_repl_config; + std::vector m_loaded_projects; std::unordered_map> m_output_to_step; std::unordered_map> m_tools;