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}
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" {} \;
'';

View file

@ -101,12 +101,12 @@ in stdenv.mkDerivation {
rm "$out/${appdir}/qt.conf"
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} {} \;
RPATH=${ldpath}:${gcc.cc}/lib:$out/${appdir}
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" {} \;
mkdir -p "$out/share/applications"

View file

@ -20,9 +20,9 @@ stdenv.mkDerivation {
buildPhase = ''
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 . -perm +111 -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 +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/csh@$(type -P csh)@g"
find . -perm -0100 -type f | xargs sed -i -e "s@/bin/rm@$(type -P rm)@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

View file

@ -82,7 +82,7 @@ rec {
find . -name '*.so' -exec cp '{}' $out/lib ';'
find . -name '*.txt' -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
'') ["buildContent" "defEnsureDir" "minInit"];

View file

@ -86,7 +86,7 @@ stdenv.mkDerivation rec {
preFixup = ''
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/')
if [ -z "$type" ]; then
:

View file

@ -96,7 +96,7 @@ stdenv.mkDerivation rec {
preFixup = ''
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/')
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.
echo "patching script interpreter paths"
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")
if test -n "$oldPath" -a "''${oldPath:0:''${#NIX_STORE}}" != "$NIX_STORE"; then
local newPath=$(type -P $(basename $oldPath) || true)

View file

@ -18,7 +18,7 @@ patchShebangs() {
local oldInterpreterLine
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
# missing shebang => not a script
continue

View file

@ -38,7 +38,7 @@ stdenv.mkDerivation rec {
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
(if stdenv.isLinux then ''
find . -type f -perm +100 \
find . -type f -perm -0100 \
-exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${libedit}/lib:${ncurses}/lib:${gmp}/lib" {} \;
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
# find editline/gmp.
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)" \
--set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
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 ''
mkdir -p "$out/lib"
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)" \
--set-rpath "$out/lib:${gmp}/lib" {} \;
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
# 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)" \
--set-rpath "$rpath" {} \;

View file

@ -142,7 +142,7 @@ let result = stdenv.mkDerivation rec {
rpath=$rpath''${rpath:+:}$jrePath/lib/${architecture}
# 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)" \
--set-rpath "$rpath" {} \;

View file

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

View file

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

View file

@ -40,7 +40,7 @@ rec {
cp ../make/makedis.csh $out/share/${name}/build-snapshot
cp *.h $out/include
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"];
name = "NCBI-Toolbox-" + version;

View file

@ -21,7 +21,7 @@ rpath=
for i in $libraries; do
rpath=$rpath${rpath:+:}$i/lib
done
find $out -type f -perm +100 \
find $out -type f -perm -0100 \
-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" {} \;

View file

@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
find $out \( \
\( -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.? \
--set-rpath ${zlib}/lib:${ncurses}/lib {} \;
# fix ineffective PROGDIR / MYNDKDIR determination

View file

@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
find $out \( \
\( -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.? \
--set-rpath ${zlib}/lib:${ncurses}/lib {} \;
# fix ineffective PROGDIR / MYNDKDIR determination

View file

@ -26,7 +26,7 @@ wrapPythonProgramsIn() {
done
# 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".
if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)^#! $python^"

View file

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

View file

@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
patchelf --set-rpath "$out/usr/lib/plexmediaserver" "$out/usr/lib/plexmediaserver/$bin"
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" '{}' \;

View file

@ -26,7 +26,7 @@ stdenv.mkDerivation {
'';
preInstall = ''
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)";
meta = {