From 29da94290f0624be804f95373ea06ccb3e4e104b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Wed, 22 Oct 2025 11:09:53 +0300 Subject: [PATCH] Disable some unsafe CLI arguments in template builds by default. --- SConstruct | 12 ++- core/config/project_settings.cpp | 22 ++-- main/main.cpp | 138 +++++++++++++++++++------- main/main.h | 1 + misc/dist/linux/godot.6 | 3 - misc/dist/shell/_godot.zsh-completion | 1 - misc/dist/shell/godot.bash-completion | 1 - misc/dist/shell/godot.fish | 1 - 8 files changed, 130 insertions(+), 49 deletions(-) diff --git a/SConstruct b/SConstruct index 8b12900cc20..991ab89846e 100644 --- a/SConstruct +++ b/SConstruct @@ -239,7 +239,14 @@ opts.Add(BoolVariable("disable_physics_3d", "Disable 3D physics nodes and server opts.Add(BoolVariable("disable_navigation_2d", "Disable 2D navigation features", False)) opts.Add(BoolVariable("disable_navigation_3d", "Disable 3D navigation features", False)) opts.Add(BoolVariable("disable_xr", "Disable XR nodes and server", False)) -opts.Add(BoolVariable("disable_overrides", "Disable project settings overrides and related CLI arguments", False)) +opts.Add(BoolVariable("disable_overrides", "Disable project settings overrides (override.cfg)", False)) +opts.Add( + BoolVariable( + "disable_path_overrides", + "Disable CLI arguments to override project path/main pack/scene and run scripts (export template only)", + True, + ) +) opts.Add("build_profile", "Path to a file containing a feature build profile", "") opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "") opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True)) @@ -1033,6 +1040,9 @@ if env["brotli"]: if not env["disable_overrides"]: env.Append(CPPDEFINES=["OVERRIDE_ENABLED"]) +if env.editor_build or not env["disable_path_overrides"]: + env.Append(CPPDEFINES=["OVERRIDE_PATH_ENABLED"]) + if not env["verbose"]: methods.no_verbose(env) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 37e40c83783..21f2bc4e4d0 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -632,9 +632,8 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) { * If found, load it or fail. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we * are running from source code. - * If not found and `p_upwards` is true (--upwards passed by the user), look for - * project files in parent folders up to the system root (used to run a game - * from command line while in a subfolder). + * If not found and `p_upwards` is true, look for project files in parent folders + * up to the system root (used to run a game from command line while in a subfolder). * If a project file is found, load it or fail. * If nothing was found, error out. */ @@ -731,7 +730,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b #endif // Try to use the filesystem for files, according to OS. - // (Only Android -when reading from pck- and iOS use this.) + // (Only Android -when reading from PCK-.) if (!OS::get_singleton()->get_resource_dir().is_empty()) { Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); @@ -804,6 +803,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b break; } +#if defined(OVERRIDE_PATH_ENABLED) if (p_upwards) { // Try to load settings ascending through parent directories d->change_dir(".."); @@ -812,6 +812,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b } current_dir = d->get_current_dir(); } else { +#else + { +#endif break; } } @@ -829,12 +832,17 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) { Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override); +#ifdef OVERRIDE_ENABLED if (err == OK && !p_ignore_override) { - String custom_settings = GLOBAL_GET("application/config/project_settings_override"); - if (!custom_settings.is_empty()) { - _load_settings_text(custom_settings); + bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); + if (!disable_override) { + String custom_settings = GLOBAL_GET("application/config/project_settings_override"); + if (!custom_settings.is_empty()) { + _load_settings_text(custom_settings); + } } } +#endif // Updating the default value after the project settings have loaded. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory"); diff --git a/main/main.cpp b/main/main.cpp index 1dc73e60040..ff2c07b424e 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -487,6 +487,9 @@ void Main::print_help_option(const char *p_option, const char *p_description, CL case CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG: availability_badge = "\u001b[1;94mD"; break; + case CLI_OPTION_AVAILABILITY_TEMPLATE_UNSAFE: + availability_badge = "\u001b[1;93mX"; + break; case CLI_OPTION_AVAILABILITY_TEMPLATE_RELEASE: availability_badge = "\u001b[1;92mR"; break; @@ -529,6 +532,9 @@ void Main::print_help(const char *p_binary) { #ifdef DEBUG_ENABLED OS::get_singleton()->print(" \u001b[1;94mD\u001b[0m Available in editor builds and debug export templates only.\n"); #endif +#if defined(OVERRIDE_PATH_ENABLED) + OS::get_singleton()->print(" \u001b[1;93mX\u001b[0m Only available in editor builds, and export templates compiled with `disable_path_overrides=false`.\n"); +#endif #ifdef TOOLS_ENABLED OS::get_singleton()->print(" \u001b[1;91mE\u001b[0m Only available in editor builds.\n"); #endif @@ -555,21 +561,20 @@ void Main::print_help(const char *p_binary) { print_help_option("--quit", "Quit after the first iteration.\n"); print_help_option("--quit-after ", "Quit after the given number of iterations. Set to 0 to disable.\n"); print_help_option("-l, --language ", "Use a specific locale ( being a two-letter code).\n"); - print_help_option("--path ", "Path to a project ( must contain a \"project.godot\" file).\n"); -#ifdef OVERRIDE_ENABLED - print_help_option("--scene ", "Path or UID of a scene in the project that should be started.\n"); - print_help_option("-u, --upwards", "Scan folders upwards for project.godot file.\n"); - print_help_option("--main-pack ", "Path to a pack (.pck) file to load.\n"); -#endif // OVERRIDE_ENABLED +#if defined(OVERRIDE_PATH_ENABLED) + print_help_option("--path ", "Path to a project ( must contain a \"project.godot\" file).\n", CLI_OPTION_AVAILABILITY_TEMPLATE_UNSAFE); + print_help_option("--scene ", "Path or UID of a scene in the project that should be started.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_UNSAFE); + print_help_option("--main-pack ", "Path to a pack (.pck) file to load.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_UNSAFE); +#endif // defined(OVERRIDE_PATH_ENABLED) #ifdef DISABLE_DEPRECATED print_help_option("--render-thread ", "Render thread mode (\"safe\", \"separate\").\n"); #else print_help_option("--render-thread ", "Render thread mode (\"unsafe\" [deprecated], \"safe\", \"separate\").\n"); #endif // DISABLE_DEPRECATED -#ifdef OVERRIDE_ENABLED - print_help_option("--remote-fs
", "Remote filesystem ([:] address).\n"); - print_help_option("--remote-fs-password ", "Password for remote filesystem.\n"); -#endif // OVERRIDE_ENABLED +#if defined(DEBUG_ENABLED) || defined(TOOLS_ENABLED) + print_help_option("--remote-fs
", "Remote filesystem ([:] address).\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG); + print_help_option("--remote-fs-password ", "Password for remote filesystem.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG); +#endif // defined(DEBUG_ENABLED) || defined (TOOLS_ENABLED) print_help_option("--audio-driver ", "Audio driver ["); for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) { @@ -642,9 +647,11 @@ void Main::print_help(const char *p_binary) { print_help_option("--extra-gpu-memory-tracking", "Enables additional memory tracking (see class reference for `RenderingDevice.get_driver_and_device_memory_report()` and linked methods). Currently only implemented for Vulkan. Enabling this feature may cause crashes on some systems due to buggy drivers or bugs in the Vulkan Loader. See https://github.com/godotengine/godot/issues/95967\n"); print_help_option("--accurate-breadcrumbs", "Force barriers between breadcrumbs. Useful for narrowing down a command causing GPU resets. Currently only implemented for Vulkan.\n"); #endif +#if defined(DEBUG_ENABLED) || defined(TOOLS_ENABLED) print_help_option("--remote-debug ", "Remote debug (://[:], e.g. tcp://127.0.0.1:6007).\n"); +#endif print_help_option("--single-threaded-scene", "Force scene tree to run in single-threaded mode. Sub-thread groups are disabled and run on the main thread.\n"); -#if defined(DEBUG_ENABLED) +#ifdef DEBUG_ENABLED print_help_option("--debug-collisions", "Show collision shapes when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG); print_help_option("--debug-paths", "Show path lines when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG); print_help_option("--debug-navigation", "Show navigation polygons when running the scene.\n", CLI_OPTION_AVAILABILITY_TEMPLATE_DEBUG); @@ -666,12 +673,14 @@ void Main::print_help(const char *p_binary) { print_help_option("--editor-pseudolocalization", "Enable pseudolocalization for the editor and the project manager.\n", CLI_OPTION_AVAILABILITY_EDITOR); #endif -#ifdef OVERRIDE_ENABLED +#if defined(OVERRIDE_PATH_ENABLED) || defined(TESTS_ENABLED) print_help_title("Standalone tools"); - print_help_option("-s, --script