Commit 5ac63a96 authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Fix gn gen after vcvarsall.bat

If you are using a locally installed toolchain
(DEPOT_TOOLS_WIN_TOOLCHAIN=0) then the behavior of gn gen depended on
whether you had run vcvarsall.bat before running gn gen. That is because
vcvarsall.bat appends to several environment variables, these appended
values are captured by setup_toolchain.py, so running vcvarsall.bat
affects the command line of commands generated by gn gen.

This fixes that by clearing INCLUDE, LIB, and LIBPATH so that gn gen is
hermetic. This was tested with VS 2019.

Bug: 1112456
Change-Id: Ib2388466915d26033937004ddc5ca304f81e5d79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333081
Commit-Queue: Dirk Pranke <dpranke@google.com>
Auto-Submit: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#794331}
parent 458c9d8d
...@@ -139,9 +139,16 @@ def _LoadToolchainEnv(cpu, sdk_dir, target_store): ...@@ -139,9 +139,16 @@ def _LoadToolchainEnv(cpu, sdk_dir, target_store):
if not os.path.exists(script_path): if not os.path.exists(script_path):
# vcvarsall.bat for VS 2017 fails if run after running vcvarsall.bat from # vcvarsall.bat for VS 2017 fails if run after running vcvarsall.bat from
# VS 2013 or VS 2015. Fix this by clearing the vsinstalldir environment # VS 2013 or VS 2015. Fix this by clearing the vsinstalldir environment
# variable. # variable. Since vcvarsall.bat appends to the INCLUDE, LIB, and LIBPATH
# environment variables we need to clear those to avoid getting double
# entries when vcvarsall.bat has been run before gn gen. vcvarsall.bat
# also adds to PATH, but there is no clean way of clearing that and it
# doesn't seem to cause problems.
if 'VSINSTALLDIR' in os.environ: if 'VSINSTALLDIR' in os.environ:
del os.environ['VSINSTALLDIR'] del os.environ['VSINSTALLDIR']
del os.environ['INCLUDE']
del os.environ['LIB']
del os.environ['LIBPATH']
other_path = os.path.normpath(os.path.join( other_path = os.path.normpath(os.path.join(
os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['GYP_MSVS_OVERRIDE_PATH'],
'VC/Auxiliary/Build/vcvarsall.bat')) 'VC/Auxiliary/Build/vcvarsall.bat'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment