diff options
author | Emily Marigold Klassen <forivall@gmail.com> | 2017-10-06 16:49:45 -0700 |
---|---|---|
committer | Gibson Fahnestock <gibfahn@gmail.com> | 2017-10-08 07:42:44 -0700 |
commit | 2b5b423dffec7e2250e6153c6d6c3a21d7086664 (patch) | |
tree | 18c8a0f606fd79f2dac4cc46e53d4da6e93c601f /configure | |
parent | eb08e3e5fb71d9f33ff97e1ce4605fbf5a60315c (diff) | |
download | android-node-v8-2b5b423dffec7e2250e6153c6d6c3a21d7086664.tar.gz android-node-v8-2b5b423dffec7e2250e6153c6d6c3a21d7086664.tar.bz2 android-node-v8-2b5b423dffec7e2250e6153c6d6c3a21d7086664.zip |
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -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: @@ -1350,6 +1350,36 @@ def configure_inspector(o): options.without_ssl) o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1 + +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': [], @@ -1428,6 +1458,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'] |