Repository: godotengine/godot (language: cpp)

Issue:
[Buildsystem] Builds fail with MSVC with separate build symbols
### Tested versions

- Reproducible in master [0028fd625e2c5b202e204bc12828cbca043213d3]
- Not reproducible in master [b5bdb88062a31a982c8f3bf4b820188edd53c6c5]
- Bisected down to #103864 [45053520216b70d5669587b55e6b3d98df201c3d]

### System information

Godot v4.4.stable - Windows 10.0.26100 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 (NVIDIA; 32.0.15.7247) - AMD Ryzen 7 3800XT 8-Core Processor (16 Threads)

### Issue description

When attempting to build Godot, I'm getting the following error when generating the executable:
```
Starting build...
cmd /c chcp 65001>nul && scons dev_build=yes separate_debug_symbols=yes tests=yes compiledb=yes d3d12=yes
scons: Reading SConscript files ...
Automatically detected platform: windows
Auto-detected 16 CPU cores available for build parallelism. Using 15 cores by default. You can override it with the `-j` or `num_jobs` arguments.
Building for platform "windows", architecture "x86_64", target "editor".
INFO: Developer build, with debug optimization level and debug symbols (unless overridden).
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
Linking Program bin\godot.windows.editor.dev.x86_64.exe ...
Generating compile_commands.json ...
Generating bin\godot.windows.editor.dev.x86_64.exe ...
scons: *** [bin\godot.windows.editor.dev.x86_64.exe] KeyError : 'OBJCOPY'
Traceback (most recent call last):
  File "C:\Users\kilau\AppData\Local\Programs\Python\Python310\lib\site-packages\SCons\Environment.py", line 2677, in __getitem__
    return self.__dict__['overrides'][key]
KeyError: 'OBJCOPY'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kilau\AppData\Local\Programs\Python\Python310\lib\site-packages\SCons\Action.py", line 1434, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "C:\Users\kilau\Development\godot_dev\godot4\platform\windows\platform_windows_builders.py", line 10, in make_debug_mingw
    os.system("{0} --only-keep-debug {1} {1}.debugsymbols".format(env["OBJCOPY"], dst))
  File "C:\Users\kilau\AppData\Local\Programs\Python\Python310\lib\site-packages\SCons\Environment.py", line 2681, in __getitem__
    return self.__dict__['__subject'].__getitem__(key)
  File "C:\Users\kilau\AppData\Local\Programs\Python\Python310\lib\site-packages\SCons\Environment.py", line 603, in __getitem__
    return self._dict[key]
KeyError: 'OBJCOPY'
scons: building terminated because of errors.
INFO: Time elapsed: 00:00:20.14 
```

### Steps to reproduce

Run `scons dev_build=yes separate_debug_symbols=yes tests=yes compiledb=yes` on a system with MSVC.

### Minimal reproduction project (MRP)

N/A


Discussion / hints:
Ran a bisect and narrowed down the regression to #103864 
This issue can be worked around by running SCons within the `x64 Native Tools Command Prompt for VS 2022` console.

For VSCode, this can be setup by adding to your `tasks.json` file:
``` json
"windows": {
        "options": {
            "shell": {
                "executable": "cmd.exe",
                "args": [
                    "/C",
                    "\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\"",
                    "&&"
                ]
            }
        }
    }
```

Then, change any build actions to type `shell`.

Process is documented here: https://code.visualstudio.com/docs/cpp/config-msvc#_run-vs-code-outside-the-developer-command-prompt

Fix patch:
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index 1ddefb9c331f..284b43d55de7 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -124,7 +124,7 @@ if env["d3d12"]:
             Copy("$TARGET", "$SOURCE"),
         )
 
-if not os.getenv("VCINSTALLDIR"):
+if not env.msvc:
     if env["debug_symbols"]:
         env.AddPostAction(prog, env.Run(platform_windows_builders.make_debug_mingw))
         if env["windows_subsystem"] == "gui":


Test patch: