Commit 92ffd1a8 authored by Karen Qian's avatar Karen Qian Committed by Commit Bot

Pruning virtualenv from environment in mb.py.

Bug: 996624
Change-Id: Ibdaf0267017ff652431822bd53bf1d982b254401
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1795757Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: default avatarRobbie Iannucci <iannucci@chromium.org>
Commit-Queue: Karen Qian <karenqian@google.com>
Cr-Commit-Position: refs/heads/master@{#695426}
parent 5c29c267
...@@ -28,15 +28,21 @@ def _ExtractImportantEnvironment(output_of_set): ...@@ -28,15 +28,21 @@ def _ExtractImportantEnvironment(output_of_set):
"""Extracts environment variables required for the toolchain to run from """Extracts environment variables required for the toolchain to run from
a textual dump output by the cmd.exe 'set' command.""" a textual dump output by the cmd.exe 'set' command."""
envvars_to_save = ( envvars_to_save = (
'cipd_cache_dir', # needed by vpython
'homedrive', # needed by vpython
'homepath', # needed by vpython
'goma_.*', # TODO(scottmg): This is ugly, but needed for goma. 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma.
'include', 'include',
'lib', 'lib',
'libpath', 'libpath',
'luci_context', # needed by vpython
'path', 'path',
'pathext', 'pathext',
'systemroot', 'systemroot',
'temp', 'temp',
'tmp', 'tmp',
'userprofile', # needed by vpython
'vpython_virtualenv_root' # needed by vpython
) )
env = {} env = {}
# This occasionally happens and leads to misleading SYSTEMROOT error messages # This occasionally happens and leads to misleading SYSTEMROOT error messages
......
...@@ -36,8 +36,31 @@ sys.path = [os.path.join(CHROMIUM_SRC_DIR, 'build')] + sys.path ...@@ -36,8 +36,31 @@ sys.path = [os.path.join(CHROMIUM_SRC_DIR, 'build')] + sys.path
import gn_helpers import gn_helpers
def PruneVirtualEnv():
# Set by VirtualEnv, no need to keep it.
os.environ.pop('VIRTUAL_ENV', None)
# Set by VPython, if scripts want it back they have to set it explicitly.
os.environ.pop('PYTHONNOUSERSITE', None)
# Look for "activate_this.py" in this path, which is installed by VirtualEnv.
# This mechanism is used by vpython as well to sanitize VirtualEnvs from
# $PATH.
os.environ['PATH'] = os.pathsep.join([
p for p in os.environ.get('PATH', '').split(os.pathsep)
if not os.path.isfile(os.path.join(p, 'activate_this.py'))
])
def main(args): def main(args):
# Prune all evidence of VPython/VirtualEnv out of the environment. This means
# that we 'unwrap' vpython VirtualEnv path/env manipulation. Invocations of
# `python` from GN should never inherit the gn.py's own VirtualEnv. This also
# helps to ensure that generated ninja files do not reference python.exe from
# the VirtualEnv generated from depot_tools' own .vpython file (or lack
# thereof), but instead reference the default python from the PATH.
PruneVirtualEnv()
mbw = MetaBuildWrapper() mbw = MetaBuildWrapper()
return mbw.Main(args) return mbw.Main(args)
......
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