From e886d662ec2580c9b19c44296d0bb64fbf635ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Sat, 13 Aug 2022 21:52:03 +0200 Subject: Overhaul CLI argument forwarding to processes started by the editor --- core/os/os.cpp | 4 ---- core/os/os.h | 3 --- editor/editor_node.cpp | 11 +++++++---- editor/editor_run.cpp | 9 +++++---- editor/project_manager.cpp | 29 +++++++++-------------------- main/main.cpp | 28 ++++++++++++++++++++++++++-- main/main.h | 11 +++++++++++ platform/javascript/os_javascript.h | 1 - 8 files changed, 58 insertions(+), 38 deletions(-) diff --git a/core/os/os.cpp b/core/os/os.cpp index 1358c926d1..6091079241 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -166,10 +166,6 @@ bool OS::is_stdout_verbose() const { return _verbose_stdout; } -bool OS::is_single_window() const { - return _single_window; -} - bool OS::is_stdout_debug_enabled() const { return _debug_stdout; } diff --git a/core/os/os.h b/core/os/os.h index 9152b797ef..be9d73c22d 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -52,7 +52,6 @@ class OS { int low_processor_usage_mode_sleep_usec = 10000; bool _verbose_stdout = false; bool _debug_stdout = false; - bool _single_window = false; String _local_clipboard; int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure bool _allow_hidpi = false; @@ -243,8 +242,6 @@ public: void set_stdout_enabled(bool p_enabled); void set_stderr_enabled(bool p_enabled); - virtual bool is_single_window() const; - virtual void disable_crash_handler() {} virtual bool is_disable_crash_handler() const { return false; } virtual void initialize_debugging() {} diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e7946f56da..211258d953 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1815,15 +1815,15 @@ void EditorNode::restart_editor() { List args; + for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) { + args.push_back(a); + } + args.push_back("--path"); args.push_back(ProjectSettings::get_singleton()->get_resource_path()); args.push_back("-e"); - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - if (!to_reopen.is_empty()) { args.push_back(to_reopen); } @@ -3162,6 +3162,9 @@ void EditorNode::_discard_changes(const String &p_str) { String exec = OS::get_singleton()->get_executable_path(); List args; + for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) { + args.push_back(a); + } args.push_back("--path"); args.push_back(exec.get_base_dir()); args.push_back("--project-manager"); diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index 6ce8625daa..3b828951e4 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -33,6 +33,7 @@ #include "core/config/project_settings.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "main/main.h" #include "servers/display_server.h" EditorRun::Status EditorRun::get_status() const { @@ -46,6 +47,10 @@ String EditorRun::get_running_scene() const { Error EditorRun::run(const String &p_scene, const String &p_write_movie) { List args; + for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) { + args.push_back(a); + } + String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (!resource_path.is_empty()) { args.push_back("--path"); @@ -105,10 +110,6 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) { screen -= 3; } - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - Rect2 screen_rect; screen_rect.position = DisplayServer::get_singleton()->screen_get_position(screen); screen_rect.size = DisplayServer::get_singleton()->screen_get_size(screen); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 21891e381b..d9f21e1e5f 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -47,6 +47,7 @@ #include "editor/editor_settings.h" #include "editor/editor_themes.h" #include "editor/editor_vcs_interface.h" +#include "main/main.h" #include "scene/gui/center_container.h" #include "scene/gui/line_edit.h" #include "scene/gui/margin_container.h" @@ -2109,27 +2110,15 @@ void ProjectManager::_open_selected_projects() { List args; + for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) { + args.push_back(a); + } + args.push_back("--path"); args.push_back(path); args.push_back("--editor"); - if (OS::get_singleton()->is_stdout_debug_enabled()) { - args.push_back("--debug"); - } - - if (OS::get_singleton()->is_stdout_verbose()) { - args.push_back("--verbose"); - } - - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - - if (OS::get_singleton()->is_single_window()) { - args.push_back("--single-window"); - } - Error err = OS::get_singleton()->create_instance(args); ERR_FAIL_COND(err); } @@ -2242,13 +2231,13 @@ void ProjectManager::_run_project_confirm() { List args; + for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) { + args.push_back(a); + } + args.push_back("--path"); args.push_back(path); - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - Error err = OS::get_singleton()->create_instance(args); ERR_FAIL_COND(err); } diff --git a/main/main.cpp b/main/main.cpp index 965fcc66c6..61d88254f1 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -143,6 +143,7 @@ static int audio_driver_idx = -1; // Engine config/tools +static bool single_window = false; static bool editor = false; static bool project_manager = false; static bool cmdline_tool = false; @@ -153,6 +154,8 @@ static OS::ProcessID editor_pid = 0; #ifdef TOOLS_ENABLED static bool auto_build_solutions = false; static String debug_server_uri; + +HashMap> forwardable_cli_arguments; #endif // Display @@ -196,6 +199,12 @@ bool Main::is_cmdline_tool() { return cmdline_tool; } +#ifdef TOOLS_ENABLED +const Vector &Main::get_forwardable_cli_arguments(Main::CLIScope p_scope) { + return forwardable_cli_arguments[p_scope]; +} +#endif + static String unescape_cmdline(const String &p_str) { return p_str.replace("%20", " "); } @@ -703,6 +712,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph List::Element *N = I->next(); +#ifdef TOOLS_ENABLED + if (I->get() == "--debug" || + I->get() == "--verbose" || + I->get() == "--disable-crash-handler") { + forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(I->get()); + forwardable_cli_arguments[CLI_SCOPE_PROJECT].push_back(I->get()); + } + if (I->get() == "--single-window" || + I->get() == "--audio-driver" || + I->get() == "--display-driver" || + I->get() == "--rendering-driver") { + forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(I->get()); + } +#endif + if (adding_user_args) { user_args.push_back(I->get()); } else if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // display help @@ -881,7 +905,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } } else if (I->get() == "--single-window") { // force single window - OS::get_singleton()->_single_window = true; + single_window = true; } else if (I->get() == "-t" || I->get() == "--always-on-top") { // force always-on-top window init_always_on_top = true; @@ -2446,7 +2470,7 @@ bool Main::start() { bool embed_subwindows = GLOBAL_DEF("display/window/subwindows/embed_subwindows", true); - if (OS::get_singleton()->is_single_window() || (!project_manager && !editor && embed_subwindows) || !DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) { + if (single_window || (!project_manager && !editor && embed_subwindows) || !DisplayServer::get_singleton()->has_feature(DisplayServer::Feature::FEATURE_SUBWINDOWS)) { sml->get_root()->set_embedding_subwindows(true); } diff --git a/main/main.h b/main/main.h index d1870ab8df..f0bfe69b34 100644 --- a/main/main.h +++ b/main/main.h @@ -35,6 +35,9 @@ #include "core/os/thread.h" #include "core/typedefs.h" +template +class Vector; + class Main { static void print_help(const char *p_binary); static uint64_t last_ticks; @@ -47,6 +50,14 @@ class Main { public: static bool is_cmdline_tool(); +#ifdef TOOLS_ENABLED + enum CLIScope { + CLI_SCOPE_TOOL, // Editor and project manager. + CLI_SCOPE_PROJECT, + }; + static const Vector &get_forwardable_cli_arguments(CLIScope p_scope); +#endif + static int test_entrypoint(int argc, char *argv[], bool &tests_need_run); static Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true); static Error setup2(Thread::ID p_main_tid_override = 0); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 35e13c94fc..d932745177 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -98,7 +98,6 @@ public: String get_user_data_dir() const override; bool is_userfs_persistent() const override; - bool is_single_window() const override { return true; } void alert(const String &p_alert, const String &p_title = "ALERT!") override; -- cgit v1.2.3