Skip to content

Commit

Permalink
fix: do not assume that /usr/bin/env exists on macOS (#216)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tie authored Jun 28, 2024
1 parent d1299a4 commit 706d04a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
18 changes: 9 additions & 9 deletions pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def CalculateGeneratorInputInfo(params):

LINK_COMMANDS_MAC = """\
quiet_cmd_alink = LIBTOOL-STATIC $@
cmd_alink = rm -f $@ && ./gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
cmd_alink = rm -f $@ && %(python)s gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %%.o,$^)
quiet_cmd_link = LINK($(TOOLSET)) $@
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
Expand All @@ -218,7 +218,7 @@ def CalculateGeneratorInputInfo(params):
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
""" # noqa: E501
""" % {'python': sys.executable} # noqa: E501

LINK_COMMANDS_ANDROID = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
Expand Down Expand Up @@ -609,14 +609,14 @@ def CalculateGeneratorInputInfo(params):
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
# already.
quiet_cmd_mac_tool = MACTOOL $(4) $<
cmd_mac_tool = ./gyp-mac-tool $(4) $< "$@"
cmd_mac_tool = %(python)s gyp-mac-tool $(4) $< "$@"
quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
cmd_mac_package_framework = %(python)s gyp-mac-tool package-framework "$@" $(4)
quiet_cmd_infoplist = INFOPLIST $@
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
""" # noqa: E501
""" % {'python': sys.executable} # noqa: E501


def WriteRootHeaderSuffixRules(writer):
Expand Down Expand Up @@ -2498,7 +2498,7 @@ def CalculateMakefilePath(build_file, base_name):
"PLI.host": PLI_host,
}
if flavor == "mac":
flock_command = "./gyp-mac-tool flock"
flock_command = "%s gyp-mac-tool flock" % sys.executable
header_params.update(
{
"flock": flock_command,
Expand Down Expand Up @@ -2548,7 +2548,7 @@ def CalculateMakefilePath(build_file, base_name):
header_params.update(
{
"copy_archive_args": copy_archive_arguments,
"flock": "./gyp-flock-tool flock",
"flock": "%s gyp-flock-tool flock" % sys.executable,
"flock_index": 2,
}
)
Expand All @@ -2564,7 +2564,7 @@ def CalculateMakefilePath(build_file, base_name):
{
"copy_archive_args": copy_archive_arguments,
"link_commands": LINK_COMMANDS_AIX,
"flock": "./gyp-flock-tool flock",
"flock": "%s gyp-flock-tool flock" % sys.executable,
"flock_index": 2,
}
)
Expand All @@ -2574,7 +2574,7 @@ def CalculateMakefilePath(build_file, base_name):
{
"copy_archive_args": copy_archive_arguments,
"link_commands": LINK_COMMANDS_OS400,
"flock": "./gyp-flock-tool flock",
"flock": "%s gyp-flock-tool flock" % sys.executable,
"flock_index": 2,
}
)
Expand Down
29 changes: 16 additions & 13 deletions pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -2595,9 +2595,9 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
"alink",
description="LIBTOOL-STATIC $out, POSTBUILDS",
command="rm -f $out && "
"./gyp-mac-tool filter-libtool libtool $libtool_flags "
"%s gyp-mac-tool filter-libtool libtool $libtool_flags "
"-static -o $out $in"
"$postbuilds",
"$postbuilds" % sys.executable,
)
master_ninja.rule(
"lipo",
Expand Down Expand Up @@ -2698,41 +2698,44 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
master_ninja.rule(
"copy_infoplist",
description="COPY INFOPLIST $in",
command="$env ./gyp-mac-tool copy-info-plist $in $out $binary $keys",
command="$env %s gyp-mac-tool copy-info-plist $in $out $binary $keys"
% sys.executable,
)
master_ninja.rule(
"merge_infoplist",
description="MERGE INFOPLISTS $in",
command="$env ./gyp-mac-tool merge-info-plist $out $in",
command="$env %s gyp-mac-tool merge-info-plist $out $in" % sys.executable,
)
master_ninja.rule(
"compile_xcassets",
description="COMPILE XCASSETS $in",
command="$env ./gyp-mac-tool compile-xcassets $keys $in",
command="$env %s gyp-mac-tool compile-xcassets $keys $in" % sys.executable,
)
master_ninja.rule(
"compile_ios_framework_headers",
description="COMPILE HEADER MAPS AND COPY FRAMEWORK HEADERS $in",
command="$env ./gyp-mac-tool compile-ios-framework-header-map $out "
"$framework $in && $env ./gyp-mac-tool "
"copy-ios-framework-headers $framework $copy_headers",
command="$env %(python)s gyp-mac-tool compile-ios-framework-header-map "
"$out $framework $in && $env %(python)s gyp-mac-tool "
"copy-ios-framework-headers $framework $copy_headers"
% {'python': sys.executable},
)
master_ninja.rule(
"mac_tool",
description="MACTOOL $mactool_cmd $in",
command="$env ./gyp-mac-tool $mactool_cmd $in $out $binary",
command="$env %s gyp-mac-tool $mactool_cmd $in $out $binary"
% sys.executable,
)
master_ninja.rule(
"package_framework",
description="PACKAGE FRAMEWORK $out, POSTBUILDS",
command="./gyp-mac-tool package-framework $out $version$postbuilds "
"&& touch $out",
command="%s gyp-mac-tool package-framework $out $version$postbuilds "
"&& touch $out" % sys.executable,
)
master_ninja.rule(
"package_ios_framework",
description="PACKAGE IOS FRAMEWORK $out, POSTBUILDS",
command="./gyp-mac-tool package-ios-framework $out $postbuilds "
"&& touch $out",
command="%s gyp-mac-tool package-ios-framework $out $postbuilds "
"&& touch $out" % sys.executable,
)
if flavor == "win":
master_ninja.rule(
Expand Down
9 changes: 6 additions & 3 deletions pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):
# Then re-sign everything with 'preserve=True'
postbuilds.extend(
[
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
% (
sys.executable,
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
key,
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
Expand All @@ -1190,8 +1191,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):
for target in targets:
postbuilds.extend(
[
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
% (
sys.executable,
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
key,
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
Expand All @@ -1204,8 +1206,9 @@ def _GetIOSPostbuilds(self, configname, output_binary):

postbuilds.extend(
[
'%s code-sign-bundle "%s" "%s" "%s" "%s" %s'
'%s %s code-sign-bundle "%s" "%s" "%s" "%s" %s'
% (
sys.executable,
os.path.join("${TARGET_BUILD_DIR}", "gyp-mac-tool"),
key,
settings.get("CODE_SIGN_ENTITLEMENTS", ""),
Expand Down

0 comments on commit 706d04a

Please sign in to comment.