Skip to content

Commit

Permalink
build: allow build with system python 3
Browse files Browse the repository at this point in the history
When the system python is python 3, configure now creates a directory
with a symlink called 'python' to python2, uses it when it calls
run_gyp, and puts it in config.mk so that it propagates to everything
that make launches

PR-URL: #16058
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
forivall authored and MylesBorins committed Nov 28, 2017
1 parent 4005ed6 commit d4b3b63
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ exec python "$0" "$@"
del _

import sys
from distutils.spawn import find_executable as which
if sys.version_info[0] != 2 or sys.version_info[1] not in (6, 7):
sys.stderr.write('Please use either Python 2.6 or 2.7')

from distutils.spawn import find_executable as which
python2 = which('python2') or which('python2.6') or which('python2.7')

if python2:
Expand Down Expand Up @@ -1318,6 +1318,36 @@ def configure_inspector(o):
options.without_ssl)
o['variables']['v8_inspector'] = b(not disable_inspector)


def get_bin_override():
# If the system python is not the python we are running (which should be
# python 2), then create a directory with a symlink called `python` to our
# sys.executable. This directory will be prefixed to the PATH, so that
# other tools that shell out to `python` will use the appropriate python

if os.path.realpath(which('python')) == os.path.realpath(sys.executable):
return

bin_override = os.path.abspath('out/tools/bin')
try:
os.makedirs(bin_override)
except OSError as e:
if e.errno != errno.EEXIST: raise e

python_link = os.path.join(bin_override, 'python')
try:
os.unlink(python_link)
except OSError as e:
if e.errno != errno.ENOENT: raise e
os.symlink(sys.executable, python_link)

# We need to set the environment right now so that when gyp (in run_gyp)
# shells out, it finds the right python (specifically at
# https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43)
os.environ['PATH'] = bin_override + ':' + os.environ['PATH']

return bin_override

output = {
'variables': {},
'include_dirs': [],
Expand Down Expand Up @@ -1394,6 +1424,10 @@ if options.prefix:

config = '\n'.join(map('='.join, config.iteritems())) + '\n'

bin_override = get_bin_override()
if bin_override:
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config

write('config.mk', do_not_edit + config)

gyp_args = ['--no-parallel']
Expand Down

0 comments on commit d4b3b63

Please sign in to comment.