setup-hooks/strip: add stripExclude

authored by Tim Cuthbertson and committed by Artturin 0bffcc3f 074dea1e

+31 -1
+22
doc/stdenv/stdenv.chapter.md
··· 937 937 938 938 Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`). 939 939 940 + ##### `stripExclude` {#var-stdenv-stripExclude} 941 + 942 + A list of filenames or path patterns to avoid stripping. A file is excluded if its name _or_ path (from the derivation root) matches. 943 + 944 + This example prevents all `*.rlib` files from being stripped: 945 + 946 + ```nix 947 + stdenv.mkDerivation { 948 + # ... 949 + stripExclude = [ "*.rlib" ] 950 + } 951 + ``` 952 + 953 + This example prevents files within certain paths from being stripped: 954 + 955 + ```nix 956 + stdenv.mkDerivation { 957 + # ... 958 + stripExclude = [ "lib/modules/*/build/* ] 959 + } 960 + ``` 961 + 940 962 ##### `dontPatchELF` {#var-stdenv-dontPatchELF} 941 963 942 964 If set, the `patchelf` command is not used to remove unnecessary `RPATH` entries. Only applies to Linux.
+9 -1
pkgs/build-support/setup-hooks/strip.sh
··· 49 49 local ranlibCmd="$2" 50 50 local paths="$3" 51 51 local stripFlags="$4" 52 + local excludeFlags=() 52 53 local pathsNew= 53 54 54 55 [ -z "$cmd" ] && echo "stripDirs: Strip command is empty" 1>&2 && exit 1 55 56 [ -z "$ranlibCmd" ] && echo "stripDirs: Ranlib command is empty" 1>&2 && exit 1 57 + 58 + local pattern 59 + if [ -n "${stripExclude:-}" ]; then 60 + for pattern in "${stripExclude[@]}"; do 61 + excludeFlags+=(-a '!' '(' -name "$pattern" -o -wholename "$prefix/$pattern" ')' ) 62 + done 63 + fi 56 64 57 65 local p 58 66 for p in ${paths}; do ··· 67 75 local striperr 68 76 striperr="$(mktemp --tmpdir="$TMPDIR" 'striperr.XXXXXX')" 69 77 # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh. 70 - find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 | 78 + find $paths -type f "${excludeFlags[@]}" -a '!' -path "$prefix/lib/debug/*" -print0 | 71 79 # Make sure we process files under symlinks only once. Otherwise 72 80 # 'strip` can corrupt files when writes to them in parallel: 73 81 # https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039