Skip to content

Commit 0091d30

Browse files
committed
Merge pull request #108818 from bruvzg/no_cli_over
Add project setting and build option to disable `override.cfg` and related CLI arguments.
2 parents 7c03300 + 1211cd8 commit 0091d30

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

SConstruct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ opts.Add(BoolVariable("disable_physics_3d", "Disable 3D physics nodes and server
239239
opts.Add(BoolVariable("disable_navigation_2d", "Disable 2D navigation features", False))
240240
opts.Add(BoolVariable("disable_navigation_3d", "Disable 3D navigation features", False))
241241
opts.Add(BoolVariable("disable_xr", "Disable XR nodes and server", False))
242+
opts.Add(BoolVariable("disable_overrides", "Disable project settings overrides and related CLI arguments", False))
242243
opts.Add("build_profile", "Path to a file containing a feature build profile", "")
243244
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
244245
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
@@ -1035,6 +1036,9 @@ if env["minizip"]:
10351036
if env["brotli"]:
10361037
env.Append(CPPDEFINES=["BROTLI_ENABLED"])
10371038

1039+
if not env["disable_overrides"]:
1040+
env.Append(CPPDEFINES=["OVERRIDE_ENABLED"])
1041+
10381042
if not env["verbose"]:
10391043
methods.no_verbose(env)
10401044

core/config/project_settings.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,16 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
648648
ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
649649

650650
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
651+
#ifdef OVERRIDE_ENABLED
651652
if (err == OK && !p_ignore_override) {
652653
// Load override from location of the main pack
653654
// Optional, we don't mind if it fails
654-
_load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
655+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
656+
if (!disable_override) {
657+
_load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
658+
}
655659
}
660+
#endif // OVERRIDE_ENABLED
656661
return err;
657662
}
658663

@@ -698,12 +703,17 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
698703
// If we opened our package, try and load our project.
699704
if (found) {
700705
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
706+
#ifdef OVERRIDE_ENABLED
701707
if (err == OK && !p_ignore_override) {
702708
// Load overrides from the PCK and the executable location.
703709
// Optional, we don't mind if either fails.
704-
_load_settings_text("res://override.cfg");
705-
_load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
710+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
711+
if (!disable_override) {
712+
_load_settings_text("res://override.cfg");
713+
_load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
714+
}
706715
}
716+
#endif // OVERRIDE_ENABLED
707717
return err;
708718
}
709719
}
@@ -718,10 +728,15 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
718728

719729
if (!OS::get_singleton()->get_resource_dir().is_empty()) {
720730
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
731+
#ifdef OVERRIDE_ENABLED
721732
if (err == OK && !p_ignore_override) {
722733
// Optional, we don't mind if it fails.
723-
_load_settings_text("res://override.cfg");
734+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
735+
if (!disable_override) {
736+
_load_settings_text("res://override.cfg");
737+
}
724738
}
739+
#endif // OVERRIDE_ENABLED
725740
return err;
726741
}
727742

@@ -741,11 +756,16 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
741756
err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary"));
742757
if (err == OK && !p_ignore_override) {
743758
// Optional, we don't mind if it fails.
744-
_load_settings_text(resource_path.path_join("override.cfg"));
759+
#ifdef OVERRIDE_ENABLED
760+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
761+
if (!disable_override) {
762+
_load_settings_text(resource_path.path_join("override.cfg"));
763+
}
764+
#endif // OVERRIDE_ENABLED
745765
return err;
746766
}
747767
}
748-
#endif
768+
#endif // MACOS_ENABLED
749769

