@@ -12,10 +12,10 @@ exec python "$0" "$@"
12
12
del _
13
13
14
14
import sys
15
+ from distutils.spawn import find_executable as which
15
16
if sys.version_info[0] ! = 2 or sys.version_info[1] not in (6, 7):
16
17
sys.stderr.write(' Please use either Python 2.6 or 2.7' )
17
18
18
- from distutils.spawn import find_executable as which
19
19
python2 = which(' python2' ) or which(' python2.6' ) or which(' python2.7' )
20
20
21
21
if python2:
@@ -1350,6 +1350,36 @@ def configure_inspector(o):
1350
1350
options.without_ssl)
1351
1351
o[' variables' ][' v8_enable_inspector' ] = 0 if disable_inspector else 1
1352
1352
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
+
1353
1383
output = {
1354
1384
' variables' : {},
1355
1385
' include_dirs' : [],
@@ -1428,6 +1458,10 @@ if options.prefix:
1428
1458
1429
1459
config = ' \n' .join(map(' =' .join, config.iteritems ())) + ' \n'
1430
1460
1461
+ bin_override = get_bin_override ()
1462
+ if bin_override:
1463
+ config = ' export PATH:=' + bin_override + ' :$(PATH)\n' + config
1464
+
1431
1465
write(' config.mk' , do_not_edit + config)
1432
1466
1433
1467
gyp_args = [' --no-parallel' ]
0 commit comments