|
37 | 37 |
|
38 | 38 | echo "Patching embedded git revision in ${exe} to ${rev} ..."
|
39 | 39 |
|
40 |
| - # Ensure only one occurrence of placeholder |
41 |
| - if [[ $(grep -c -a ${placeholder} ${drv}/bin/${exe}) -ne 1 ]]; then |
42 |
| - echo "Not exactly one occurrence of ${placeholder} in ${drv}/bin/${exe}!" |
43 |
| - exit 1 |
44 |
| - fi |
45 |
| -
|
46 | 40 | mkdir -p $out/bin
|
47 |
| - sed 's/${placeholder}/${rev}/' ${drv}/bin/${exe} > $out/bin/${exe} |
48 |
| - chmod +x $out/bin/${exe} |
| 41 | + occ=$(grep -c -a ${placeholder} ${drv}/bin/${exe} || true) |
| 42 | + if [[ "$occ" = "1" ]]; then |
| 43 | + sed 's/${placeholder}/${rev}/' ${drv}/bin/${exe} > $out/bin/${exe} |
| 44 | + chmod +x $out/bin/${exe} |
| 45 | + else |
| 46 | + echo "Warning: placeholder occurrence count=$occ in ${drv}/bin/${exe}; keeping original binary without embedding revision" >&2 |
| 47 | + cp ${drv}/bin/${exe} $out/bin/${exe} |
| 48 | + chmod +x $out/bin/${exe} |
| 49 | + fi |
49 | 50 | '';
|
50 | 51 | postFixup = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
|
51 |
| - install_name_tool -add_rpath ${pkgs.zlib}/lib $out/bin/${exe} |
52 |
| - install_name_tool -add_rpath ${pkgs.lmdb}/lib $out/bin/${exe} |
53 |
| - install_name_tool -add_rpath ${pkgs.libcxx}/lib $out/bin/${exe} |
54 |
| - install_name_tool -add_rpath ${pkgs.libiconv}/lib $out/bin/${exe} |
55 |
| - install_name_tool -add_rpath ${pkgs.libffi}/lib $out/bin/${exe} |
| 52 | + if file "$out/bin/${exe}" | grep -q 'Mach-O'; then |
| 53 | + install_name_tool -add_rpath ${pkgs.zlib}/lib $out/bin/${exe} |
| 54 | + install_name_tool -add_rpath ${pkgs.lmdb}/lib $out/bin/${exe} |
| 55 | + install_name_tool -add_rpath ${pkgs.libcxx}/lib $out/bin/${exe} |
| 56 | + install_name_tool -add_rpath ${pkgs.libiconv}/lib $out/bin/${exe} |
| 57 | + install_name_tool -add_rpath ${pkgs.libffi}/lib $out/bin/${exe} |
| 58 | + else |
| 59 | + echo "Skipping install_name_tool: $out/bin/${exe} is not a Mach-O file" >&2 |
| 60 | + fi |
56 | 61 | '';
|
57 | 62 | };
|
58 | 63 |
|
|
0 commit comments