Skip to content

Commit 49908b1

Browse files
forivallMylesBorins
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 5b931d7 commit 49908b1

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:
@@ -1318,6 +1318,36 @@ def configure_inspector(o):
13181318
options.without_ssl)
13191319
o['variables']['v8_inspector'] = b(not disable_inspector)
13201320

1321+
1322+
def get_bin_override():
1323+
# If the system python is not the python we are running (which should be
1324+
# python 2), then create a directory with a symlink called `python` to our
1325+
# sys.executable. This directory will be prefixed to the PATH, so that
1326+
# other tools that shell out to `python` will use the appropriate python
1327+
1328+
if os.path.realpath(which('python')) == os.path.realpath(sys.executable):
1329+
return
1330+
1331+
bin_override = os.path.abspath('out/tools/bin')
1332+
try:
1333+
os.makedirs(bin_override)
1334+
except OSError as e:
1335+
if e.errno != errno.EEXIST: raise e
1336+
1337+
python_link = os.path.join(bin_override, 'python')
1338+
try:
1339+
os.unlink(python_link)
1340+
except OSError as e:
1341+
if e.errno != errno.ENOENT: raise e
1342+
os.symlink(sys.executable, python_link)
1343+
1344+
# We need to set the environment right now so that when gyp (in run_gyp)
1345+
# shells out, it finds the right python (specifically at
1346+
# https://github.com/nodejs/node/blob/d82e107/deps/v8/gypfiles/toolchain.gypi#L43)
1347+
os.environ['PATH'] = bin_override + ':' + os.environ['PATH']
1348+
1349+
return bin_override
1350+
13211351
output = {
13221352
'variables': {},
13231353
'include_dirs': [],
@@ -1394,6 +1424,10 @@ if options.prefix:
13941424

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

1427+
bin_override = get_bin_override()
1428+
if bin_override:
1429+
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config
1430+
13971431
write('config.mk', do_not_edit + config)
13981432

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

0 commit comments

Comments
 (0)