Skip to content

Commit 43509c3

Browse files
committed
fix: do not assume that /usr/bin/env exists on macOS
For example, when building in Nix sandbox, /usr/bin/env is not available. This change also makes gyp tool execution consistent with gyp-win-tool that uses sys.executable on Windows.
1 parent 7e13b43 commit 43509c3

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

pylib/gyp/generator/make.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import re
2727
import subprocess
28+
import sys
2829
import gyp
2930
import gyp.common
3031
import gyp.xcode_emulation
@@ -207,7 +208,7 @@ def CalculateGeneratorInputInfo(params):
207208

208209
LINK_COMMANDS_MAC = """\
209210
quiet_cmd_alink = LIBTOOL-STATIC $@
210-
cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
211+
cmd_alink = rm -f $@ && %(python)s gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %%.o,$^)
211212
212213
quiet_cmd_link = LINK($(TOOLSET)) $@
213214
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
@@ -217,7 +218,7 @@ def CalculateGeneratorInputInfo(params):
217218
218219
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
219220
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
220-
""" # noqa: E501
221+
""" % {'python': sys.executable} # noqa: E501
221222

222223
LINK_COMMANDS_ANDROID = """\
223224
quiet_cmd_alink = AR($(TOOLSET)) $@
@@ -600,14 +601,14 @@ def CalculateGeneratorInputInfo(params):
600601
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
601602
# already.
602603
quiet_cmd_mac_tool = MACTOOL $(4) $<
603-
cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
604+
cmd_mac_tool = %(python)s gyp-mac-tool $(4) $< "$@"
604605
605606
quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
606-
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
607+
cmd_mac_package_framework = %(python)s gyp-mac-tool package-framework "$@" $(4)
607608
608609
quiet_cmd_infoplist = INFOPLIST $@
609610
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
610-
""" # noqa: E501
611+
""" % {'python': sys.executable} # noqa: E501
611612

612613

613614
def WriteRootHeaderSuffixRules(writer):
@@ -2464,7 +2465,7 @@ def CalculateMakefilePath(build_file, base_name):
24642465
"PLI.host": GetEnvironFallback(("PLI_host", "PLI"), "pli"),
24652466
}
24662467
if flavor == "mac":
2467-
flock_command = "./gyp-mac-tool flock"
2468+
flock_command = "%s gyp-mac-tool flock" % sys.executable
24682469
header_params.update(
24692470
{
24702471
"flock": flock_command,
@@ -2514,7 +2515,7 @@ def CalculateMakefilePath(build_file, base_name):
25142515
header_params.update(
25152516
{
25162517
"copy_archive_args": copy_archive_arguments,
2517-
"flock": "./gyp-flock-tool flock",
2518+
"flock": "%s gyp-flock-tool flock" % sys.executable,
25182519
"flock_index": 2,
25192520
}
25202521
)
@@ -2530,7 +2531,7 @@ def CalculateMakefilePath(build_file, base_name):
25302531
{
25312532
"copy_archive_args": copy_archive_arguments,
25322533
"link_commands": LINK_COMMANDS_AIX,
2533-
"flock": "./gyp-flock-tool flock",
2534+
"flock": "%s gyp-flock-tool flock" % sys.executable,
25342535
"flock_index": 2,
25352536
}
25362537
)
@@ -2540,7 +2541,7 @@ def CalculateMakefilePath(build_file, base_name):
25402541
{
25412542
"copy_archive_args": copy_archive_arguments,
25422543
"link_commands": LINK_COMMANDS_OS400,
2543-
"flock": "./gyp-flock-tool flock",
2544+
"flock": "%s gyp-flock-tool flock" % sys.executable,
25442545
"flock_index": 2,
25452546
}
25462547
)

