Skip to content
69 changes: 35 additions & 34 deletions SCons/Tool/MSCommon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def normalize_env(env, keys, force: bool=False):
progfiles_dir = os.path.join(sysroot_path, "Program Files")

# Powershell 7
progfiles_ps_dir = os.path.join(progfiles_dir, r"PowerShell\7")
progfiles_ps_dir = os.path.join(progfiles_dir, "PowerShell", "7")
if progfiles_ps_dir not in normenv["PATH"]:
normenv["PATH"] = normenv["PATH"] + os.pathsep + progfiles_ps_dir

Expand All @@ -365,46 +365,47 @@ def normalize_env(env, keys, force: bool=False):
return normenv


# TODO: Hard-coded list of the variables that (may) need to be
# imported from os.environ[] for the chain of development batch
# files to execute correctly. One call to vcvars*.bat may
# end up running a dozen or more scripts, changes not only with
# each release but with what is installed at the time. We think
# in modern installations most are set along the way and don't
# need to be picked from the env, but include these for safety's sake.
# Any VSCMD variables definitely are picked from the env and
# control execution in interesting ways.
# Note these really should be unified - either controlled by vs.py,
# or synced with the the common_tools_var # settings in vs.py.
_VS_VC_VARS = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the _ prefix here. There's no major reason to sugguest accessing this from other code should be avoided ?

Copy link
Copy Markdown
Contributor Author

@jcbrill jcbrill May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an indicator that it shouldn't necessarily be modified. I don't feel strongly either way.

We should probably add a debug logging statement for each of the keys retrieved from the list in normalize_env since the list can now be modified. The mscommon log file is the easiest way to determine if a user modified the list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed change removing the _ prefix and added debug logging in the loop that evaluates the keys.

'COMSPEC', # path to "shell"
'OS', # name of OS family: Windows_NT or undefined (95/98/ME)
'VS170COMNTOOLS', # path to common tools for given version
'VS160COMNTOOLS',
'VS150COMNTOOLS',
'VS140COMNTOOLS',
'VS120COMNTOOLS',
'VS110COMNTOOLS',
'VS100COMNTOOLS',
'VS90COMNTOOLS',
'VS80COMNTOOLS',
'VS71COMNTOOLS',
'VSCOMNTOOLS',
'MSDevDir',
'VSCMD_DEBUG', # enable logging and other debug aids
'VSCMD_SKIP_SENDTELEMETRY',
'windir', # windows directory (SystemRoot not available in 95/98/ME)
'VCPKG_DISABLE_METRICS',
'VCPKG_ROOT',
]

def get_output(vcbat, args=None, env=None, skip_sendtelemetry=False):
"""Parse the output of given bat file, with given args."""

if env is None:
# Create a blank environment, for use in launching the tools
env = SCons.Environment.Environment(tools=[])

# TODO: Hard-coded list of the variables that (may) need to be
# imported from os.environ[] for the chain of development batch
# files to execute correctly. One call to vcvars*.bat may
# end up running a dozen or more scripts, changes not only with
# each release but with what is installed at the time. We think
# in modern installations most are set along the way and don't
# need to be picked from the env, but include these for safety's sake.
# Any VSCMD variables definitely are picked from the env and
# control execution in interesting ways.
# Note these really should be unified - either controlled by vs.py,
# or synced with the the common_tools_var # settings in vs.py.
vs_vc_vars = [
'COMSPEC', # path to "shell"
'OS', # name of OS family: Windows_NT or undefined (95/98/ME)
'VS170COMNTOOLS', # path to common tools for given version
'VS160COMNTOOLS',
'VS150COMNTOOLS',
'VS140COMNTOOLS',
'VS120COMNTOOLS',
'VS110COMNTOOLS',
'VS100COMNTOOLS',
'VS90COMNTOOLS',
'VS80COMNTOOLS',
'VS71COMNTOOLS',
'VSCOMNTOOLS',
'MSDevDir',
'VSCMD_DEBUG', # enable logging and other debug aids
'VSCMD_SKIP_SENDTELEMETRY',
'windir', # windows directory (SystemRoot not available in 95/98/ME)
'VCPKG_DISABLE_METRICS',
'VCPKG_ROOT',
]
env['ENV'] = normalize_env(env['ENV'], vs_vc_vars, force=False)
env['ENV'] = normalize_env(env['ENV'], _VS_VC_VARS, force=False)

if skip_sendtelemetry:
_force_vscmd_skip_sendtelemetry(env)
Expand Down
Loading