mass rewrite of find parameters to cross-platform style

Fixes #9044, close #9667. Thanks to @taku0 for suggesting this solution.
Now we have no modes starting with `/` or `+`.

Rewrite the `-perm` parameters of find:
 - completely safe: rewrite `/0100` and `+100` to `-0100`,
 - slightly semantics-changing: rewrite `+111` to `-0100`.
I cross-verified the `find` manual pages for Linux, Darwin, FreeBSD.
This commit is contained in:
Vladimír Čunát 2015-09-06 10:21:43 +02:00
parent f67ddbaa6f
commit 8f33b8cc93
23 changed files with 27 additions and 27 deletions

View File

@ -52,7 +52,7 @@ in stdenv.mkDerivation {
RPATH=${libPaths}:$out/${appdir} RPATH=${libPaths}:$out/${appdir}
echo "Updating rpaths to $RPATH in:" echo "Updating rpaths to $RPATH in:"
find "$out/${appdir}" -type f -a -perm /0100 \ find "$out/${appdir}" -type f -a -perm -0100 \
-print -exec patchelf --force-rpath --set-rpath "$RPATH" {} \; -print -exec patchelf --force-rpath --set-rpath "$RPATH" {} \;
''; '';

View File

@ -101,12 +101,12 @@ in stdenv.mkDerivation {
rm "$out/${appdir}/qt.conf" rm "$out/${appdir}/qt.conf"
rm -fr "$out/${appdir}/plugins" rm -fr "$out/${appdir}/plugins"
find "$out/${appdir}" -type f -a -perm /0100 \ find "$out/${appdir}" -type f -a -perm -0100 \
-print -exec patchelf --set-interpreter ${stdenv.glibc}/lib/${interpreter} {} \; -print -exec patchelf --set-interpreter ${stdenv.glibc}/lib/${interpreter} {} \;
RPATH=${ldpath}:${gcc.cc}/lib:$out/${appdir} RPATH=${ldpath}:${gcc.cc}/lib:$out/${appdir}
echo "updating rpaths to: $RPATH" echo "updating rpaths to: $RPATH"
find "$out/${appdir}" -type f -a -perm /0100 \ find "$out/${appdir}" -type f -a -perm -0100 \
-print -exec patchelf --force-rpath --set-rpath "$RPATH" {} \; -print -exec patchelf --force-rpath --set-rpath "$RPATH" {} \;
mkdir -p "$out/share/applications" mkdir -p "$out/share/applications"

View File

@ -20,9 +20,9 @@ stdenv.mkDerivation {
buildPhase = '' buildPhase = ''
find . -name Makefile | xargs sed -i -e "s@/bin/rm@$(type -P rm)@g" find . -name Makefile | xargs sed -i -e "s@/bin/rm@$(type -P rm)@g"
find . -name Makefile | xargs sed -i -e "s@/bin/mv@$(type -P mv)@g" find . -name Makefile | xargs sed -i -e "s@/bin/mv@$(type -P mv)@g"
find . -perm +111 -type f | xargs sed -i -e "s@/bin/csh@$(type -P csh)@g" find . -perm -0100 -type f | xargs sed -i -e "s@/bin/csh@$(type -P csh)@g"
find . -perm +111 -type f | xargs sed -i -e "s@/bin/rm@$(type -P rm)@g" find . -perm -0100 -type f | xargs sed -i -e "s@/bin/rm@$(type -P rm)@g"
find . -perm +111 -type f | xargs sed -i -e "s@/bin/mv@$(type -P mv)@g" find . -perm -0100 -type f | xargs sed -i -e "s@/bin/mv@$(type -P mv)@g"
sed -i -e "s/^XLIBS *=.*/XLIBS=-lXaw -lXt -lX11/" source/formed/Makefile sed -i -e "s/^XLIBS *=.*/XLIBS=-lXaw -lXt -lX11/" source/formed/Makefile

View File

@ -82,7 +82,7 @@ rec {
find . -name '*.so' -exec cp '{}' $out/lib ';' find . -name '*.so' -exec cp '{}' $out/lib ';'
find . -name '*.txt' -exec cp '{}' $out/share/${name}/doc ';' find . -name '*.txt' -exec cp '{}' $out/share/${name}/doc ';'
find . -name '*.hlp' -exec cp '{}' $out/share/${name}/doc ';' find . -name '*.hlp' -exec cp '{}' $out/share/${name}/doc ';'
find . -perm +111 -a ! -name '*.*' -exec cp '{}' $out/bin ';' find . -perm -0100 -a ! -name '*.*' -exec cp '{}' $out/bin ';'
cp -r . $out/share/${name}/build-snapshot cp -r . $out/share/${name}/build-snapshot
'') ["buildContent" "defEnsureDir" "minInit"]; '') ["buildContent" "defEnsureDir" "minInit"];

View File

@ -86,7 +86,7 @@ stdenv.mkDerivation rec {
preFixup = '' preFixup = ''
echo "=== PatchElfing away ===" echo "=== PatchElfing away ==="
find $out/libexec/Mathematica/SystemFiles -type f -perm +100 | while read f; do find $out/libexec/Mathematica/SystemFiles -type f -perm -0100 | while read f; do
type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/') type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/')
if [ -z "$type" ]; then if [ -z "$type" ]; then
: :

View File

@ -96,7 +96,7 @@ stdenv.mkDerivation rec {
preFixup = '' preFixup = ''
echo "=== PatchElfing away ===" echo "=== PatchElfing away ==="
find $out/libexec/Mathematica/SystemFiles -type f -perm +100 | while read f; do find $out/libexec/Mathematica/SystemFiles -type f -perm -0100 | while read f; do
type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/') type=$(readelf -h "$f" 2>/dev/null | grep 'Type:' | sed -e 's/ *Type: *\([A-Z]*\) (.*/\1/')
if [ -z "$type" ]; then if [ -z "$type" ]; then
: :

View File

@ -569,7 +569,7 @@ let inherit (builtins) head tail trace; in
# Interpreters that are already in the store are left untouched. # Interpreters that are already in the store are left untouched.
echo "patching script interpreter paths" echo "patching script interpreter paths"
local f local f
for f in $(find "${dir}" -xtype f -perm /0100); do for f in $(find "${dir}" -xtype f -perm -0100); do
local oldPath=$(sed -ne '1 s,^#![ ]*\([^ ]*\).*$,\1,p' "$f") local oldPath=$(sed -ne '1 s,^#![ ]*\([^ ]*\).*$,\1,p' "$f")
if test -n "$oldPath" -a "''${oldPath:0:''${#NIX_STORE}}" != "$NIX_STORE"; then if test -n "$oldPath" -a "''${oldPath:0:''${#NIX_STORE}}" != "$NIX_STORE"; then
local newPath=$(type -P $(basename $oldPath) || true) local newPath=$(type -P $(basename $oldPath) || true)

View File

@ -18,7 +18,7 @@ patchShebangs() {
local oldInterpreterLine local oldInterpreterLine
local newInterpreterLine local newInterpreterLine
find "$dir" -type f -perm /0100 | while read f; do find "$dir" -type f -perm -0100 | while read f; do
if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then if [ "$(head -1 "$f" | head -c +2)" != '#!' ]; then
# missing shebang => not a script # missing shebang => not a script
continue continue

View File

@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
# On Linux, use patchelf to modify the executables so that they can # On Linux, use patchelf to modify the executables so that they can
# find editline/gmp. # find editline/gmp.
(if stdenv.isLinux then '' (if stdenv.isLinux then ''
find . -type f -perm +100 \ find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${libedit}/lib:${ncurses}/lib:${gmp}/lib" {} \; --set-rpath "${libedit}/lib:${ncurses}/lib:${gmp}/lib" {} \;
for prog in ld ar gcc strip ranlib; do for prog in ld ar gcc strip ranlib; do

View File

@ -60,7 +60,7 @@ stdenv.mkDerivation rec {
# On Linux, use patchelf to modify the executables so that they can # On Linux, use patchelf to modify the executables so that they can
# find editline/gmp. # find editline/gmp.
stdenv.lib.optionalString stdenv.isLinux '' stdenv.lib.optionalString stdenv.isLinux ''
find . -type f -perm +100 \ find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${ncurses}/lib:${gmp}/lib" {} \; --set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2 sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2

View File

@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
stdenv.lib.optionalString stdenv.isLinux '' stdenv.lib.optionalString stdenv.isLinux ''
mkdir -p "$out/lib" mkdir -p "$out/lib"
ln -sv "${ncurses}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5" ln -sv "${ncurses}/lib/libncurses.so" "$out/lib/libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5"
find . -type f -perm +100 \ find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$out/lib:${gmp}/lib" {} \; --set-rpath "$out/lib:${gmp}/lib" {} \;
sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2 sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2

View File

@ -45,7 +45,7 @@ fi
rpath=$rpath${rpath:+:}$jrePath/lib/$architecture/jli rpath=$rpath${rpath:+:}$jrePath/lib/$architecture/jli
# set all the dynamic linkers # set all the dynamic linkers
find $out -type f -perm +100 \ find $out -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$rpath" {} \; --set-rpath "$rpath" {} \;

View File

@ -142,7 +142,7 @@ let result = stdenv.mkDerivation rec {
rpath=$rpath''${rpath:+:}$jrePath/lib/${architecture} rpath=$rpath''${rpath:+:}$jrePath/lib/${architecture}
# set all the dynamic linkers # set all the dynamic linkers
find $out -type f -perm +100 \ find $out -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "$rpath" {} \; --set-rpath "$rpath" {} \;

View File

@ -10,7 +10,7 @@ buildRubyGem {
}; };
dontPatchShebangs = true; dontPatchShebangs = true;
postInstall = '' postInstall = ''
find $out -type f -perm /0100 | while read f; do find $out -type f -perm -0100 | while read f; do
substituteInPlace $f \ substituteInPlace $f \
--replace "/usr/bin/env" "${coreutils}/bin/env" --replace "/usr/bin/env" "${coreutils}/bin/env"
done done

View File

@ -6,7 +6,7 @@ buildRubyGem {
sha256 = "1zkxw6699bbmsamrij2lirscbh0j58p1p3bql22jsxvx34j6w5nc"; sha256 = "1zkxw6699bbmsamrij2lirscbh0j58p1p3bql22jsxvx34j6w5nc";
dontPatchShebangs = true; dontPatchShebangs = true;
postInstall = '' postInstall = ''
find $out -type f -perm /0100 | while read f; do find $out -type f -perm -0100 | while read f; do
substituteInPlace $f \ substituteInPlace $f \
--replace "/usr/bin/env" "${coreutils}/bin/env" --replace "/usr/bin/env" "${coreutils}/bin/env"
done done

View File

@ -40,7 +40,7 @@ rec {
cp ../make/makedis.csh $out/share/${name}/build-snapshot cp ../make/makedis.csh $out/share/${name}/build-snapshot
cp *.h $out/include cp *.h $out/include
cp *.c *.h $out/source cp *.c *.h $out/source
find . -perm +111 -a '(' '(' ! -name '*.*' ')' -o '(' -name '*.REAL' ')' ')' -exec cp '{}' $out/bin ';' find . -perm -0100 -a '(' '(' ! -name '*.*' ')' -o '(' -name '*.REAL' ')' ')' -exec cp '{}' $out/bin ';'
'') ["defEnsureDir" "build" "minInit"]; '') ["defEnsureDir" "build" "minInit"];
name = "NCBI-Toolbox-" + version; name = "NCBI-Toolbox-" + version;

View File

@ -21,7 +21,7 @@ rpath=
for i in $libraries; do for i in $libraries; do
rpath=$rpath${rpath:+:}$i/lib rpath=$rpath${rpath:+:}$i/lib
done done
find $out -type f -perm +100 \ find $out -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \; -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
find $out -type f -perm +100 \ find $out -type f -perm -0100 \
-exec patchelf --set-rpath "$rpath" {} \; -exec patchelf --set-rpath "$rpath" {} \;

View File

@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
find $out \( \ find $out \( \
\( -type f -a -name "*.so*" \) -o \ \( -type f -a -name "*.so*" \) -o \
\( -type f -a -perm /0100 \) \ \( -type f -a -perm -0100 \) \
\) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \ \) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \
--set-rpath ${zlib}/lib:${ncurses}/lib {} \; --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
# fix ineffective PROGDIR / MYNDKDIR determination # fix ineffective PROGDIR / MYNDKDIR determination

View File

@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
find $out \( \ find $out \( \
\( -type f -a -name "*.so*" \) -o \ \( -type f -a -name "*.so*" \) -o \
\( -type f -a -perm /0100 \) \ \( -type f -a -perm -0100 \) \
\) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \ \) -exec patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-*so.? \
--set-rpath ${zlib}/lib:${ncurses}/lib {} \; --set-rpath ${zlib}/lib:${ncurses}/lib {} \;
# fix ineffective PROGDIR / MYNDKDIR determination # fix ineffective PROGDIR / MYNDKDIR determination

View File

@ -26,7 +26,7 @@ wrapPythonProgramsIn() {
done done
# Find all regular files in the output directory that are executable. # Find all regular files in the output directory that are executable.
for f in $(find "$dir" -type f -perm /0100); do for f in $(find "$dir" -type f -perm -0100); do
# Rewrite "#! .../env python" to "#! /nix/store/.../python". # Rewrite "#! .../env python" to "#! /nix/store/.../python".
if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^" sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"

View File

@ -9,7 +9,7 @@ patchELF() {
if [ -e "$prefix" ]; then if [ -e "$prefix" ]; then
find "$prefix" \( \ find "$prefix" \( \
\( -type f -a -name "*.so*" \) -o \ \( -type f -a -name "*.so*" \) -o \
\( -type f -a -perm /0100 \) \ \( -type f -a -perm -0100 \) \
\) -print -exec patchelf --shrink-rpath '{}' \; \) -print -exec patchelf --shrink-rpath '{}' \;
fi fi
stopNest stopNest

View File

@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
patchelf --set-rpath "$out/usr/lib/plexmediaserver" "$out/usr/lib/plexmediaserver/$bin" patchelf --set-rpath "$out/usr/lib/plexmediaserver" "$out/usr/lib/plexmediaserver/$bin"
done done
find $out/usr/lib/plexmediaserver/Resources -type f -a -perm /0100 \ find $out/usr/lib/plexmediaserver/Resources -type f -a -perm -0100 \
-print -exec patchelf --set-interpreter "${glibc}/lib/ld-linux-x86-64.so.2" '{}' \; -print -exec patchelf --set-interpreter "${glibc}/lib/ld-linux-x86-64.so.2" '{}' \;

View File

@ -26,7 +26,7 @@ stdenv.mkDerivation {
''; '';
preInstall = '' preInstall = ''
mkdir -p "$out"/{bin,lib,include} mkdir -p "$out"/{bin,lib,include}
find . -maxdepth 1 -type f -perm +111 -exec cp '{}' "$out"/bin ';' find . -maxdepth 1 -type f -perm -0100 -exec cp '{}' "$out"/bin ';'
''; '';
makeFlags = "PREFIX=$(out)"; makeFlags = "PREFIX=$(out)";
meta = { meta = {