summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/make-binary-wrapper
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-05-11 22:00:24 +0200
committerNaïm Favier <n@monade.li>2022-05-12 01:44:02 +0200
commit88369997e1db7e1819b7b940fc2740f188d6608d (patch)
treed05c589c2f01f53ec3f6f76e5d99e97505c56107 /pkgs/build-support/setup-hooks/make-binary-wrapper
parent2ae69114a11c6a80a58abc6984fde8851ee8fe40 (diff)
downloadnixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar.gz
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar.bz2
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar.lz
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar.xz
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.tar.zst
nixpkgs-88369997e1db7e1819b7b940fc2740f188d6608d.zip
makeBinaryWrapper: add extractCmd
A small shell script that can be used to extract a binary wrapper's
makeCWrapper call from its embedded docstring, without depending on
makeBinaryWrapper.
Diffstat (limited to 'pkgs/build-support/setup-hooks/make-binary-wrapper')
-rw-r--r--pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix6
-rw-r--r--pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh7
2 files changed, 10 insertions, 3 deletions
diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix
index a78d52fb42c..318624011b7 100644
--- a/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix
+++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/default.nix
@@ -3,6 +3,7 @@
 , darwin
 , makeSetupHook
 , dieHook
+, writeShellScript
 , tests
 , cc ? stdenv.cc
 , sanitizers ? []
@@ -18,6 +19,11 @@ makeSetupHook {
       san = lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers);
     in "${cc}/bin/cc ${san}";
 
+    # Extract the function call used to create a binary wrapper from its embedded docstring
+    passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''
+      strings -dw "$1" | sed -n '/^makeCWrapper/,/^$/ p'
+    '';
+
     passthru.tests = tests.makeBinaryWrapper;
   };
 } ./make-binary-wrapper.sh
diff --git a/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh
index ff3f1d3f0c7..6b8f5d60eb6 100644
--- a/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh
+++ b/pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh
@@ -311,8 +311,9 @@ void set_env_suffix(char *env, char *sep, char *suffix) {
 "
 }
 
-# Embed a C string which shows up as readable text in the compiled binary wrapper
-# documentationString ARGS
+# Embed a C string which shows up as readable text in the compiled binary wrapper,
+# giving instructions for recreating the wrapper.
+# Keep in sync with makeBinaryWrapper.extractCmd
 docstring() {
     printf '%s' "const char * DOCSTRING = \"$(escapeStringLiteral "
 
@@ -333,7 +334,7 @@ makeCWrapper $(formatArgs "$@")
 
 # formatArgs EXECUTABLE ARGS
 formatArgs() {
-    printf '%s' "$1"
+    printf '%s' "${1@Q}"
     shift
     while [ $# -gt 0 ]; do
         case "$1" in