Skip to content
16 changes: 16 additions & 0 deletions SCons/Tool/MSCommon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ def normalize_env(env, keys, force: bool=False):
if sys32_wbem_dir not in normenv['PATH']:
normenv['PATH'] = normenv['PATH'] + os.pathsep + sys32_wbem_dir

# ProgramFiles for PowerShell 7 Path and PSModulePath
progfiles_dir = os.environ.get("ProgramFiles")
if not progfiles_dir:
Comment thread
bdbaddog marked this conversation as resolved.
sysroot_drive, _ = os.path.splitdrive(sys32_dir)
sysroot_path = sysroot_drive + os.sep
progfiles_dir = os.path.join(sysroot_path, "Program Files")

# Powershell 7
progfiles_ps_dir = os.path.join(progfiles_dir, r"PowerShell\7")

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.

why r"PowerShell\7"? is that a single path element and not PowerShell \ 7 ?

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.

raw string it is Powershell\7:

os.path.join(os.environ["ProgramFiles"], r"Powershell\7")
'C:\Program Files\Powershell\7'

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.

Would you prefer os.path.join(progfiles_dir, "PowerShell", "7")?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@bdbaddog that will give Python syntax warnings if not a rawstring. @jcbrill, yes join all the path elements, don't use one with an embedded separator.

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.

if progfiles_ps_dir not in normenv["PATH"]:
normenv["PATH"] = normenv["PATH"] + os.pathsep + progfiles_ps_dir

# Without Powershell in PATH, an internal call to a telemetry
# function (starting with a VS2019 update) can fail
# Note can also set VSCMD_SKIP_SENDTELEMETRY to avoid this.
Expand Down Expand Up @@ -389,12 +401,16 @@ def get_output(vcbat, args=None, env=None, skip_sendtelemetry=False):
'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',

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.

Can we move this list to be a package variable?

That way it can be changed from a SConscript/SConstruct if desired..

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.

Absolutely

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How would that work? Seems a bit awkward to have to deal with a variable in the vastly more common default case - we've only had the one issue/PR relating to someone trying to use vcpkg, so it can't be very common in the world SCons reaches.

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.

@mwichmann I believe that @bdbaddog is talking about moving the constant list of variables from inside the function to file-level. This way it could be modified externally if desired but not necessarily recommended.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ah... "package variable" is a defined term in SCons (https://scons.org/doc/production/HTML/scons-man.html#v-PackageVariable) so I thought that's what it meant. If the intent was module global, yes, that's a good idea: things that are "constants" (even if they're changeable) are better at the top of the file than embedded in a function.

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.

It was only moved immediately above the function using the list rather than the top of the file. It is only used in one place (Captain Obvious).

Hope that is ok.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Personally prefer them at the top for visibility, but there's some argument that something with only one use is also good kept close to the place of use. There are few absolutes with Python.

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.

Agreed. better to have all the constants at the top of the file if possible.

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.

None of the current constants in MSCommon/common.py are at the top of the file. All inline near use point.

]
env['ENV'] = normalize_env(env['ENV'], vs_vc_vars, force=False)

if skip_sendtelemetry:
_force_vscmd_skip_sendtelemetry(env)

# debug("ENV=%r", env['ENV'])

if args:
debug("Calling '%s %s'", vcbat, args)
cmd_str = '"%s" %s & set' % (vcbat, args)
Expand Down