mirror of
https://github.com/open-goal/jak-project
synced 2026-07-11 23:30:16 -04:00
repl: cleanup startup logs when opening the REPL
This commit is contained in:
@@ -185,9 +185,11 @@ std::optional<std::string> try_get_jak_project_path() {
|
||||
return try_get_project_path_from_path(get_current_executable_path());
|
||||
}
|
||||
|
||||
std::optional<fs::path> try_get_data_dir() {
|
||||
std::optional<fs::path> 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<fs::path> try_get_data_dir() {
|
||||
}
|
||||
}
|
||||
|
||||
bool setup_project_path(std::optional<fs::path> project_path_override) {
|
||||
bool setup_project_path(std::optional<fs::path> project_path_override, bool skip_logs) {
|
||||
if (g_file_path_info.initialized) {
|
||||
return true;
|
||||
}
|
||||
@@ -204,16 +206,20 @@ bool setup_project_path(std::optional<fs::path> 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<fs::path> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::string> try_get_project_path_from_path(const std::string& path);
|
||||
bool setup_project_path(std::optional<fs::path> project_path_override);
|
||||
bool setup_project_path(std::optional<fs::path> 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<std::string>& path);
|
||||
|
||||
@@ -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"))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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/<name>/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)
|
||||
(define USE_PS3_LEVELS #f)
|
||||
|
||||
+11
-26
@@ -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> compiler;
|
||||
@@ -126,16 +111,16 @@ int main(int argc, char** argv) {
|
||||
|
||||
// Initialize nREPL server socket
|
||||
std::function<bool()> 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<Compiler>(
|
||||
game_version, std::make_optional(repl_config), username,
|
||||
std::make_unique<REPL::Wrapper>(username, repl_config, startup_file));
|
||||
std::make_unique<REPL::Wrapper>(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<Compiler>(
|
||||
game_version, std::make_optional(repl_config), username,
|
||||
std::make_unique<REPL::Wrapper>(username, repl_config, startup_file));
|
||||
std::make_unique<REPL::Wrapper>(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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ class MakeSystem {
|
||||
}
|
||||
|
||||
void clear_project();
|
||||
std::vector<std::string> 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<REPL::Config> m_repl_config;
|
||||
std::vector<std::string> m_loaded_projects;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<MakeStep>> m_output_to_step;
|
||||
std::unordered_map<std::string, std::shared_ptr<Tool>> m_tools;
|
||||
|
||||
Reference in New Issue
Block a user