scons icon indicating copy to clipboard operation
scons copied to clipboard

Build as administrator is required on windows (sometimes?)

Open koubaa opened this issue 2 years ago • 50 comments

  • I tried to submit the bug on the mailing list on 5/12/23 but looking at the archives it is not there. So I am posting here. SCons version: 4.0.1, installed via pip from pypi Python 3.10 from python.org Windows 10, Visual Studio 2019.
def GetVCVarsPath():¬
    vswhere_path = os.path.expandvars('%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe')¬
    args = [vswhere_path,¬
            '-format', 'json',¬
            '-utf8',¬
            '-version', '[16.0,)'] # VS2019+¬
    # Prefer older Visual Studio versions over newer ones¬
    for cand in sorted(json.loads(check_output(args).decode('utf-8')),¬
                       key=lambda cand: cand['installationVersion']):¬
        install_path = cand['installationPath']¬
        vcvars_path = os.path.join(install_path,¬
                                   'VC',¬
                                   'Auxiliary',¬
                                   'Build',¬
                                   'vcvars64.bat')¬
        if os.path.exists(vcvars_path):¬
            return vcvars_path

We use MSVC_USE_SCRIPT=GetVCVarsPath(), function defined above. Users might also have Visual Studio 2022 installed, but this build requires VS2019.

Describe the bug I set up a scons-based build system at my organization. Some users have complained to me that they can only run the build as administrator. I am not able to reproduce that problem myself. Here is the error message that the users who are affected get when they build as a non-admin.

cl : Command line error D8050 : cannot execute 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.20.27508\bin\HostX64\x64\c1xx.dll': failed to get command line into debug records scons: building terminated because of errors.

I can try to get a minimal reproducible example, but apparently any c++ scons build is affected for these users. We use Visual Studio 2019

scons is invoked from python in a virtual environment where scons is installed as a subprocess. The executable in the subprocess is determined using the result of the subprocess where scons.

koubaa avatar Nov 01 '23 13:11 koubaa

Well, the error is a compiler error, not an SCons error - SCons has found and executed a compiler binary. It seems it's trying to create a file somewhere that it hasn't the rights to, which is why running with admin rights helps. I'd be looking at the settings of environment variables TEMP and TMP in the places where this is causing trouble to see if there are any clues there. SCons does fetch those from the environment (os.environ) and put them into the execution environment so they'll be available to the processes that are kicked off by SCons.

There are other ways to specify the version you want to use, though those have evolved somewhat since 4.0, so you shouldn't have to resort to your own call to vswhere (scons is going to do that anyway) but that's not the problem since you've shown it's finding it already, since 14.2x is the 2019 series.

scons is invoked from python in a virtual environment where scons is installed as a subprocess. The executable in the subprocess is determined using the result of the subprocess where scons.

Out of curiosity, why make it so complicated?

@jcbrill any thoughts here?

mwichmann avatar Nov 01 '23 14:11 mwichmann

Out of curiosity, why make it so complicated?

@mwichmann I set it up to just run scons from the shell in the appropriate python environment. At some point I took on other responsibilities and someone else made that change, and I don't know why, unfortunately. But I am still asked for help by users when the build system doesn't work since I created it initially.

koubaa avatar Nov 01 '23 14:11 koubaa

Not much to add yet.

This thread seems to be similar: https://developercommunity.visualstudio.com/t/binhostx86x86c1xxdll/314749 (emphasis added)

In my case I was running cl.exe via SCons. Scons strips the environment! So you need to tell Scons to pass through TMP from up-level environment, or just set it to something in the sconscipt.

To verify that this indeed is the case, create cl.bat somewhere in path with content that conststs of "set". This will print the environment variables. In my case TMP wasn't set to anything (and apparently cl.exe defaults to %systemroot% and fails with access denied -- that's why one of the solutions is to have cl run as admin)

At present, it sounds like a Windows environment issue.

In addition to checking that the TEMP and TMP environment variables are defined and point to folders that exist, one user experienced this error with VS2017 when the USERPROFILE environment variable was not defined.

https://stackoverflow.com/questions/52152923/vs2017-build-returns-d8050-failed-to-get-command-line-into-debug-records https://stackoverflow.com/questions/26547214/cl-exe-returing-error-code-d8050

jcbrill avatar Nov 01 '23 15:11 jcbrill

SCons made this change:

  • The %TEMP% and %TMP% external environment variables are now propagated automatically to the command execution environment on Windows systems.

way back in

RELEASE 0.96.90 - Tue, 15 Feb 2005

The change to automatically propagate %USERPROFILE% into the execution environment came much later, in 2021 (more than a year after 4.0), so it's possible that is a part of the issue you're seeing.

mwichmann avatar Nov 01 '23 15:11 mwichmann

USERPROFILE does not appear to be imported from the environment until version 4.4.0.

jcbrill avatar Nov 01 '23 15:11 jcbrill

USERPROFILE does not appear to be imported from the environment until version 4.4.0.

Yes, I think it missed the 4.3.0 release by a couple of weeks.

diff --git a/SCons/Platform/win32.py b/SCons/Platform/win32.py
index eeb2abff4..990794f96 100644
--- a/SCons/Platform/win32.py
+++ b/SCons/Platform/win32.py
@@ -381,7 +381,7 @@ def generate(env):
     # for SystemDrive because it's related.
     #
     # Weigh the impact carefully before adding other variables to this list.
-    import_env = ['SystemDrive', 'SystemRoot', 'TEMP', 'TMP' ]
+    import_env = ['SystemDrive', 'SystemRoot', 'TEMP', 'TMP', 'USERPROFILE']
     for var in import_env:
         v = os.environ.get(var)
         if v:

mwichmann avatar Nov 01 '23 15:11 mwichmann

Typical TEMP and TMP User Variables definitions are:

TEMP=%USERPROFILE%\AppData\Local\Temp TMP=%USERPROFILE%\AppData\Local\Temp

Typical TEMP and TMP System Variables definitions are:

TEMP=%SystemRoot%\TEMP TMP=%SystemRoot%\TEMP

If the User Variable TEMP and TMP definitions are missing, there might be a permissions problem with the temp folder off the system root (as mentioned in the linked posts) which would explain why it works with admin privileges.

jcbrill avatar Nov 01 '23 16:11 jcbrill

Try upgrading to latest SCons...

bdbaddog avatar Nov 01 '23 17:11 bdbaddog

The windows environment issue experienced is reproducible when both TEMP and TMP are undefined using scons 4.0.1 and VS2019.

If either TEMP or TMP are defined and point to a valid folder the build will succeed. USERPROFILE does not matter.

FAILS from a "normal" windows command-line prompt without TEMP and TMP:

K:\SCons\test-scons-4440>set TEMP=
K:\SCons\test-scons-4440>set TMP=
K:\SCons\test-scons-4440>set USERPROFILE=

K:\SCons\test-scons-4440>%PYEXE% ../scons-4.0.1/scripts/scons.py
scons: Reading SConscript files ...

Computer Name: VS64-DEV-W11
SCons Root: Unknown
Installed Versions: ['14.2', '14.1', '14.0', '12.0', '11.0', '10.0', '9.0', '8.0', '7.1', '7.0', '6.0']
Default Tools: ['default', 'mslink', 'msvc', 'gfortran', 'masm', 'mslib', 'dmd', 'msvs', 'midl', 'filesystem', 'jar', 'javac', 'rmic', 'tar', 'zip', 'textfile']

