Skip to content

Commit 162908a

Browse files
committed
Add fall-back to /usr/bin/codesign
... in case the `codesign` binary is not part of the directory where the `ar` tool resides. This might happen when not using a toolchain configured by nixpkgs_cc_configure, but instead using one from a nix-shell. The codesign tool is not part of a nixpkgs stdenv cc toolchain by default.
1 parent c6c8dcc commit 162908a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

haskell/private/cc_wrapper.py.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,16 @@ def darwin_rewrite_load_commands(rewrites, output):
931931
if args:
932932
subprocess.check_call([INSTALL_NAME_TOOL] + args + [output])
933933
# Resign the binary after patching it.
934+
# Fall back to /usr/bin/codesign if the `CODESIGN` executable is not available
935+
# (this might happen when using a default cc toolchain from a nix shell on Darwin instead
936+
# of using a nixpkgs_cc_configure'd toolchain).
937+
codesign = CODESIGN if os.access(CODESIGN, os.X_OK) else "/usr/bin/codesign"
934938
# This is necessary on MacOS Monterey on M1.
935939
# The moving back and forth is necessary because the OS caches the signature.
936940
# See this note from nixpkgs for reference:
937941
# https://github.com/NixOS/nixpkgs/blob/5855ff74f511423e3e2646248598b3ffff229223/pkgs/os-specific/darwin/signing-utils/utils.sh#L1-L6
938942
os.rename(output, f"{output}.resign")
939-
subprocess.check_call([CODESIGN] + ["-f", "-s", "-"] + [f"{output}.resign"], env = {'CODESIGN_ALLOCATE': CODESIGN_ALLOCATE})
943+
subprocess.check_call([codesign] + ["-f", "-s", "-"] + [f"{output}.resign"], env = {'CODESIGN_ALLOCATE': CODESIGN_ALLOCATE})
940944
os.rename(f"{output}.resign", output)
941945

942946

0 commit comments

Comments
 (0)