mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-02 20:03:16 +00:00
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.
This commit is contained in:
parent
2ae69114a1
commit
88369997e1
@ -1,4 +1,4 @@
|
||||
{ stdenv, lib, makeDesktopItem, makeWrapper, lndir, config
|
||||
{ stdenv, lib, makeDesktopItem, makeWrapper, makeBinaryWrapper, lndir, config
|
||||
, fetchurl, zip, unzip, jq, xdg-utils, writeText
|
||||
|
||||
## various stuff that can be plugged in
|
||||
@ -229,7 +229,7 @@ let
|
||||
# Symbolic link: wrap the link's target.
|
||||
oldExe="$(readlink -v --canonicalize-existing "$executablePath")"
|
||||
rm "$executablePath"
|
||||
elif wrapperCmd=$(strings -dw "$executablePath" | sed -n '/^makeCWrapper/,/^$/ p'); [[ $wrapperCmd ]]; then
|
||||
elif wrapperCmd=$(${makeBinaryWrapper.extractCmd} "$executablePath"); [[ $wrapperCmd ]]; then
|
||||
# If the executable is a binary wrapper, we need to update its target to
|
||||
# point to $out, but we can't just edit the binary in-place because of length
|
||||
# issues. So we extract the command used to create the wrapper and add the
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user