Skip to content

tools,build: use the python interpreter running gyp througout the whole build process #27476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,40 +1523,6 @@ def configure_inspector(o):
options.without_ssl)
o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1


def make_bin_override():
if sys.platform == 'win32':
raise Exception('make_bin_override should not be called on win32.')
# 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

which_python = which('python')
if (which_python and
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': [],
Expand Down Expand Up @@ -1638,14 +1604,11 @@ def make_bin_override():

config = '\n'.join(['='.join(item) for item in config.items()]) + '\n'

# On Windows there's no reason to search for a different python binary.
bin_override = None if sys.platform == 'win32' else make_bin_override()
if bin_override:
config = 'export PATH:=' + bin_override + ':$(PATH)\n' + config
os.environ['PYTHON_EXECUTABLE'] = sys.executable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is not used in the context of this PR.


write('config.mk', do_not_edit + config)

gyp_args = ['--no-parallel', '-Dconfiguring_node=1']
gyp_args = ['--no-parallel', '-Dconfiguring_node=1', "-DPYTHON_EXECUTABLE=%s" % sys.executable]

if options.use_ninja:
gyp_args += ['-f', 'ninja']
Expand Down
4 changes: 2 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
'process_outputs_as_sources': 1,
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'tools/mkssldef.py',
'<@(mkssldef_flags)',
'-o',
Expand Down Expand Up @@ -873,7 +873,7 @@
}]
],
'action': [
'python', 'tools/js2c.py',
'<(PYTHON_EXECUTABLE)', 'tools/js2c.py',
'<@(_outputs)',
'<@(_inputs)',
],
Expand Down
8 changes: 4 additions & 4 deletions src/inspector/node_inspector.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'<(SHARED_INTERMEDIATE_DIR)/src/node_protocol.json',
],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'tools/inspector_protocol/convert_protocol_to_json.py',
'<@(_inputs)',
'<@(_outputs)',
Expand All @@ -95,7 +95,7 @@
],
'process_outputs_as_sources': 1,
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'tools/inspector_protocol/code_generator.py',
'--jinja_dir', '<@(protocol_tool_path)',
'--output_base', '<(SHARED_INTERMEDIATE_DIR)/src/',
Expand All @@ -113,7 +113,7 @@
'<(SHARED_INTERMEDIATE_DIR)/concatenated_protocol.json',
],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'tools/inspector_protocol/concatenate_protocols.py',
'<@(_inputs)',
'<@(_outputs)',
Expand All @@ -129,7 +129,7 @@
],
'process_outputs_as_sources': 1,
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'tools/compress_json.py',
'<@(_inputs)',
'<@(_outputs)',
Expand Down
2 changes: 2 additions & 0 deletions tools/gyp/gyp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Make sure we're using the version of pylib in this repo, not one installed
# elsewhere on the system.
sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), 'pylib'))
sys.argv.append("-DPYTHON_EXECUTABLE=" + os.path.realpath(sys.executable))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be upstreamed to https://github.com/refack/GYP

In the context of this PR it's not necessary as there are should no be any direct calls to GYP outside of through ./configure

os.environ['PYTHON_EXECUTABLE'] = os.path.realpath(sys.executable)
import gyp

if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tools/gyp/pylib/gyp/generator/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ def Finalize1(self, xcode_targets, serialize_all_tests):
command_prefix = ''
if serialize_all_tests:
command_prefix = \
"""python -c "import fcntl, subprocess, sys
"""%s -c "import fcntl, subprocess, sys
file = open('$TMPDIR/GYP_serialize_test_runs', 'a')
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
sys.exit(subprocess.call(sys.argv[1:]))" """
sys.exit(subprocess.call(sys.argv[1:]))" """ % (sys.executable)

