Commit 2131f972 authored by Sajjad Mirza's avatar Sajjad Mirza Committed by Commit Bot

[mb.py] Check multiple locations for the real python.

Sometimes the value of sys.prefix (or sys.real_prefix in vpython)
includes the bin/ directory within the python installation, and
sometimes it does not. To accommodate this, check both prefix/bin and
prefix itself for the python executable.

Bug: 1049421
Change-Id: Ia7c072dc0b4b8232ec8fdce20f9211e3c978a3ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055976
Commit-Queue: Sajjad Mirza <sajjadm@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarRobbie Iannucci <iannucci@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741574}
parent 9223f56a
...@@ -1029,12 +1029,23 @@ class MetaBuildWrapper(object): ...@@ -1029,12 +1029,23 @@ class MetaBuildWrapper(object):
# because in python 3 vpython will no longer have its current 'viral' # because in python 3 vpython will no longer have its current 'viral'
# qualities and will require explicit usage to opt in to. # qualities and will require explicit usage to opt in to.
prefix = getattr(sys, "real_prefix", sys.prefix) prefix = getattr(sys, "real_prefix", sys.prefix)
python_exe = ('%s\\bin\\python.exe' if self.platform.startswith('win') else python_exe = 'python.exe' if self.platform.startswith('win') else 'python'
'%s/bin/python') % prefix # The value of prefix varies. Sometimes it extends to include the bin/
if os.path.isfile(python_exe): # directory of the python install such that prefix/python is the intepreter,
cmd.append('--script-executable=%s' % python_exe) # 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' % python_exe)
break
else: else:
self.Print('python interpreter not under %s/bin' % prefix) self.Print('python interpreter not under %s' % prefix)
ret, output, _ = self.Run(cmd) ret, output, _ = self.Run(cmd)
if ret: if ret:
......
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