Build: _build-vs64-dev-w11-0001 {'MSVC_VERSION': '14.2', 'MSVC_USE_SCRIPT': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat'}

scons: done reading SConscript files.
scons: Building targets ...
cl /Fo_build-vs64-dev-w11-0001\hello.obj /c src\hello.cpp /TP /MDd /EHsc /ZI /FS
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.cpp
cl : Command line error D8050 : cannot execute 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\c1xx.dll': failed to get command line into debug records
scons: *** [_build-vs64-dev-w11-0001\hello.obj] Error 2
scons: building terminated because of errors.

K:\SCons\test-scons-4440>

PASSES from an admin windows command prompt without TEMP and TMP:

J:\SCons\test-scons-4440>set TEMP=
J:\SCons\test-scons-4440>set TMP=
J:\SCons\test-scons-4440>set USERPROFILE=

J:\SCons\test-scons-4440>%PYEXE% ../scons-4.0.1/scripts/scons.py
scons: Reading SConscript files ...

Computer Name: VS64-DEV-W11
SCons Root: Unknown
Installed Versions: ['14.2', '14.1', '14.0', '12.0', '11.0', '10.0', '9.0', '8.0', '7.1', '7.0', '6.0']
Default Tools: ['default', 'mslink', 'msvc', 'gfortran', 'masm', 'mslib', 'dmd', 'msvs', 'midl', 'filesystem', 'jar', 'javac', 'rmic', 'tar', 'zip', 'textfile']

Build: _build-vs64-dev-w11-0001 {'MSVC_VERSION': '14.2', 'MSVC_USE_SCRIPT': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat'}

scons: done reading SConscript files.
scons: Building targets ...
cl /Fo_build-vs64-dev-w11-0001\hello.obj /c src\hello.cpp /TP /MDd /EHsc /ZI /FS
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.cpp

<...REMOVED...>

link /DEBUG /OUT:_build-vs64-dev-w11-0001\hello.exe kernel32.lib user32.lib _build-vs64-dev-w11-0001\hello.obj _build-vs64-dev-w11-0001\hello01.obj _build-vs64-dev-w11-0001\hello02.obj _build-vs64-dev-w11-0001\hello03.obj _build-vs64-dev-w11-0001\hello04.obj _build-vs64-dev-w11-0001\hello05.obj _build-vs64-dev-w11-0001\hello06.obj _build-vs64-dev-w11-0001\hello07.obj _build-vs64-dev-w11-0001\hello08.obj _build-vs64-dev-w11-0001\hello09.obj _build-vs64-dev-w11-0001\hello10.obj _build-vs64-dev-w11-0001\hello11.obj _build-vs64-dev-w11-0001\hello12.obj _build-vs64-dev-w11-0001\hello13.obj _build-vs64-dev-w11-0001\hello14.obj _build-vs64-dev-w11-0001\hello15.obj _build-vs64-dev-w11-0001\hello16.obj _build-vs64-dev-w11-0001\hello17.obj _build-vs64-dev-w11-0001\hello18.obj _build-vs64-dev-w11-0001\hello19.obj _build-vs64-dev-w11-0001\hello20.obj
Microsoft (R) Incremental Linker Version 14.29.30151.0
Copyright (C) Microsoft Corporation.  All rights reserved.

scons: done building targets.

J:\SCons\test-scons-4440>

PASSES from a "normal" command-line prompt with either TEMP or TMP:

K:\SCons\test-scons-4440>set TMP=
K:\SCons\test-scons-4440>set TEMP=%SYSTEMROOT%\temp
K:\SCons\test-scons-4440>set USERPROFILE=

K:\SCons\test-scons-4440>%PYEXE% ../scons-4.0.1/scripts/scons.py
scons: Reading SConscript files ...

Computer Name: VS64-DEV-W11
SCons Root: Unknown
Installed Versions: ['14.2', '14.1', '14.0', '12.0', '11.0', '10.0', '9.0', '8.0', '7.1', '7.0', '6.0']
Default Tools: ['default', 'mslink', 'msvc', 'gfortran', 'masm', 'mslib', 'dmd', 'msvs', 'midl', 'filesystem', 'jar', 'javac', 'rmic', 'tar', 'zip', 'textfile']

Build: _build-vs64-dev-w11-0001 {'MSVC_VERSION': '14.2', 'MSVC_USE_SCRIPT': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat'}

scons: done reading SConscript files.
scons: Building targets ...
cl /Fo_build-vs64-dev-w11-0001\hello.obj /c src\hello.cpp /TP /MDd /EHsc /ZI /FS
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30151 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.cpp

<...REMOVED...>

link /DEBUG /OUT:_build-vs64-dev-w11-0001\hello.exe kernel32.lib user32.lib _build-vs64-dev-w11-0001\hello.obj _build-vs64-dev-w11-0001\hello01.obj _build-vs64-dev-w11-0001\hello02.obj _build-vs64-dev-w11-0001\hello03.obj _build-vs64-dev-w11-0001\hello04.obj _build-vs64-dev-w11-0001\hello05.obj _build-vs64-dev-w11-0001\hello06.obj _build-vs64-dev-w11-0001\hello07.obj _build-vs64-dev-w11-0001\hello08.obj _build-vs64-dev-w11-0001\hello09.obj _build-vs64-dev-w11-0001\hello10.obj _build-vs64-dev-w11-0001\hello11.obj _build-vs64-dev-w11-0001\hello12.obj _build-vs64-dev-w11-0001\hello13.obj _build-vs64-dev-w11-0001\hello14.obj _build-vs64-dev-w11-0001\hello15.obj _build-vs64-dev-w11-0001\hello16.obj _build-vs64-dev-w11-0001\hello17.obj _build-vs64-dev-w11-0001\hello18.obj _build-vs64-dev-w11-0001\hello19.obj _build-vs64-dev-w11-0001\hello20.obj
Microsoft (R) Incremental Linker Version 14.29.30151.0
Copyright (C) Microsoft Corporation.  All rights reserved.

scons: done building targets.

K:\SCons\test-scons-4440>

Edits:

  • fixed environment variable setting in listing 3.
  • using embedded python 3.6

jcbrill avatar Nov 01 '23 18:11 jcbrill

Try upgrading to latest SCons...

If TEMP and TMP are both undefined, the latest SCons with VS2022 will fail in the same manner.

jcbrill avatar Nov 01 '23 18:11 jcbrill

Try upgrading to latest SCons...

If TEMP and TMP are both undefined, the latest SCons with VS2022 will fail in the same manner.

I don't see that he said those aren't defined..? Regardless 4.0.1 is old. Always try with newest SCons before reporting a defect.

bdbaddog avatar Nov 01 '23 19:11 bdbaddog

I don't see that he said those aren't defined..?

That was us running off and speculating on possible causes, and now testing (thanks @jcbrill for confirming which case it - likely - is) based on some other instances of similar.

mwichmann avatar Nov 01 '23 19:11 mwichmann

Research notes thus far based on the issue report above, search results, msvc documentation, and command-line experiments for posterity.

There appears to be a confluence of events based on the windows environment and an msvc debug build that can result in build failures:

  • TEMP and TMP undefined.
  • msvc debug build.

This is not specific to SCons and can be reproduced in a windows command-line environment. The behavior experienced is exactly the same as described in the second and third items below.

Background information:

  • https://github.com/SCons/scons/issues/4440#issue-1972380644 (emphasis added)

    ... Some users have complained to me that they can only run the build as administrator. I am not able to reproduce that problem myself. Here is the error message that the users who are affected get when they build as a non-admin.
    ...
    cl : Command line error D8050 : cannot execute ... : failed to get command line into debug records

  • https://developercommunity.visualstudio.com/t/binhostx86x86c1xxdll/314749#T-N531583 (emphasis added)

    my %tmp% is fine. Procmon trace shows that cl.exe tries to open some c:\windows{GUID} for write access -- and then fails.

  • https://developercommunity.visualstudio.com/t/binhostx86x86c1xxdll/314749#T-N531583 (emphasis added)

    In my case I was running cl.exe via SCons. Scons strips the environment! So you need to tell Scons to pass through TMP from up-level environment, or just set it to something in the sconscipt.

    To verify that this indeed is the case, create cl.bat somewhere in path with content that conststs of "set". This will print the environment variables. In my case TMP wasn't set to anything (and apparently cl.exe defaults to %systemroot% and fails with access denied -- that's why one of the solutions is to have cl run as admin)

  • https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/command-line-error-d8049?view=msvc-160 (emphasis added)

    Command-line error D8049
    ...
    To resolve this issue
    Use shorter paths for your include and build directories. Install your library include headers in directories that have shorter paths, and use short paths to your projects' intermediate and destination build directories. IF you alias paths, use short aliases. Set %TMP% and %TEMP% to directories that have shorter paths.

While there does not appear to be specific documentation for D8050, D8049 seems to imply the usage of the windows temp folders as a source for populating the debug records.

Test methodology for windows environment without SCons for failed build:

  • set TEMP=
  • set TMP=
  • <execute VS2022 vcvars64.bat>
  • <start procmon64.exe>
  • manually invoke compiler cl /c /MDd /EHsc /ZI /FS hello.cpp
  • <stop procmon64.exe>

Procmon excerpts for a failed build:

5:15:07.3381547 PM cl.exe  8208  CreateFile  C:\Windows\{9BB928B8-7056-4D5E-B84A-DCB45C12CB49}  ACCESS DENIED  Desired Access: Generic Write, Read Attributes, ...

The attempt to create a file for writing in C:\Windows\{9BB928B8-7056-4D5E-B84A-DCB45C12CB49} fails due to access restrictions for a "normal" user which results in the build failure message:

cl : Command line error D8050 : cannot execute ... : failed to get command line into debug records

Test methodology for admin windows environment without SCons for successful build:

  • set TEMP=
  • set TMP=
  • <execute VS2022 vcvars64.bat>
  • <start procmon64.exe>
  • manually invoke compiler cl /c /MDd /EHsc /ZI /FS hello.cpp
  • <stop procmon64.exe>

Procmon excerpts from a successful build:

5:16:33.1787847 PM cl.exe  7900  CreateFile  C:\Windows\{23FA6196-BD74-4313-94D3-B1C0C6920F98}  SUCCESS  Desired Access: Generic Write, Read Attributes, ..., OpenResult: Created
5:16:33.1792722 PM cl.exe  7900  WriteFile   C:\Windows\{23FA6196-BD74-4313-94D3-B1C0C6920F98}  SUCCESS  Offset: 0, Length: 852, Priority: Normal
5:16:33.1796428 PM cl.exe  7900  WriteFile   C:\Windows\{23FA6196-BD74-4313-94D3-B1C0C6920F98}  SUCCESS  Offset: 852, Length: 120
5:16:33.1797237 PM cl.exe  7900  CloseFile   C:\Windows\{23FA6196-BD74-4313-94D3-B1C0C6920F98}  SUCCESS	
...
5:16:33.2503249 PM mspdbsrv.exe  692  Process Start  SUCCESS
Parent PID: 7900,
Command line: mspdbsrv.exe -start -spawn,
Current directory: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\,
Environment:
  ...
  ENC_CL=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\cl.exe
  ENC_CMD=3cb C:\WINDOWS\{23FA6196-BD74-4313-94D3-B1C0C6920F98}
  ENC_CWD=J:\SCons\test-scons-4440\src
  ENC_PDB=J:\SCons\test-scons-4440\src\vc140.pdb
  ENC_SRC=hello.cpp
  ...
...

The attempt to create a file for writing in C:\Windows\{23FA6196-BD74-4313-94D3-B1C0C6920F98} is successful and the file is populated.

The mspdbsrv.exe program is launched and includes environment variables for the temporary files (e.g., ENC_*).

The environment variable ENC_CMD is likely the command line that is referred to in the error message above.

This succeeds in an admin command interpreter due to the ability to read/write into the %SYSTEMROOT% folder.

jcbrill avatar Nov 01 '23 22:11 jcbrill

Seems like the user should FIRST try upgrading to latest SCons which we know has better MSVC logic and then we can spend any time trying to debug their issue.. We don't generally provide support to versions which are not the most current.

bdbaddog avatar Nov 02 '23 19:11 bdbaddog

@jcbrill @bdbaddog @mwichmann Sorry for the late reply here. The original user who reported the issue had issues reproducing the issue. Another user recently reported the same issue. They have %TMP%, %TEMP%, and %USERPROFILE% set and have tried SCons 4.0.1, 4.5.3, and 4.7.0 in a virtual environment. and can still reproduce the problem with all three versions of SCons.

koubaa avatar Apr 02 '24 14:04 koubaa

@jcbrill @bdbaddog @mwichmann Sorry for the late reply here. The original user who reported the issue had issues reproducing the issue. Another user recently reported the same issue. They have %TMP%, %TEMP%, and %USERPROFILE% set and have tried SCons 4.0.1, 4.5.3, and 4.7.0 in a virtual environment. and can still reproduce the problem with all three versions of SCons.

Are they running these from powershell or cmd.exe shell? By virtual environment, we're talking about python's venv, or virtualenv, and not something else right? Is this being run in docker, or similar?

We have seem weird issues in the past where anti-virus could impact such things.

So the original user no longer has the issue, but another user does and it's currently reproducible? How long has their machine been up? Can they try rebooting and see if it goes away?

Can you share the most minimal SConstruct which reproduces this?

env=Environment()
env.SharedObject('hello.c', SHCXXFLAGS="$SHCXXFLAGS /MDd /EHsc /ZI /FS")

Would that do it?

bdbaddog avatar Apr 02 '24 19:04 bdbaddog

The installed Visual Studio version number might be helpful as well (e.g., 16.1, 16.2).

Is vs2019 updated to the latest version?

jcbrill avatar Apr 02 '24 23:04 jcbrill

cl : Command line error D8050 : cannot execute 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.20.27508\bin\HostX64\x64\c1xx.dll': failed to get command line into debug records scons: building terminated because of errors.

The original error message posted above in Nov 2023 shows toolset version 14.20.27508 which is a very early 2019 toolset and possibly the very first toolset.

The latest toolset version for 2019 is 14.29.30133.

Have updates to VS2019 been applied after the initial installation?

Note that the v142 tools can be used in VS2022 by using the MSVC_TOOLSET_VERSION construction variable: Environment(MSVC_VERSION='14.3', MSVC_TOOLSET_VERSION='14.2', ...)

jcbrill avatar Apr 03 '24 11:04 jcbrill

It took us a while but we just migrated our windows toolchain to vs2022. Some users continue to see this problem with scons 4.8.

See below: 1>cl : Command line error D8050: cannot execute 'C:\ANSYSDev\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\HostX64\x64\c1xx.dll': failed to get command line into debug records

The affected user is able to build successfully when running scons from an admin command prompt.

koubaa avatar Jul 26 '24 13:07 koubaa

Are they running these from powershell or cmd.exe shell? By virtual environment, we're talking about python's venv, or virtualenv, and not something else right? Is this being run in docker, or similar?

cmd.exe (but the user can reproduce the issue in powershell), python venv, not in docker.

We have seem weird issues in the past where anti-virus could impact such things.

We can't change our antivirus settings, the windows settings are controlled by our IT

So the original user no longer has the issue, but another user does and it's currently reproducible? How long has their machine been up? Can they try rebooting and see if it goes away?

As far as I can tell the issue is reproducible across reboots and is consistently reproducible

Can you share the most minimal SConstruct which reproduces this?

env=Environment()
env.SharedObject('hello.c', SHCXXFLAGS="$SHCXXFLAGS /MDd /EHsc /ZI /FS")

Would that do it?

I would need some time but I think eventually I could produce something like that

koubaa avatar Jul 26 '24 13:07 koubaa

We'll look at it if there's any way to.

On the antivirus topic: no idea if AV is at all involved in this problem (usually you'll get some less-than-helpful popups if so, so you'd probably know about it), but you really need to be able to whitelist a development tree, or it's going to be completely unworkable for devs. That's not anything particular to SCons. I've noticed one of the IDEs I use (the JetBrains family) detects if, once you've indicated you "trust" a project checkout, antivirus is going to be involved, it produces a program to add the whitelist settings and asks if you want to run it - so it's a widely recognized issue.

I do see some evidence on people running into this, and nobody ever comes up with a very workable solution (usually something brute-force like "uninstall and reinstall Visual Studio, so the rights get reset". Here's a quite recent instance from Microsoft's own vcpkg project, building the well-known boost C++ libraries. The build tool there is CMake (and perhaps ninja):

CMake Error at F:/src/vcpkg/downloads/tools/cmake-3.29.2-windows/cmake-3.29.2-windows-i386/share/cmake-3.29/Modules/CMakeTestCXXCompiler.cmake:60 (message):
  The C++ compiler

    "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'F:/src/vcpkg/buildtrees/boost-headers/x64-windows-rel/CMakeFiles/CMakeScratch/TryCompile-swsthv'
    
    Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" -v cmTC_2c6b6
    [1/2] C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\cl.exe  /nologo /TP   /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP   /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /showIncludes /FoCMakeFiles\cmTC_2c6b6.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_2c6b6.dir\ /FS -c F:\src\vcpkg\buildtrees\boost-headers\x64-windows-rel\CMakeFiles\CMakeScratch\TryCompile-swsthv\testCXXCompiler.cxx
    FAILED: CMakeFiles/cmTC_2c6b6.dir/testCXXCompiler.cxx.obj 
    C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\cl.exe  /nologo /TP   /nologo /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP   /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  -MDd /showIncludes /FoCMakeFiles\cmTC_2c6b6.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_2c6b6.dir\ /FS -c F:\src\vcpkg\buildtrees\boost-headers\x64-windows-rel\CMakeFiles\CMakeScratch\TryCompile-swsthv\testCXXCompiler.cxx
    cl : Command line error D8050 : cannot execute 'C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\c1xx.dll': failed to get command line into debug records

The issue in question is microsoft/vcpkg:38549

mwichmann avatar Jul 26 '24 13:07 mwichmann

Here's the command line invocation (filename & libname obscured). As a sanity check, I verified that when running as admin, it is the same command line invocation to cl:

cl /Foout\Debug\libname\fname.obj /c out\Debug\libname\fname.cc /TP /W3 /sdl- /WX- /Gd /EHsc /nologo /wd4996 /wd4267 /GS /Od /RTC1 /MDd /DNOMINMAX /DWIN32 /D_UNICODE /DUNICODE /D_DEBUG /Iout\Debug\libname /IC:\thidpartylibname\Release\include /Z7

cl : Command line error D8050 : cannot execute 'C:\ANSYSDev\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\HostX64\x64\c1xx.dll': failed to get command line into debug records

koubaa avatar Jul 26 '24 14:07 koubaa

@koubaa - in the corporate environments I've worked in, it's sometimes possible to get IT to temporarily disable A/V to see if it's contributing to such a problem.

Did you try googling this issue? I see this answer on Stack Overflow searching for that msvc error code https://stackoverflow.com/a/30788191/82681

bdbaddog avatar Jul 26 '24 16:07 bdbaddog

@koubaa If possible, running the attached script on the host computer might provide additional useful information about the windows environment.

Attached is scons-environ.zip which contains:

  • scons-environ.py

Run the attached script on the host computer in the same windows shell environment that SCons is invoked and redirect the output to a file:

  • python scons-environment.py >scons-environ-log.txt

After reviewing the output file content for privacy, attach the output file.

Notes:

  • The attached script was written very quickly so there may be issues.
  • The host computer USERPROFILE is obfuscated for privacy when reporting.
  • If the host computer USERPROFILE contains any special characters, the obfuscation may need to be disabled internally.

Possible causes/resolutions from internet searches include:

  • Issues with the TEMP/TMP/USERPROFILE specifications.
  • Issues with the $ character in the TEMP/TMP path specification.
  • Disk free space issues.

The source code in its entirety:

import os
import shutil

USERPROFILE = os.environ.get("USERPROFILE", "")
USERPROFILE_NORM = USERPROFILE.lower()
SAFEPROFILE = r"Z:\USERPROFILE"
USE_SAFEPROFILE = True

_cache_drive_free = {}

MB = 1024.0 * 1024.0

def evar_path(var):
    val = os.environ.get(var, "")
    if val:
        exists = 1 if os.path.exists(val) else 0
        dollar = 1 if "$" in val else 0
        spaces = 1 if " " in val else 0
        normpath = os.path.normcase(os.path.realpath(os.path.abspath(val)))
    else:
        exists = 0
        dollar = 0
        spaces = 0
        normpath = None

    if normpath:
        drive, _ = os.path.splitdrive(normpath)
        if drive not in _cache_drive_free:
            free = shutil.disk_usage(drive).free / MB
            _cache_drive_free[drive] = free

    if USE_SAFEPROFILE and USERPROFILE and val.lower().startswith(USERPROFILE_NORM):
        safe_val = SAFEPROFILE + val[len(USERPROFILE):]
    else:
        safe_val = val

    print(f"osvar name={var}, exists={exists}, dollar={dollar}, spaces={spaces}, path={safe_val!r}")

for var in [
    "SYSTEMDRIVE",
    "SYSTEMROOT",
    "TEMP",
    "TMP",
    "USERPROFILE",
    "COMSPEC",
]:
    evar_path(var)

for drive, free in _cache_drive_free.items():
    print(f"drive name={drive!r}, free={free:.1f} MB")

Sample output with USERPROFILE rewritten to Z:\USERPROFILE:

osvar name=SYSTEMDRIVE, exists=1, dollar=0, spaces=0, path='C:'
osvar name=SYSTEMROOT, exists=1, dollar=0, spaces=0, path='C:\\Windows'
osvar name=TEMP, exists=0, dollar=1, spaces=0, path='Z:\\USERPROFILE\\AppData\\$TEMP'
osvar name=TMP, exists=1, dollar=0, spaces=0, path='Z:\\USERPROFILE\\AppData\\Local\\Temp'
osvar name=USERPROFILE, exists=1, dollar=0, spaces=0, path='Z:\\USERPROFILE'
osvar name=COMSPEC, exists=1, dollar=0, spaces=0, path='C:\\Windows\\system32\\cmd.exe'
drive name='c:', free=454958.0 MB

jcbrill avatar Jul 26 '24 16:07 jcbrill

I'll follow up on these.

I was wondering if it was a race condition in how VS2022 uses TMP, and asked the affected user to use num_jobs=1, and the issue persists.

koubaa avatar Jul 26 '24 17:07 koubaa

C:\Dev\scripts\batches>pushd D:\Dev
 
D:\Dev>workon build
(build) D:\Dev>python the-test.py
osvar name=SYSTEMDRIVE, exists=1, dollar=0, spaces=0, path='C:'
osvar name=SYSTEMROOT, exists=1, dollar=0, spaces=0, path='C:\\Windows'
osvar name=TEMP, exists=1, dollar=0, spaces=0, path='Z:\\USERPROFILE\\AppData\\Local\\Temp'
osvar name=TMP, exists=1, dollar=0, spaces=0, path='Z:\\USERPROFILE\\AppData\\Local\\Temp'
osvar name=USERPROFILE, exists=1, dollar=0, spaces=0, path='Z:\\USERPROFILE'
osvar name=COMSPEC, exists=1, dollar=0, spaces=0, path='C:\\Windows\\system32\\cmd.exe'
drive name='c:', free=58225.2 MB
 
(build) D:\Dev>

koubaa avatar Jul 26 '24 18:07 koubaa

@koubaa Sorry for the confusion with the implementation of the obfuscation.

There is nothing that jumps out concerning the environment variable configuration.

All the tests checks were done on the actual paths.

The Z:\USERPROFILE was chosen so that it would be reasonably easy to tell which paths were likely using the windows default USERPROFILE prefix (e.g., TEMP=%USERPROFILE%\AppData\Temp) versus a custom location (e.g., C:\Temp).

Some users are sensitive about having their username exposed. It certainly could have been done better.

It might be worth checking the security/permissions settings on the C:\Users\USERNAME\AppData\Local\Temp folder for the appropriate user name that invokes the build command.

It also might be worth testing settings of TEMP and TMP that are outside the windows system and user folders especially if the antivirus settings are less picky for folders outside the system/user folders (or a folder that can be explicitly added to the av exception list).

If a new temp folder is configured, the temp folder must exist.

Note to self:

  • The python tempfile.mkstemp function interrogates the environment for ["TMPDIR", "TEMP", "TMP"].

jcbrill avatar Jul 26 '24 19:07 jcbrill

How much space is free on z: drive?

bdbaddog avatar Jul 26 '24 20:07 bdbaddog

How much space is free on z: drive?

Z:\USERPROFILE is an alias for C:\Users\USERNAME. According to the output posted above, there is approximately 56.86 GB free on the c drive.

jcbrill avatar Jul 26 '24 20:07 jcbrill

@koubaa I've attached a revised version of the earlier script. At your convenience, I would be interested in knowing if it works somewhere other than here.

scons-environ-2.zip contains a revised version of:

  • scons-environ.py

Run the attached script on the host computer in the same windows shell environment that SCons is invoked and redirect the output to a file:

python scons-environment.py >scons-environ-log.txt

Changes:

  • Modifications to the obfuscation of user and computer names.
  • Reporting of disk free space for all fixed and removable drives.
  • Addition of the TMPDIR environment variable.
  • Creation of temporary files using tempfile.mkstemp.
  • Permissions for temporary folders and temporary files via system calls to icacls.

Caveats:

  • The reporting of permissions may expose host internal names (e.g., domain names, etc). It might be necessary to manually obfuscate the permission names.
  • Unhandled exceptions are likely.

Sample output when run on a local computer:

Configuration:
    USE_SAFE_USERNAME=True (<USERNAME>)
    USE_SAFE_COMPUTERNAME=True (<COMPUTERNAME>)

Drive free space:
    C:    18,132.6 MB
    E:   100,308.1 MB

Environment paths:
    SYSTEMDRIVE='C:' (exists=True, nspecial=0)
    SYSTEMROOT='C:\\WINDOWS' (exists=True, nspecial=0)
    USERPROFILE='C:\\Users\\<USERNAME>' (exists=True, nspecial=0)
    COMSPEC='C:\\WINDOWS\\system32\\cmd.exe' (exists=True, nspecial=0)
    TMPDIR='' (exists=False, nspecial=0)
    TEMP='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp' (exists=True, nspecial=0)
    TMP='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp' (exists=True, nspecial=0)

Temporary file paths:
    TMPDIR='' (exists=False)
    TEMP='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp' (exists=True)
        acl[0] NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
        acl[1] BUILTIN\Administrators:(I)(OI)(CI)(F)
        acl[2] <COMPUTERNAME>\<USERNAME>:(I)(OI)(CI)(F)
        tempfile='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp\\tmpj3kubeeo'
            acl[0] NT AUTHORITY\SYSTEM:(I)(F)
            acl[1] BUILTIN\Administrators:(I)(F)
            acl[2] <COMPUTERNAME>\<USERNAME>:(I)(F)
    TMP='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp' (exists=True)
        acl[0] NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
        acl[1] BUILTIN\Administrators:(I)(OI)(CI)(F)
        acl[2] <COMPUTERNAME>\<USERNAME>:(I)(OI)(CI)(F)
        tempfile='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp\\tmpopsk03yw'
            acl[0] NT AUTHORITY\SYSTEM:(I)(F)
            acl[1] BUILTIN\Administrators:(I)(F)
            acl[2] <COMPUTERNAME>\<USERNAME>:(I)(F)
    <WinTemp>='C:\\WINDOWS\\Temp' (exists=True)
        acl[0]  Access is denied.
        tempfile='C:\\WINDOWS\\Temp\\tmpda1b0n_p'
            acl[0] NT AUTHORITY\SYSTEM:(I)(S,RD)
            acl[1] BUILTIN\IIS_IUSRS:(I)(S,RD)
            acl[2] BUILTIN\Administrators:(I)(F)
            acl[3] NT AUTHORITY\SYSTEM:(I)(F)
            acl[4] <COMPUTERNAME>\<USERNAME>:(I)(F)
    <PyDefault>='' (exists=False)
        tempfile='C:\\Users\\<USERNAME>\\AppData\\Local\\Temp\\tmp1mf9xmcy'
            acl[0] NT AUTHORITY\SYSTEM:(I)(F)
            acl[1] BUILTIN\Administrators:(I)(F)
            acl[2] <COMPUTERNAME>\<USERNAME>:(I)(F)

jcbrill avatar Jul 29 '24 17:07 jcbrill