Skip to content

Commit 73bcd94

Browse files
committed
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
1 parent 2da7d9b commit 73bcd94

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

configure

+34
Original file line numberDiff line numberDiff line change
@@ -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+
bin_override = None
1354+
1355+
def setup_bin_overrides():
1356+
global bin_override
1357+
# If the system python is not the python we are running (which should be
1358+
# python 2), then create a directory with a symlink called `python` to our
1359+
# sys.executable. This directory will be prefixed to the PATH, so that
1360+
# other tools that shell out to `python` will use the appropriate python
1361+
1362+
from distutils.spawn import find_executable as which
1363+
if os.path.realpath(which('python')) == os.path.realpath(sys.executable):
1364+
return
1365+
1366+
bin_override = os.path.abspath('out/tools/bin')
1367+
try:
1368+
os.makedirs(bin_override)
1369+
except os.error as e:
1370+
if e.errno != errno.EEXIST:
1371+
raise e
1372+
1373+
python_link = os.path.join(bin_override, 'python')
1374+
try:
1375+
os.unlink(python_link)
1376+
except os.error as e:
1377+
if e.errno != errno.ENOENT:
1378+
raise e
1379+
os.symlink(sys.executable, python_link)
1380+
1381+
os.environ['PATH'] = bin_override + ':' + os.environ['PATH']
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+
setup_bin_overrides()
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)