Skip to content

Commit

Permalink
fix: use current python interpreter for tools
Browse files Browse the repository at this point in the history
This change patches the shebang line in the tool scripts to use the
current Python interpeter. This fixes the build if either the $PATH
contains different python3 interpreter (or does not contain at all)
or /usr/bin/env is not available (e.g. Nix sandbox on macOS).
  • Loading branch information
tie committed Jun 3, 2024
1 parent 4a8e328 commit 6d804d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ def CopyTool(flavor, out_path, generator_flags={}):
with open(source_path) as source_file:
source = source_file.readlines()

# Replace hash bang line with an absolute path to the Python interpreter.
# Note that we use shebang instead of source[0] in the output.
shebang = "#!" + sys.executable + "\n"

# Set custom header flags.
header = "# Generated by gyp. Do not edit.\n"
mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
Expand All @@ -542,7 +546,7 @@ def CopyTool(flavor, out_path, generator_flags={}):
# Add header and write it out.
tool_path = os.path.join(out_path, "gyp-%s-tool" % prefix)
with open(tool_path, "w") as tool_file:
tool_file.write("".join([source[0], header] + source[1:]))
tool_file.write("".join([shebang, header] + source[1:]))

# Make file executable.
os.chmod(tool_path, 0o755)
Expand Down

0 comments on commit 6d804d9

Please sign in to comment.