Skip to content

Commit 2b5b423

Browse files
forivallgibfahn
authored andcommitted
build: allow build with system python 3
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>
1 parent eb08e3e commit 2b5b423

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

configure

+35-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ exec python "$0" "$@"
1212
del _
1313

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

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

2121
if python2:
@@ -1350,6 +1350,36 @@ def configure_inspector(o):
13501350
options.without_ssl)
13511351
o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
13521352

1353+
1354+
def get_bin_override():
1355+
# If the system python is not the python we are running (which should be
1356+
# python 2), then create a directory with a symlink called `python` to our
1357+
# sys.executable. This directory will be prefixed to the PATH, so that
1358+
# other tools that shell out to `python` will use the appropriate python
1359+
1360+
if os.path.realpath(which('python')) == os.path.realpath(sys.executable):
1361+
return
1362+
1363+
bin_override = os.path.abspath('out/tools/bin')
1364+
try:
1365+
os.makedirs(bin_override)
1366+
except OSError as e:
1367+
if e.errno != errno.EEXIST: raise e
1368+
1369+
python_link = os.path.join(bin_override, 'python')
1370+
try:
1371+
os.unlink(python_link)
1372+
except OSError as e:
1373+
if e.errno != errno.ENOENT: raise e
1374+
os.symlink(sys.executable, python_link)
1375+
1376+
# We need to set the environment right now so that when gyp (in run_gyp)
1377+
# shells out, it finds the right python (specifically at
1378+
# https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43)
1379+
os.environ['PATH'] = bin_override + ':' + os.environ['PATH']
1380+
1381+
return bin_override
1382+
13531383
output = {
13541384
'variables': {},
13551385
'include_dirs': [],
@@ -1428,6 +1458,10 @@ if options.prefix:
14281458

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

1461+
bin_override = get_bin_override()
1462+
if bin_override:
1463+
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config
1464+
14311465
write('config.mk', do_not_edit + config)
14321466

14331467
gyp_args = ['--no-parallel']

0 commit comments

Comments
 (0)