750770
// Nothing was found, try to find a project file in provided path (`p_path`)
751771
// or, if requested (`p_upwards`) in parent directories.
@@ -765,7 +785,12 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
765785
err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
766786
if (err == OK && !p_ignore_override) {
767787
// Optional, we don't mind if it fails.
768-
_load_settings_text(current_dir.path_join("override.cfg"));
788+
#ifdef OVERRIDE_ENABLED
789+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
790+
if (!disable_override) {
791+
_load_settings_text(current_dir.path_join("override.cfg"));
792+
}
793+
#endif // OVERRIDE_ENABLED
769794
found = true;
770795
break;
771796
}
@@ -1574,6 +1599,7 @@ ProjectSettings::ProjectSettings() {
15741599
GLOBAL_DEF("application/config/use_custom_user_dir", false);
15751600
GLOBAL_DEF("application/config/custom_user_dir_name", "");
15761601
GLOBAL_DEF("application/config/project_settings_override", "");
1602+
GLOBAL_DEF("application/config/disable_project_settings_override", false);
15771603

15781604
GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
15791605
GLOBAL_DEF("application/config/auto_accept_quit", true);

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@
307307
<member name="application/config/description" type="String" setter="" getter="" default="&quot;&quot;">
308308
The project's description, displayed as a tooltip in the Project Manager when hovering the project.
309309
</member>
310+
<member name="application/config/disable_project_settings_override" type="bool" setter="" getter="" default="false">
311+
If [code]true[/code], disables loading of project settings overrides (file defined in [member application/config/project_settings_override] and [code]res://override.cfg[/code]) and related CLI arguments.
312+
</member>
310313
<member name="application/config/icon" type="String" setter="" getter="" default="&quot;&quot;">
311314
Icon used for the project, set when project loads. Exporters will also use this icon as a fallback if necessary.
312315
</member>

main/main.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,20 @@ void Main::print_help(const char *p_binary) {
556556
print_help_option("--quit-after <int>", "Quit after the given number of iterations. Set to 0 to disable.\n");
557557
print_help_option("-l, --language <locale>", "Use a specific locale (<locale> being a two-letter code).\n");
558558
print_help_option("--path <directory>", "Path to a project (<directory> must contain a \"project.godot\" file).\n");
559+
#ifdef OVERRIDE_ENABLED
559560
print_help_option("--scene <path>", "Path or UID of a scene in the project that should be started.\n");
560561
print_help_option("-u, --upwards", "Scan folders upwards for project.godot file.\n");
561562
print_help_option("--main-pack <file>", "Path to a pack (.pck) file to load.\n");
563+
#endif // OVERRIDE_ENABLED
562564
#ifdef DISABLE_DEPRECATED
563565
print_help_option("--render-thread <mode>", "Render thread mode (\"safe\", \"separate\").\n");
564566
#else
565567
print_help_option("--render-thread <mode>", "Render thread mode (\"unsafe\" [deprecated], \"safe\", \"separate\").\n");
566-
#endif
568+
#endif // DISABLE_DEPRECATED
569+
#ifdef OVERRIDE_ENABLED
567570
print_help_option("--remote-fs <address>", "Remote filesystem (<host/IP>[:<port>] address).\n");
568571
print_help_option("--remote-fs-password <password>", "Password for remote filesystem.\n");
572+
#endif // OVERRIDE_ENABLED
569573

570574
print_help_option("--audio-driver <driver>", "Audio driver [");
571575
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
@@ -662,10 +666,12 @@ void Main::print_help(const char *p_binary) {
662666
print_help_option("--editor-pseudolocalization", "Enable pseudolocalization for the editor and the project manager.\n", CLI_OPTION_AVAILABILITY_EDITOR);
663667
#endif
664668

669+
#ifdef OVERRIDE_ENABLED
665670
print_help_title("Standalone tools");
666671
print_help_option("-s, --script <script>", "Run a script.\n");
667672
print_help_option("--main-loop <main_loop_name>", "Run a MainLoop specified by its global class name.\n");
668673
print_help_option("--check-only", "Only parse for errors and quit (use with --script).\n");
674+
#endif // OVERRIDE_ENABLED
669675
#ifdef TOOLS_ENABLED
670676
print_help_option("--import", "Starts the editor, waits for any resources to be imported, and then quits.\n", CLI_OPTION_AVAILABILITY_EDITOR);
671677
print_help_option("--export-release <preset> <path>", "Export the project in release mode using the given preset and output path. The preset name should match one defined in \"export_presets.cfg\".\n", CLI_OPTION_AVAILABILITY_EDITOR);
@@ -1432,7 +1438,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
14321438
OS::get_singleton()->print("Missing language argument, aborting.\n");
14331439
goto error;
14341440
}
1435-
1441+
#ifdef OVERRIDE_ENABLED
14361442
} else if (arg == "--remote-fs") { // remote filesystem
14371443

14381444
if (N) {
@@ -1451,6 +1457,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
14511457
OS::get_singleton()->print("Missing remote filesystem password, aborting.\n");
14521458
goto error;
14531459
}
1460+
#endif // OVERRIDE_ENABLED
14541461
} else if (arg == "--render-thread") { // render thread mode
14551462

14561463
if (N) {
@@ -1651,8 +1658,10 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
16511658
OS::get_singleton()->print("Missing relative or absolute path, aborting.\n");
16521659
goto error;
16531660
}
1661+
#ifdef OVERRIDE_ENABLED
16541662
} else if (arg == "-u" || arg == "--upwards") { // scan folders upwards
16551663
upwards = true;
1664+
#endif // OVERRIDE_ENABLED
16561665
} else if (arg == "--quit") { // Auto quit at the end of the first main loop iteration
16571666
quit_after = 1;
16581667
#ifdef TOOLS_ENABLED
@@ -1723,7 +1732,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
17231732
OS::get_singleton()->print("Missing time scale argument, aborting.\n");
17241733
goto error;
17251734
}
1726-
1735+
#ifdef OVERRIDE_ENABLED
17271736
} else if (arg == "--main-pack") {
17281737
if (N) {
17291738
main_pack = N->get();
@@ -1732,7 +1741,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
17321741
OS::get_singleton()->print("Missing path to main pack file, aborting.\n");
17331742
goto error;
17341743
}
1735-
1744+
#endif // OVERRIDE_ENABLED
17361745
} else if (arg == "-d" || arg == "--debug") {
17371746
debug_uri = "local://";
17381747
OS::get_singleton()->_debug_stdout = true;
@@ -1913,6 +1922,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
19131922
}
19141923
#endif
19151924

1925+
#ifdef OVERRIDE_ENABLED
19161926
// Network file system needs to be configured before globals, since globals are based on the
19171927
// 'project.godot' file which will only be available through the network if this is enabled
19181928
if (!remotefs.is_empty()) {
@@ -1930,6 +1940,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
19301940
goto error;
19311941
}
19321942
}
1943+
#endif // OVERRIDE_ENABLED
19331944