pylib/gyp/generator/ninja.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,9 +2593,9 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
25932593
"alink",
25942594
description="LIBTOOL-STATIC $out, POSTBUILDS",
25952595
command="rm -f $out && "
2596-
"./gyp-mac-tool filter-libtool libtool $libtool_flags "
2596+
"%s gyp-mac-tool filter-libtool libtool $libtool_flags "
25972597
"-static -o $out $in"
2598-
"$postbuilds",
2598+
"$postbuilds" % sys.executable,
25992599
)
26002600
master_ninja.rule(
26012601
"lipo",
@@ -2696,41 +2696,44 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
26962696
master_ninja.rule(
26972697
"copy_infoplist",
26982698
description="COPY INFOPLIST $in",
2699-
command="$env ./gyp-mac-tool copy-info-plist $in $out $binary $keys",
2699+
command="$env %s gyp-mac-tool copy-info-plist $in $out $binary $keys"
2700+
% sys.executable,
27002701
)
27012702
master_ninja.rule(
27022703
"merge_infoplist",
27032704
description="MERGE INFOPLISTS $in",
2704-
command="$env ./gyp-mac-tool merge-info-plist $out $in",
2705+
command="$env %s gyp-mac-tool merge-info-plist $out $in" % sys.executable,
27052706
)
27062707
master_ninja.rule(
27072708
"compile_xcassets",
27082709
description="COMPILE XCASSETS $in",
2709-
command="$env ./gyp-mac-tool compile-xcassets $keys $in",
2710+
command="$env %s gyp-mac-tool compile-xcassets $keys $in" % sys.executable,
27102711
)
27112712
master_ninja.rule(
27122713
"compile_ios_framework_headers",
27132714
description="COMPILE HEADER MAPS AND COPY FRAMEWORK HEADERS $in",
2714-
command="$env ./gyp-mac-tool compile-ios-framework-header-map $out "
2715-
"$framework $in && $env ./gyp-mac-tool "
2716-
"copy-ios-framework-headers $framework $copy_headers",
2715+
command="$env %(python)s gyp-mac-tool compile-ios-framework-header-map "
2716+
"$out $framework $in && $env %(python)s gyp-mac-tool "
2717+
"copy-ios-framework-headers $framework $copy_headers"
2718+
% {'python': sys.executable},
27172719
)
27182720
master_ninja.rule(
27192721
"mac_tool",
27202722
description="MACTOOL $mactool_cmd $in",
2721-
command="$env ./gyp-mac-tool $mactool_cmd $in $out $binary",
2723+
command="$env %s gyp-mac-tool $mactool_cmd $in $out $binary"
2724+
% sys.executable,
27222725
)
27232726
master_ninja.rule(
27242727
"package_framework",
27252728
description="PACKAGE FRAMEWORK $out, POSTBUILDS",
2726-
command="./gyp-mac-tool package-framework $out $version$postbuilds "
2727-
"&& touch $out",
2729+
command="%s gyp-mac-tool package-framework $out $version$postbuilds "
2730+
"&& touch $out" % sys.executable,
27282731
)
27292732
master_ninja.rule(
27302733
"package_ios_framework",
27312734
description="PACKAGE IOS FRAMEWORK $out, POSTBUILDS",
2732-
command="./gyp-mac-tool package-ios-framework $out $postbuilds "
2733-
"&& touch $out",
2735+
command="%s gyp-mac-tool package-ios-framework $out $postbuilds "
2736+
"&& touch $out" % sys.executable,
27342737
)
27352738
if flavor == "win":
27362739
master_ninja.rule(

pylib/gyp/xcode_emulation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):
11741174
# Then re-sign everything with 'preserve=True'
11751175
postbuilds.extend(
11761176
[
1177-
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1177+
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
11781178
% (
1179+
sys.executable,
11791180
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
11801181
key,
11811182
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
@@ -1190,8 +1191,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):
11901191
for target in targets:
11911192
postbuilds.extend(
11921193
[
1193-
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1194+
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
11941195
% (
1196+
sys.executable,
11951197
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
11961198
key,
11971199
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
@@ -1204,8 +1206,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):
12041206

12051207
postbuilds.extend(
12061208
[
1207-
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
1209+
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
12081210
% (
1211+
sys.executable,
12091212
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
12101213
key,
12111214
settings.get("CODE_SIGN_ENTITLEMENTS", ""),

0 commit comments

Comments
 (0)