# If we were unable to exec for some reason, we want to exit
# with an error, and fixup variable references to be shell
Expand Down
4 changes: 2 additions & 2 deletions tools/icu/icu-generic.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
'msvs_quote_cmd': 0,
'inputs': [ '<(icu_data_in)', 'icu_small.json' ],
'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/icutmp/icudt<(icu_ver_major)<(icu_endianness).dat' ],
'action': [ 'python',
'action': [ '<(PYTHON_EXECUTABLE)',
'icutrim.py',
'-P', '<(PRODUCT_DIR)/.', # '.' suffix is a workaround against GYP assumptions :(
'-D', '<(icu_data_in)',
Expand Down Expand Up @@ -322,7 +322,7 @@
'action_name': 'icutrim',
'inputs': [ '<(icu_data_in)', 'icu_small.json' ],
'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/icutmp/icudt<(icu_ver_major)<(icu_endianness).dat' ],
'action': [ 'python',
'action': [ '<(PYTHON_EXECUTABLE)',
'icutrim.py',
'-P', '<(PRODUCT_DIR)',
'-D', '<(icu_data_in)',
Expand Down
2 changes: 1 addition & 1 deletion tools/v8_gypfiles/broken/shim_headers.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
'outputs': [
'<!@pymod_do_main(generate_shim_headers <@(generator_args) --outputs)',
],
'action': ['python',
'action': ['<(PYTHON_EXECUTABLE)',
'<(generator_path)',
'<@(generator_args)',
'--generate',
Expand Down
4 changes: 2 additions & 2 deletions tools/v8_gypfiles/inspector.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
'<@(inspector_generated_output_root)/src/js_protocol.stamp',
],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'<(inspector_protocol_path)/check_protocol_compatibility.py',
'--stamp', '<@(_outputs)',
'<@(_inputs)',
Expand All @@ -118,7 +118,7 @@
],
'process_outputs_as_sources': 1,
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'<(inspector_protocol_path)/code_generator.py',
'--jinja_dir', '<(V8_ROOT)/third_party',
'--output_base', '<(inspector_generated_output_root)/src/inspector',
Expand Down
2 changes: 1 addition & 1 deletion tools/v8_gypfiles/toolchain.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'has_valgrind%': 0,
'coverage%': 0,
'v8_target_arch%': '<(target_arch)',
'v8_host_byteorder%': '<!(python -c "import sys; print(sys.byteorder)")',
'v8_host_byteorder%': '<!<(PYTHON_EXECUTABLE) -c "import sys; print sys.byteorder")',
'force_dynamic_crt%': 0,

# Setting 'v8_can_use_vfp32dregs' to 'true' will cause V8 to use the VFP
Expand Down
6 changes: 3 additions & 3 deletions tools/v8_gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
}],
],
'action': [
'python', '<(V8_ROOT)/tools/testrunner/utils/dump_build_config_gyp.py',
'<(PYTHON_EXECUTABLE)', '<(V8_ROOT)/tools/testrunner/utils/dump_build_config_gyp.py',
'<@(v8_dump_build_config_args)',
],
},
Expand Down Expand Up @@ -2633,7 +2633,7 @@
'<(SHARED_INTERMEDIATE_DIR)/debug-support.cc',
],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'<(V8_ROOT)/tools/gen-postmortem-metadata.py',
'<@(_outputs)',
'<@(heapobject_files)'
Expand Down Expand Up @@ -2702,7 +2702,7 @@
'<(generate_bytecode_builtins_list_output)',
],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'<(V8_ROOT)/tools/run.py',
'<@(_inputs)',
'<@(_outputs)',
Expand Down
8 changes: 4 additions & 4 deletions tools/v8_gypfiles/v8_external_snapshot.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
],
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/libraries-extras.bin'],
'action': [
'python',
'<(PYTHON_EXECUTABLE)',
'<(V8_ROOT)/tools/js2c.py',
'<(SHARED_INTERMEDIATE_DIR)/extras-libraries.cc',
'EXTRAS',
Expand All @@ -172,14 +172,14 @@
'<(PRODUCT_DIR)/natives_blob_host.bin',
],
'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob_host.bin'
'<(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob_host.bin'
],
}, {
'outputs': [
'<(PRODUCT_DIR)/natives_blob.bin',
],
'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
'<(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
],
}],
],
Expand All @@ -188,7 +188,7 @@
'<(PRODUCT_DIR)/natives_blob.bin',
],
'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
'<(PYTHON_EXECUTABLE)', '<@(_inputs)', '<(PRODUCT_DIR)/natives_blob.bin'
],
}],
],
Expand Down