scons: When windows installed non-english Visual Studio 2019 16.4 initialization/detection fails due to text locale.

Describe the bug When Sconscript requires VS 2019 and you are still on Windows 7 it cannot be used. There are two problems:

  • vcvarsall.bat calls powershell to send telemetry, however on Windows 7 Scons for some reason cannot find Powershell folder in the path, so it cannot be invoked. This causes popup letting the user know about this to appear.
  • The message about Powershell not found is also written to sys.stderr or at least tries to be written there. On Python 3 sys.stderr requires string but subprocess returs bytes so the attempt at writing results in:
TypeError: write() argument must be str, not bytes:
  File "D:\test\SConstruct", line 1:
    env = DefaultEnvironment(MSVC_VERSION="14.2", TARGET_ARCH="x86")
  File "c:\python37\lib\site-packages\scons\SCons\Defaults.py", line 88:
    _default_env = SCons.Environment.Environment(*args, **kw)
  File "c:\python37\lib\site-packages\scons\SCons\Environment.py", line 990:
    apply_tools(self, tools, toolpath)
  File "c:\python37\lib\site-packages\scons\SCons\Environment.py", line 102:
    env.Tool(tool)
  File "c:\python37\lib\site-packages\scons\SCons\Environment.py", line 1810:
    tool(self)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\__init__.py", line 303:
    self.generate(env, *args, **kw)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\default.py", line 41:
    SCons.Tool.Tool(t)(env)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\__init__.py", line 303:
    self.generate(env, *args, **kw)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\mslink.py", line 314:
    msvc_setup_env_once(env)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\MSCommon\vc.py", line 695:
    msvc_setup_env(env)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\MSCommon\vc.py", line 814:
    d = msvc_find_valid_batch_script(env,version)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\MSCommon\vc.py", line 762:
    d = script_env(vc_script, args=arg)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\MSCommon\vc.py", line 621:
    stdout = common.get_output(script, args)
  File "c:\python37\lib\site-packages\scons\SCons\Tool\MSCommon\common.py", line 238:
    sys.stderr.write(stderr)

Curiously the same SConscript executed on Windows 10 with the same version of VS, Python and SCons works correctly. It is quite strange, because on both systems Powershell is located at C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Required information

SCons by Steven Knight et al.:
        script: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog
        engine: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog
  • Version of Python Python 3.7.5 32-bit

  • How you installed SCons python -m pip install scons

  • What Platform are you on? (Linux/Windows and which version) Windows 7 and Windows 10, both x64

  • How to reproduce your issue? Please include a small self contained reproducer. Likely a SConstruct should do for most issues.

env = DefaultEnvironment(MSVC_VERSION="14.2", TARGET_ARCH="x86")
config_context = Configure(env)
  • How you invoke scons (The command line you’re using “scons --flags some_arguments”) just scons in the folder where my SConscript is located

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I now know why it is not failing under Windows 10 but fails on Win 7. (vcvarsall.bat is not calling Powershell directly when VSCMD_DEBUG is not set but does it via start Command. For whatever reason if Powershell is not in the path start is still able to find it under Windows 10 but not on W7. For me adding Powershell folder (that is C:\Windows\System32\WindowsPowerShell\v1.0\ ) to normalize_env fixes the problem. @mwichmann Would you be able to do this as part of #3576? That and change of encoding for stderr from MBCS to OEM would fix this issue completely.