diff --git a/.gn b/.gn index 2a74dea33bd644..f218361a05b55a 100644 --- a/.gn +++ b/.gn @@ -8,10 +8,6 @@ import("//third_party/angle/dotfile_settings.gni") # The location of the build configuration file. buildconfig = "//build/config/BUILDCONFIG.gn" -# The python interpreter to use by default. On Windows, this will look -# for python3.exe and python3.bat. -script_executable = "python3" - # These arguments override the default values for items in a declare_args # block. "gn args" in turn can override these. # diff --git a/tools/mb/mb.py b/tools/mb/mb.py index 1ee7fff2cc9232..9275cb07d6451e 100755 --- a/tools/mb/mb.py +++ b/tools/mb/mb.py @@ -1087,6 +1087,33 @@ def RunGNGen(self, vals, compute_inputs_for_analyze=False, check=True): self.WriteFile(gn_runtime_deps_path, '\n'.join(labels) + '\n') cmd.append('--runtime-deps-list-file=%s' % gn_runtime_deps_path) + # Detect if we are running in a vpython interpreter, and if so force GN to + # use the real python interpreter. crbug.com/1049421 + # This ensures that ninja will only use the real python interpreter and not + # vpython, so that any python scripts in the build will only use python + # modules vendored into //third_party. + # This can be deleted when python 3 becomes the only supported interpreter, + # because in python 3 vpython will no longer have its current 'viral' + # qualities and will require explicit usage to opt in to. + prefix = getattr(sys, "real_prefix", sys.prefix) + python_exe = 'python.exe' if self.platform.startswith('win') else 'python' + # The value of prefix varies. Sometimes it extends to include the bin/ + # directory of the python install such that prefix/python is the + # interpreter, and other times prefix/bin/python is the interpreter. + # Therefore we need to check both. Also, it is safer to check prefix/bin + # first because there have been previous installs where prefix/bin/python + # was the real binary and prefix/python was actually vpython-native. + possible_python_locations = [ + os.path.join(prefix, 'bin', python_exe), + os.path.join(prefix, python_exe), + ] + for p in possible_python_locations: + if os.path.isfile(p): + cmd.append('--script-executable=%s' % p) + break + else: + self.Print('python interpreter not under %s' % prefix) + ret, output, _ = self.Run(cmd) if ret != 0: if self.args.json_output: