From 4dd3e95377844906a72fce7ad961bc128fb8fc6b 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: [PATCH] Overhaul CLI argument forwarding to processes started by the editor --- editor/editor_node.cpp | 13 +++++++++---- editor/editor_run.cpp | 15 ++++++++------- editor/project_manager.cpp | 27 +++++++++++---------------- main/main.cpp | 22 ++++++++++++++++++++++ main/main.h | 10 ++++++++++ 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index db6e27d0283..9303d7d98ca 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1626,15 +1626,16 @@ void EditorNode::restart_editor() { List args; + const Vector &forwardable_args = Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL); + for (int i = 0; i < forwardable_args.size(); i++) { + args.push_back(forwardable_args[i]); + } + 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 != String()) { args.push_back(to_reopen); } @@ -3072,6 +3073,10 @@ void EditorNode::_discard_changes(const String &p_str) { String exec = OS::get_singleton()->get_executable_path(); List args; + const Vector &forwardable_args = Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL); + for (int i = 0; i < forwardable_args.size(); i++) { + args.push_back(forwardable_args[i]); + } 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 f36def07a7d..7dc30b5a76b 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -30,11 +30,11 @@ #include "editor_run.h" -#include "plugins/script_editor_plugin.h" -#include "script_editor_debugger.h" - #include "core/project_settings.h" #include "editor_settings.h" +#include "main/main.h" +#include "plugins/script_editor_plugin.h" +#include "script_editor_debugger.h" EditorRun::Status EditorRun::get_status() const { return status; @@ -47,6 +47,11 @@ String EditorRun::get_running_scene() const { Error EditorRun::run(const String &p_scene, const String &p_custom_args, const List &p_breakpoints, const bool &p_skip_breakpoints) { List args; + const Vector &forwardable_args = Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT); + for (int i = 0; i < forwardable_args.size(); i++) { + args.push_back(forwardable_args[i]); + } + String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { @@ -101,10 +106,6 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L screen -= 3; } - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - Rect2 screen_rect; screen_rect.position = OS::get_singleton()->get_screen_position(screen); screen_rect.size = OS::get_singleton()->get_screen_size(screen); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index aac729dc0e9..2cafea31db2 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -43,6 +43,7 @@ #include "editor_scale.h" #include "editor_settings.h" #include "editor_themes.h" +#include "main/main.h" #include "scene/gui/center_container.h" #include "scene/gui/line_edit.h" #include "scene/gui/margin_container.h" @@ -2015,23 +2016,16 @@ void ProjectManager::_open_selected_projects() { List args; + const Vector &forwardable_args = Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL); + for (int i = 0; i < forwardable_args.size(); i++) { + args.push_back(forwardable_args[i]); + } + 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"); - } - String exec = OS::get_singleton()->get_executable_path(); OS::ProcessID pid = 0; @@ -2115,13 +2109,14 @@ void ProjectManager::_run_project_confirm() { List args; + const Vector &forwardable_args = Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT); + for (int j = 0; j < forwardable_args.size(); j++) { + args.push_back(forwardable_args[j]); + } + args.push_back("--path"); args.push_back(path); - if (OS::get_singleton()->is_disable_crash_handler()) { - args.push_back("--disable-crash-handler"); - } - String exec = OS::get_singleton()->get_executable_path(); OS::ProcessID pid = 0; diff --git a/main/main.cpp b/main/main.cpp index 37ef4332d2a..c67e8b0baf5 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -135,6 +135,8 @@ static bool delta_sync_after_draw = false; #ifdef TOOLS_ENABLED static bool auto_build_solutions = false; static String debug_server_uri; + +HashMap> forwardable_cli_arguments; #endif // Display @@ -171,6 +173,12 @@ bool Main::is_project_manager() { return project_manager; } +#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", " "); } @@ -494,6 +502,20 @@ 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() == "--video-driver") { + forwardable_cli_arguments[CLI_SCOPE_TOOL].push_back(I->get()); + } +#endif + if (I->get() == "-h" || I->get() == "--help" || I->get() == "/?") { // display help show_help = true; diff --git a/main/main.h b/main/main.h index 6cbfa7510a2..b6751633d83 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,13 @@ class Main { public: static bool is_project_manager(); +#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 Error setup(const char *execpath, int argc, char *argv[], bool p_second_phase = true); static Error setup2(Thread::ID p_main_tid_override = 0);