From aca5ba405e95d22a3934e03e947968866d23bdb6 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 26 Jun 2017 02:01:03 -0400 Subject: cc-wrapper: Unify and improve dynamic linker flag logic Besides deduplicating overlapping logic, clear warning messages were added for: - No glob/path for dynamic linker provided (use default glob) - Glob did not expand to anything (don't append flag) - glob expanded to multiple things (take first, like before) --- pkgs/build-support/cc-wrapper/default.nix | 64 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 37d62891ecfc..4dc3d1845a48 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -105,22 +105,20 @@ let done ''); - # The dynamic linker has different names on different platforms. + # The dynamic linker has different names on different platforms. This is a + # shell glob that ought to match it. dynamicLinker = - if !nativeLibc then - (if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else - if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else - # ARM with a wildcard, which can be "" or "-armhf". - if targetPlatform.isArm32 then "ld-linux*.so.3" else - if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else - if targetPlatform.system == "powerpc-linux" then "ld.so.1" else - if targetPlatform.system == "mips64el-linux" then "ld.so.1" else - if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else - if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else - builtins.trace - "Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead." - null) - else ""; + /**/ if libc == null then null + else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2" + else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2" + # ARM with a wildcard, which can be "" or "-armhf". + else if targetPlatform.isArm32 then "${libc_lib}/lib/ld-linux*.so.3" + else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1" + else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1" + else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1" + else if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" + else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" + else null; expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null" then buildPackages.stdenv.mkDerivation { @@ -175,39 +173,39 @@ stdenv.mkDerivation { } '' - # TODO(@Ericson2314): Unify logic next hash break - + optionalString (libc != null) (if (targetPlatform.isDarwin) then '' - echo $dynamicLinker > $out/nix-support/dynamic-linker + + optionalString (libc != null) ('' + if [[ -z ''${dynamicLinker+x} ]]; then + echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2 + dynamicLinker="${libc_lib}/lib/ld*.so.?" + fi - echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook - '' else if dynamicLinker != null then '' - dynamicLinker="${libc_lib}/lib/$dynamicLinker" - echo $dynamicLinker > $out/nix-support/dynamic-linker + # Expand globs to fill array of options + dynamicLinker=($dynamicLinker) - if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then - echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 - fi + case ''${#dynamicLinker[@]} in + 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;; + 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;; + *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; + esac - # The dynamic linker is passed in `ldflagsBefore' to allow - # explicit overrides of the dynamic linker by callers to gcc/ld - # (the *last* value counts, so ours should come first). - echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before - '' else '' - dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'` if [ -n "$dynamicLinker" ]; then echo $dynamicLinker > $out/nix-support/dynamic-linker + '' + (if targetPlatform.isDarwin then '' + printf "export LD_DYLD_PATH+=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook + '' else '' if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 fi - ldflagsBefore="-dynamic-linker $dlinker" + ldflagsBefore=(-dynamic-linker "$dynamicLinker") + '') + '' fi # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to gcc/ld # (the *last* value counts, so ours should come first). - echo "$ldflagsBefore" > $out/nix-support/libc-ldflags-before + printLines "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before '') + optionalString (libc != null) '' -- cgit 1.4.1 From 093cc00cdd9d8cf31ecce5bc1dd3645c460a1b98 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 26 Jun 2017 01:17:09 -0400 Subject: cc-wrapper: Always export environment variables for binutils Before, this only happened when cross compiling. --- pkgs/build-support/cc-wrapper/default.nix | 33 ++++++++++------------------- pkgs/build-support/cc-wrapper/setup-hook.sh | 27 +++++++++++++++++------ 2 files changed, 32 insertions(+), 28 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 4dc3d1845a48..1b52a0b8b123 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -71,22 +71,6 @@ let -e 's^addCVars^addCVars${_infixSalt}^g' \ -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g' - '' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) '' - cat << 'EOF' >> $out - for CMD in ar as nm objcopy ranlib strip strings size ld windres - do - # which is not part of stdenv, but compgen will do for now - if - PATH=$_PATH type -p ${prefix}$CMD > /dev/null - then - export ''$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=${prefix}''${CMD}; - fi - done - EOF - - sed -i $out -e 's_envHooks_crossEnvHooks_g' - '' + '' - # NIX_ things which we don't both use and define, we revert them #asymmetric=$( # for pre in "" "\\$" @@ -143,6 +127,7 @@ stdenv.mkDerivation { inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin; gnugrep_bin = if nativeTools then "" else gnugrep; + binPrefix = prefix; passthru = { inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile @@ -303,20 +288,24 @@ stdenv.mkDerivation { wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd fi - export real_cc=${prefix}cc - export real_cxx=${prefix}c++ + # We export environment variables pointing to the wrapped nonstandard + # cmds, lest some lousy configure script use those to guess compiler + # version. + export named_cc=${prefix}cc + export named_cxx=${prefix}c++ + export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" if [ -e $ccPath/${prefix}gcc ]; then wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc ln -s ${prefix}gcc $out/bin/${prefix}cc - export real_cc=${prefix}gcc - export real_cxx=${prefix}g++ + export named_cc=${prefix}gcc + export named_cxx=${prefix}g++ elif [ -e $ccPath/clang ]; then wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang ln -s ${prefix}clang $out/bin/${prefix}cc - export real_cc=clang - export real_cxx=clang++ + export named_cc=${prefix}clang + export named_cxx=${prefix}clang++ fi if [ -e $ccPath/${prefix}g++ ]; then diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index f4f7ab181d3e..2900dc71a417 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -1,5 +1,3 @@ -export NIX_CC=@out@ - addCVars () { if [ -d $1/include ]; then export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" @@ -39,9 +37,26 @@ if [ -n "@coreutils_bin@" ]; then fi if [ -z "$crossConfig" ]; then - export CC=@real_cc@ - export CXX=@real_cxx@ + ENV_PREFIX="" else - export BUILD_CC=@real_cc@ - export BUILD_CXX=@real_cxx@ + ENV_PREFIX="BUILD_" fi + +export NIX_${ENV_PREFIX}CC=@out@ + +export ${ENV_PREFIX}CC=@named_cc@ +export ${ENV_PREFIX}CXX=@named_cxx@ + +for CMD in \ + cpp \ + ar as nm objcopy ranlib strip strings size ld windres +do + if + PATH=$_PATH type -p @binPrefix@$CMD > /dev/null + then + export ${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}; + fi +done + +# No local scope available for sourced files +unset ENV_PREFIX -- cgit 1.4.1 From 3739858571e24e5f5a97a0627369826b240fb8e0 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 15 Jul 2017 20:29:49 -0400 Subject: cc-wrapper: Use new bash uppercase subsitution syntax in setup hook While this requires newer bash, stdenv's setup.sh now does across the board anyways. This way is more concise. --- pkgs/build-support/cc-wrapper/setup-hook.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 2900dc71a417..3e8494cf9c18 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -52,9 +52,9 @@ for CMD in \ ar as nm objcopy ranlib strip strings size ld windres do if - PATH=$_PATH type -p @binPrefix@$CMD > /dev/null + PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null then - export ${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}; + export "${ENV_PREFIX}${CMD^^}=@binPrefix@${CMD}"; fi done -- cgit 1.4.1 From dce958ac396e88c09d5b19c284f41eef68f54ce7 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sun, 16 Jul 2017 11:39:40 -0500 Subject: buildenv: read propagated-user-env-packages line-by-line Since 3cb745d5a69018829ac15f7d5a508135f6bda123, the format of propagated-user-env-packages has changed and propagated packages have not been included by buildenv, including in the system environment. The buildenv builder is modified to read propagated-user-env-packages line-by-line, instead of expecting all packages on one line. --- pkgs/build-support/buildenv/builder.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/buildenv/builder.pl b/pkgs/build-support/buildenv/builder.pl index 678f5a3fe9e6..7cc37d156735 100755 --- a/pkgs/build-support/buildenv/builder.pl +++ b/pkgs/build-support/buildenv/builder.pl @@ -141,12 +141,11 @@ sub addPkg { my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages"; if (-e $propagatedFN) { open PROP, "<$propagatedFN" or die; - my $propagated = ; - close PROP; - my @propagated = split ' ', $propagated; - foreach my $p (@propagated) { + while (my $p = ) { + chomp $p; $postponed{$p} = 1 unless defined $done{$p}; } + close PROP; } } -- cgit 1.4.1 From c25199f6973dff040a3d248a759636f8b981b02d Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Thu, 20 Jul 2017 09:34:56 -0500 Subject: fetchurl: remove unpaired call to `stopNest' Fixes #27406. Commit 5d4efb2c816d2143f29cad8153faad1686557b2a added an assertion to `stopNest' which requires it be correctly paired with `startNest'. `fetchurl' calls `stopNest', but never calls `startNest'; the former calls are removed. --- pkgs/build-support/fetchurl/builder.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index c4fd18e46caf..7c2bdf260b4e 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -39,7 +39,6 @@ tryDownload() { curlexit=$?; fi done - stopNest } @@ -51,7 +50,6 @@ finish() { fi runHook postFetch - stopNest exit 0 } -- cgit 1.4.1 From aa4a92d2df0eebde3e0d832d2c60071f50fe4e9f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 24 Jul 2017 14:45:15 +0200 Subject: cc-wrapper/ld-wrapper: Minor speedup in string concatenation There is still a O(n) pattern match in ld-wrapper, so we should probably rewrite that code to use associative arrays. --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 6 +++--- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 3ccdc34db5b2..99eb63f40edf 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -55,7 +55,7 @@ while [ $n -lt ${#params[*]} ]; do nonFlagArgs=1 elif [ "$p" = -m32 ]; then if [ -e @out@/nix-support/dynamic-linker-m32 ]; then - NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" + NIX_LDFLAGS+=" -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" fi fi n=$((n + 1)) @@ -111,9 +111,9 @@ fi if [[ "$isCpp" = 1 ]]; then if [[ "$cppInclude" = 1 ]]; then - NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" + NIX_CFLAGS_COMPILE+=" ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" fi - NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK" + NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK" fi LD=@ldPath@/ld diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 056cfa920535..4b3906a2e10f 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -79,7 +79,7 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then case $libPath in *\ $path\ *) return 0 ;; esac - libPath="$libPath $path " + libPath+=" $path " } addToRPath() { @@ -90,12 +90,12 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then case $rpath in *\ $1\ *) return 0 ;; esac - rpath="$rpath $1 " + rpath+=" $1 " } libs="" addToLibs() { - libs="$libs $1" + libs+=" $1" } rpath="" -- cgit 1.4.1 From 47821f1cf0cd853d3d3dfea9259e02fea2766327 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Jul 2017 18:46:49 +0200 Subject: cc-wrapper: More quadratic performance fixes This eliminates the slow lookup of whether we've already seen an rpath / library path entry. Issue #27609. --- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 44 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 4b3906a2e10f..240082b5dfdc 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -64,7 +64,9 @@ extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) # Add all used dynamic libraries to the rpath. if [ "$NIX_DONT_SET_RPATH" != 1 ]; then - libPath="" + declare -A libDirsSeen + declare -a libDirs + addToLibPath() { local path="$1" if [ "${path:0:1}" != / ]; then return 0; fi @@ -76,29 +78,27 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then fi ;; esac - case $libPath in - *\ $path\ *) return 0 ;; - esac - libPath+=" $path " + if [[ -z ${libDirsSeen[$path]} ]]; then + libDirs+=("$path") + libDirsSeen[$path]=1 + fi } + declare -A rpathsSeen + declare -a rpaths + addToRPath() { # If the path is not in the store, don't add it to the rpath. # This typically happens for libraries in /tmp that are later # copied to $out/lib. If not, we're screwed. if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi - case $rpath in - *\ $1\ *) return 0 ;; - esac - rpath+=" $1 " - } - - libs="" - addToLibs() { - libs+=" $1" + if [[ -z ${rpathsSeen[$1]} ]]; then + rpaths+=("$1") + rpathsSeen[$1]=1 + fi } - rpath="" + declare -a libs # First, find all -L... switches. allParams=("${params[@]}" ${extra[@]}) @@ -112,10 +112,10 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then addToLibPath ${p2} n=$((n + 1)) elif [ "$p" = -l ]; then - addToLibs ${p2} + libs+=(${p2}) n=$((n + 1)) elif [ "${p:0:2}" = -l ]; then - addToLibs ${p:2} + libs+=(${p:2}) elif [ "$p" = -dynamic-linker ]; then # Ignore the dynamic linker argument, or it # will get into the next 'elif'. We don't want @@ -135,9 +135,8 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then # so, add the directory to the rpath. # It's important to add the rpath in the order of -L..., so # the link time chosen objects will be those of runtime linking. - - for i in $libPath; do - for j in $libs; do + for i in ${libDirs[@]}; do + for j in ${libs[@]}; do if [ -f "$i/lib$j.so" ]; then addToRPath $i break @@ -145,10 +144,9 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then done done - # Finally, add `-rpath' switches. - for i in $rpath; do - extra+=(-rpath $i) + for i in ${rpaths[@]}; do + extra+=(-rpath "$i") done fi -- cgit 1.4.1 From f6f40e3fe5fbb9721624a218faea1b520f9ec200 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Jul 2017 18:48:47 -0400 Subject: stdenv-setup and misc pkgs: Revert to space-deliminated propagated-* files We cannot switch to line-delimited yet, because certain Nix commands do not read in the entire file, but just the first line. --- pkgs/build-support/cc-wrapper/default.nix | 6 +++--- pkgs/build-support/gcc-wrapper-old/builder.sh | 2 +- pkgs/build-support/trivial-builders.nix | 2 +- pkgs/desktops/kde-4.14/kde-package/default.nix | 2 +- pkgs/development/compilers/openjdk-darwin/8.nix | 2 +- pkgs/development/compilers/openjdk-darwin/default.nix | 2 +- pkgs/development/compilers/openjdk/7.nix | 2 +- pkgs/development/compilers/openjdk/8.nix | 2 +- .../compilers/oraclejdk/jdk-linux-base.nix | 2 +- pkgs/development/compilers/zulu/default.nix | 2 +- pkgs/development/haskell-modules/generic-builder.nix | 2 +- pkgs/misc/misc.nix | 2 +- pkgs/stdenv/generic/builder.sh | 2 +- pkgs/stdenv/generic/setup.sh | 19 +++++++++++-------- 14 files changed, 26 insertions(+), 23 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 1b52a0b8b123..09d1d4cd681a 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -190,7 +190,7 @@ stdenv.mkDerivation { # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to gcc/ld # (the *last* value counts, so ours should come first). - printLines "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before + printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before '') + optionalString (libc != null) '' @@ -258,9 +258,9 @@ stdenv.mkDerivation { # Propagate the wrapped cc so that if you install the wrapper, # you get tools like gcov, the manpages, etc. as well (including # for binutils and Glibc). - printLines ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages + printWords ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages - printLines ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs + printWords ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs '' + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' diff --git a/pkgs/build-support/gcc-wrapper-old/builder.sh b/pkgs/build-support/gcc-wrapper-old/builder.sh index 4f141f6b8f21..22e32814927e 100644 --- a/pkgs/build-support/gcc-wrapper-old/builder.sh +++ b/pkgs/build-support/gcc-wrapper-old/builder.sh @@ -211,5 +211,5 @@ cp -p $utils $out/nix-support/utils.sh # tools like gcov, the manpages, etc. as well (including for binutils # and Glibc). if test -z "$nativeTools"; then - printLines $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages + printWords $gcc $binutils $libc $libc_bin > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 1ee1fe8298fd..16bd4e8e4054 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -84,7 +84,7 @@ rec { mkdir -p $out/nix-support cp ${script} $out/nix-support/setup-hook '' + lib.optionalString (deps != []) '' - printLines ${toString deps} > $out/nix-support/propagated-native-build-inputs + printWords ${toString deps} > $out/nix-support/propagated-native-build-inputs '' + lib.optionalString (substitutions != {}) '' substituteAll ${script} $out/nix-support/setup-hook ''); diff --git a/pkgs/desktops/kde-4.14/kde-package/default.nix b/pkgs/desktops/kde-4.14/kde-package/default.nix index 3637d9f89cb2..94f878097ded 100644 --- a/pkgs/desktops/kde-4.14/kde-package/default.nix +++ b/pkgs/desktops/kde-4.14/kde-package/default.nix @@ -86,7 +86,7 @@ rec { };}) '' mkdir -pv $out/nix-support - printLines ${toString list} | tee $out/nix-support/propagated-user-env-packages + printWords ${toString list} | tee $out/nix-support/propagated-user-env-packages ''; # Given manifest module data, return the module diff --git a/pkgs/development/compilers/openjdk-darwin/8.nix b/pkgs/development/compilers/openjdk-darwin/8.nix index 691829c7788a..6234b63208cd 100644 --- a/pkgs/development/compilers/openjdk-darwin/8.nix +++ b/pkgs/development/compilers/openjdk-darwin/8.nix @@ -33,7 +33,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs install_name_tool -change /usr/X11/lib/libfreetype.6.dylib ${freetype}/lib/libfreetype.6.dylib $out/jre/lib/libfontmanager.dylib diff --git a/pkgs/development/compilers/openjdk-darwin/default.nix b/pkgs/development/compilers/openjdk-darwin/default.nix index 8ce0835fcb69..1e8f88beea66 100644 --- a/pkgs/development/compilers/openjdk-darwin/default.nix +++ b/pkgs/development/compilers/openjdk-darwin/default.nix @@ -23,7 +23,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs install_name_tool -change /usr/X11/lib/libfreetype.6.dylib ${freetype}/lib/libfreetype.6.dylib $out/jre/lib/libfontmanager.dylib diff --git a/pkgs/development/compilers/openjdk/7.nix b/pkgs/development/compilers/openjdk/7.nix index 9ef7d26b2efe..72f0ba293ba9 100644 --- a/pkgs/development/compilers/openjdk/7.nix +++ b/pkgs/development/compilers/openjdk/7.nix @@ -190,7 +190,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $jre/nix-support - printLines ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. mkdir -p $out/nix-support diff --git a/pkgs/development/compilers/openjdk/8.nix b/pkgs/development/compilers/openjdk/8.nix index 7c50872ebe59..0f0b42640c5d 100644 --- a/pkgs/development/compilers/openjdk/8.nix +++ b/pkgs/development/compilers/openjdk/8.nix @@ -202,7 +202,7 @@ let # any package that depends on the JRE has $CLASSPATH set up # properly. mkdir -p $jre/nix-support - printLines ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $jre/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. mkdir -p $out/nix-support diff --git a/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix b/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix index 08fd724f7733..fec038199adc 100644 --- a/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix +++ b/pkgs/development/compilers/oraclejdk/jdk-linux-base.nix @@ -165,7 +165,7 @@ let result = stdenv.mkDerivation rec { ln -s $jrePath/lib/${architecture}/libnpjp2.so $jrePath/lib/${architecture}/plugins mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. cat <> $out/nix-support/setup-hook diff --git a/pkgs/development/compilers/zulu/default.nix b/pkgs/development/compilers/zulu/default.nix index 03be4ee8a0b9..f7638757ff7a 100644 --- a/pkgs/development/compilers/zulu/default.nix +++ b/pkgs/development/compilers/zulu/default.nix @@ -54,7 +54,7 @@ in stdenv.mkDerivation rec { find $out -name "*.so" -exec patchelf --set-rpath "$rpath" {} \; mkdir -p $out/nix-support - printLines ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs + printWords ${setJavaClassPath} > $out/nix-support/propagated-native-build-inputs # Set JAVA_HOME automatically. cat <> $out/nix-support/setup-hook diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index a8da63493a43..c7c54c959b5a 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -311,7 +311,7 @@ stdenv.mkDerivation ({ ${optionalString isGhcjs '' for exeDir in "$out/bin/"*.jsexe; do exe="''${exeDir%.jsexe}" - printLines '#!${nodejs}/bin/node' > "$exe" + printWords '#!${nodejs}/bin/node' > "$exe" cat "$exeDir/all.js" >> "$exe" chmod +x "$exe" done diff --git a/pkgs/misc/misc.nix b/pkgs/misc/misc.nix index 6e8c6f4486f1..a3c293beab33 100644 --- a/pkgs/misc/misc.nix +++ b/pkgs/misc/misc.nix @@ -23,7 +23,7 @@ in */ collection = {list, name} : runCommand "collection-${name}" {} '' mkdir -p $out/nix-support - printLines ${builtins.toString list} > $out/nix-support/propagated-user-env-packages + printWords ${builtins.toString list} > $out/nix-support/propagated-user-env-packages ''; /* creates a derivation symlinking references C/C++ libs into one include and lib directory called $out/cdt-envs/${name} diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index f8c0fd44ac78..686cb778ca77 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -15,5 +15,5 @@ cat "$setup" >> $out/setup # in stdenv. mkdir $out/nix-support if [ "$propagatedUserEnvPkgs" ]; then - printf '%s\n' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages + printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index e0a33ca1c384..56ab82232964 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -210,6 +210,11 @@ printLines() { printf '%s\n' "$@" } +printWords() { + [[ "$#" -gt 0 ]] || return 0 + printf '%s ' "$@" +} + ###################################################################### # Initialisation. @@ -291,12 +296,10 @@ findInputs() { fi if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then - local fd pkgNext - exec {fd}<"$pkg/nix-support/$propagatedBuildInputsFile" - while IFS= read -r -u $fd pkgNext; do + local pkgNext + for pkgNext in $(< "$pkg/nix-support/$propagatedBuildInputsFile"); do findInputs "$pkgNext" "$var" "$propagatedBuildInputsFile" done - exec {fd}<&- fi } @@ -814,19 +817,19 @@ fixupPhase() { if [ -n "$propagated" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs" + printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs" fi else if [ -n "$propagatedBuildInputs" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs" + printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs" fi if [ -n "$propagatedNativeBuildInputs" ]; then mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs" + printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs" fi fi @@ -840,7 +843,7 @@ fixupPhase() { if [ -n "$propagatedUserEnvPkgs" ]; then mkdir -p "${!outputBin}/nix-support" # shellcheck disable=SC2086 - printLines $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" + printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" fi runHook postFixup -- cgit 1.4.1 From ea7d13cf1acc60999a442b46b279460928165140 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 25 Jul 2017 17:48:50 -0400 Subject: stdenv-setup and misc hooks: Work with bash-3.4 for MacOS nix-shell This is a temporary measure until this impurity is removed from Nix. --- pkgs/build-support/cc-wrapper/setup-hook.sh | 2 +- .../haskell-modules/generic-builder.nix | 2 +- pkgs/servers/x11/xorg/builder.sh | 4 +-- pkgs/stdenv/generic/setup.sh | 38 ++++++++++++++-------- 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 3e8494cf9c18..104b82425f29 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -54,7 +54,7 @@ do if PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null then - export "${ENV_PREFIX}${CMD^^}=@binPrefix@${CMD}"; + export "${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}"; fi done diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index c7c54c959b5a..2ec77b0563ae 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -211,7 +211,7 @@ stdenv.mkDerivation ({ configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" # nativePkgs defined in stdenv/setup.hs - for p in "''${!nativePkgs[@]}"; do + for p in "''${nativePkgs[@]}"; do if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/ continue diff --git a/pkgs/servers/x11/xorg/builder.sh b/pkgs/servers/x11/xorg/builder.sh index 3a8cf6fa6c8e..fae8bf5a8ce5 100644 --- a/pkgs/servers/x11/xorg/builder.sh +++ b/pkgs/servers/x11/xorg/builder.sh @@ -18,14 +18,14 @@ postInstall() { for r in $requires; do if test -n "$crossConfig"; then - for p in "${!crossPkgs[@]}"; do + for p in "${crossPkgs[@]}"; do if test -e $p/lib/pkgconfig/$r.pc; then echo " found requisite $r in $p" propagatedBuildInputs="$propagatedBuildInputs $p" fi done else - for p in "${!nativePkgs[@]}"; do + for p in "${nativePkgs[@]}"; do if test -e $p/lib/pkgconfig/$r.pc; then echo " found requisite $r in $p" propagatedNativeBuildInputs="$propagatedNativeBuildInputs $p" diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 56ab82232964..1e8b5f57585a 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -17,9 +17,10 @@ runHook() { shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi - local -n var + + local varRef="$var[@]" local hook - for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do + for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do _eval "$hook" "$@" done return 0 @@ -33,9 +34,10 @@ runOneHook() { shift local var="$hookName" if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi - local -n var + + local varRef="$var[@]" local hook - for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do + for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do if _eval "$hook" "$@"; then return 0 fi @@ -271,12 +273,22 @@ runHook addInputsHook findInputs() { local pkg="$1" local var="$2" - local -n varDeref="$var" local propagatedBuildInputsFile="$3" - # Stop if we've already added this one - [[ -z "${varDeref["$pkg"]}" ]] || return 0 - varDeref["$pkg"]=1 + # TODO(@Ericson2314): Restore using associative array once Darwin + # nix-shell doesn't use impure bash. This should replace the O(n) + # case with an O(1) hash map lookup, assuming bash is implemented + # well :D. + local varRef="$var[*]" + + case "${!varRef}" in + *" $pkg "*) return 0 ;; + esac + + # For some reason, bash gives us some (hopefully limited) eval + # "for free"! Everything is single-quoted except for `"$var"` + # so `var` is expanded first. + declare -g "$var"'=("${'"$var"'[@]}" "$pkg")' if ! [ -e "$pkg" ]; then echo "build input $pkg does not exist" >&2 @@ -306,19 +318,19 @@ findInputs() { if [ -z "$crossConfig" ]; then # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs) # are handled identically to nativeBuildInputs - declare -gA nativePkgs + declare -ga nativePkgs for i in $nativeBuildInputs $buildInputs \ $defaultNativeBuildInputs $defaultBuildInputs \ $propagatedNativeBuildInputs $propagatedBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done else - declare -gA crossPkgs + declare -ga crossPkgs for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do findInputs "$i" crossPkgs propagated-build-inputs done - declare -gA nativePkgs + declare -ga nativePkgs for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do findInputs "$i" nativePkgs propagated-native-build-inputs done @@ -334,7 +346,7 @@ _addToNativeEnv() { runHook envHook "$pkg" } -for i in "${!nativePkgs[@]}"; do +for i in "${nativePkgs[@]}"; do _addToNativeEnv "$i" done @@ -345,7 +357,7 @@ _addToCrossEnv() { runHook crossEnvHook "$pkg" } -for i in "${!crossPkgs[@]}"; do +for i in "${crossPkgs[@]}"; do _addToCrossEnv "$i" done -- cgit 1.4.1