godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.96k stars 21.07k forks source link

SCons does not respect `debug_symbols="yes"` in `custom.py` #97436

Open YYF233333 opened 1 week ago

YYF233333 commented 1 week ago

Tested versions

System information

Win 10 + Visual Studio 2022 + MSVC toolchain

Issue description

Building template_release with debug symbol to profile the engine (using Visual Studio's built-in profiler). Since I don't know how to pass cmdline args in VS, I write all args in custom.py, including debug_symbols="yes", but no pdb files are generated.

Further tests shows that scons seems to completely ignore debug_symbols in custom.py and always use the default for each target. Specify debug_symbols from cmdline is not affected.

Not very sure but I found this code piece in SConstruct in the root:

# line 181-209
customs = ["custom.py"]
......
opts = Variables(customs, ARGUMENTS)
......
opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", False))

It seems to override my args in custom.py.

Also the production flag does not consider this:

# line 611-613
if env["production"]:
    env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", False)

Not tested but other variables are likely to use the same logic, so I guess my custom.py is completely ignored?

Expected behavior: scons respect build options in custom.py

Steps to reproduce

Minimal reproduction project (MRP)

Godot engine itself

akien-mga commented 1 week ago

What scons command do you pass exactly to build or generate a VS solution?

akien-mga commented 1 week ago

I tested on Linux with the following config:

# custom.py
debug_symbols="yes"
diff --git a/SConstruct b/SConstruct
index 0245531b45..2dbc2ae634 100644
--- a/SConstruct
+++ b/SConstruct
@@ -491,7 +491,9 @@ if env["optimize"] == "auto":
         opt_level = "speed"
     env["optimize"] = ARGUMENTS.get("optimize", opt_level)

+print(env["debug_symbols"])
 env["debug_symbols"] = methods.get_cmdline_bool("debug_symbols", env.dev_build)
+print(env["debug_symbols"])

 if env.editor_build:
     env.Append(CPPDEFINES=["TOOLS_ENABLED"])

And then just scons, I indeed I can reproduce the bug:

True
False

The problem is that our checks with methods.get_cmdline_bool, or in the case of string arguments just ARGUMENTS.get(), only check overrides on the command line, and not "defaults" provided through custom.py, or any other file listed as profile.

And then we have these convenience aliases like dev_build which should set good default values, but can still be overridden from the command line, and in this case should still be overridden by custom.py... maybe? Honestly I'm not sure how we could do that, there's so many layers that it's starting to be hard to know what's an engine-defined default, a user-defined default (custom.py), a user-defined override (command line), or an engine-defined but user requested alias (dev_build, dev_mode, production).

CC @Repiteo if you have some good ideas.

YYF233333 commented 1 week ago

What scons command do you pass exactly to build or generate a VS solution?

just scons target=editor vsproj=yes (with that custom.py), build with VS's Build Solution