19341945
OS::get_singleton()->_in_editor = editor;
19351946
if (globals->setup(project_path, main_pack, upwards, editor) == OK) {
@@ -3815,6 +3826,7 @@ int Main::start() {
38153826
} else if (E->get() == "--install-android-build-template") {
38163827
install_android_build_template = true;
38173828
#endif // TOOLS_ENABLED
3829+
#ifdef OVERRIDE_ENABLED
38183830
} else if (E->get() == "--scene") {
38193831
E = E->next();
38203832
if (E) {
@@ -3839,6 +3851,7 @@ int Main::start() {
38393851
// for non-game applications.
38403852
game_path = scene_path;
38413853
}
3854+
#endif // OVERRIDE_ENABLED
38423855
}
38433856
// Then parameters that have an argument to the right.
38443857
else if (E->next()) {
@@ -4043,6 +4056,19 @@ int Main::start() {
40434056

40444057
#endif // TOOLS_ENABLED
40454058

4059+
#ifdef OVERRIDE_ENABLED
4060+
bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
4061+
if (disable_override) {
4062+
script = String();
4063+
game_path = String();
4064+
main_loop_type = String();
4065+
}
4066+
#else
4067+
script = String();
4068+
game_path = String();
4069+
main_loop_type = String();
4070+
#endif // OVERRIDE_ENABLED
4071+
40464072
if (script.is_empty() && game_path.is_empty()) {
40474073
const String main_scene = GLOBAL_GET("application/run/main_scene");
40484074
if (main_scene.begins_with("uid://")) {

0 commit comments

Comments
 (0)