Overhaul CLI argument forwarding to processes started by the editor

This commit is contained in:
Pedro J. Estébanez 2022-08-13 21:52:03 +02:00
parent 1806e414b8
commit 4dd3e95377
5 changed files with 60 additions and 27 deletions

View file

@ -1626,15 +1626,16 @@ void EditorNode::restart_editor() {
List<String> args;
const Vector<String> &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<String> args;
const Vector<String> &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");

View file

@ -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<String> &p_breakpoints, const bool &p_skip_breakpoints) {
List<String> args;
const Vector<String> &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);

View file

@ -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<String> args;
const Vector<String> &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<String> args;
const Vector<String> &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;

View file

@ -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<Main::CLIScope, Vector<String>> forwardable_cli_arguments;
#endif
// Display
@ -171,6 +173,12 @@ bool Main::is_project_manager() {
return project_manager;
}
#ifdef TOOLS_ENABLED
const Vector<String> &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<String>::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;

View file

@ -35,6 +35,9 @@
#include "core/os/thread.h"
#include "core/typedefs.h"
template <class T>
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<String> &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);