From d96893647de5c519c458c1254f043f2d67d9b29c Mon Sep 17 00:00:00 2001 From: Anthony Cowley Date: Thu, 17 Dec 2015 17:02:40 -0500 Subject: [PATCH 1/4] cc-wrapper: fix on darwin The ld-wrapper.sh script calls `readlink` in some circumstances. We need to ensure that this is the `readlink` from the `coreutils` package so that flag support is as expected. This is accomplished by explicitly setting PATH at the top of each shell script. Without doing this, the following happens with a trivial `main.c`: ``` nix-env -f "" -iA pkgs.clang $ clang main.c -L /nix/../nix/store/2ankvagznq062x1gifpxwkk7fp3xwy63-xnu-2422.115.4/Library -o a.out readlink: illegal option -- f usage: readlink [-n] [file ...] ``` The key element is the `..` in the path supplied to the linker via a `-L` flag. With this patch, the above invocation works correctly on darwin, whose native `/usr/bin/readlink` does not support the `-f` flag. The explicit path also ensures that the `grep` called by `cc-wrapper.sh` is the one from Nix. Fixes #6447 --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 5 +++++ pkgs/build-support/cc-wrapper/default.nix | 13 ++++++++----- pkgs/build-support/cc-wrapper/gnat-wrapper.sh | 5 +++++ pkgs/build-support/cc-wrapper/ld-wrapper.sh | 5 +++++ pkgs/stdenv/darwin/default.nix | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 5bd59f8c585..f7541b15a82 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -1,4 +1,8 @@ #! @shell@ -e +path_backup=$PATH +if [ -n "@coreutils@" ]; then + PATH="@coreutils@/bin:@gnugrep@/bin" +fi if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then source "$NIX_CC_WRAPPER_START_HOOK" @@ -141,4 +145,5 @@ if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then source "$NIX_CC_WRAPPER_EXEC_HOOK" fi +PATH=$path_backup exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index bea7e07a202..110f5189141 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -9,13 +9,14 @@ , cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell , zlib ? null, extraPackages ? [], extraBuildCommands ? "" , dyld ? null # TODO: should this be a setup-hook on dyld? -, isGNU ? false, isClang ? cc.isClang or false +, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null }: with stdenv.lib; assert nativeTools -> nativePrefix != ""; -assert !nativeTools -> cc != null && binutils != null && coreutils != null; +assert !nativeTools -> + cc != null && binutils != null && coreutils != null && gnugrep != null; assert !nativeLibc -> libc != null; # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. @@ -37,9 +38,11 @@ stdenv.mkDerivation { inherit cc shell; libc = if nativeLibc then null else libc; - binutils = if nativeTools then null else binutils; - # The wrapper scripts use 'cat', so we may need coreutils. - coreutils = if nativeTools then null else coreutils; + binutils = if nativeTools then "" else binutils; + # The wrapper scripts use 'cat' and 'grep', so we may need coreutils + # and gnugrep. + coreutils = if nativeTools then "" else coreutils; + gnugrep = if nativeTools then "" else gnugrep; passthru = { inherit nativeTools nativeLibc nativePrefix isGNU isClang; }; diff --git a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh index 3514ccd6732..603275e4e69 100644 --- a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh @@ -1,4 +1,8 @@ #! @shell@ -e +path_backup=$PATH +if [ -n "@coreutils@" ]; then + PATH="@coreutils@/bin" +fi if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then source "$NIX_GNAT_WRAPPER_START_HOOK" @@ -100,4 +104,5 @@ if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then source "$NIX_GNAT_WRAPPER_EXEC_HOOK" fi +PATH=$path_backup exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index 30c531b7647..a7ed2f364cd 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -1,4 +1,8 @@ #! @shell@ -e +path_backup=$PATH +if [ -n "@coreutils@" ]; then + PATH="@coreutils@/bin" +fi if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then source "$NIX_LD_WRAPPER_START_HOOK" @@ -163,4 +167,5 @@ if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then source "$NIX_LD_WRAPPER_EXEC_HOOK" fi +PATH=$path_backup exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]} diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index c0c19a64c3c..0af7071e218 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -278,7 +278,7 @@ in rec { inherit stdenv shell; nativeTools = false; nativeLibc = false; - inherit (pkgs) coreutils binutils; + inherit (pkgs) coreutils binutils gnugrep; inherit (pkgs.darwin) dyld; cc = pkgs.llvmPackages.clang-unwrapped; libc = pkgs.darwin.Libsystem; From 5986aecc4c4e3d99d815da1ef7ea4ed2092f221e Mon Sep 17 00:00:00 2001 From: Anthony Cowley Date: Sun, 24 Jan 2016 00:18:32 -0500 Subject: [PATCH 2/4] Linux stdenv update: pass gnugrep to cc-wrapper --- pkgs/stdenv/linux/default.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 12fc3fed5a5..4ddf62f0aef 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -64,7 +64,7 @@ rec { # the bootstrap. In all stages, we build an stdenv and the package # set that can be built with that stdenv. stageFun = - {gccPlain, glibc, binutils, coreutils, name, overrides ? (pkgs: {}), extraBuildInputs ? []}: + {gccPlain, glibc, binutils, coreutils, gnugrep, name, overrides ? (pkgs: {}), extraBuildInputs ? []}: let @@ -93,7 +93,7 @@ rec { cc = gccPlain; isGNU = true; libc = glibc; - inherit binutils coreutils; + inherit binutils coreutils gnugrep; name = name; stdenv = stage0.stdenv; }; @@ -125,6 +125,7 @@ rec { glibc = null; binutils = null; coreutils = null; + gnugrep = null; name = null; overrides = pkgs: { @@ -160,6 +161,7 @@ rec { inherit (stage0.pkgs) glibc; binutils = bootstrapTools; coreutils = bootstrapTools; + gnugrep = bootstrapTools; name = "bootstrap-gcc-wrapper"; # Rebuild binutils to use from stage2 onwards. @@ -184,6 +186,7 @@ rec { inherit (stage1.pkgs) glibc; binutils = stage1.pkgs.binutils; coreutils = bootstrapTools; + gnugrep = bootstrapTools; name = "bootstrap-gcc-wrapper"; overrides = pkgs: { @@ -200,6 +203,7 @@ rec { gccPlain = bootstrapTools; inherit (stage2.pkgs) glibc binutils; coreutils = bootstrapTools; + gnugrep = bootstrapTools; name = "bootstrap-gcc-wrapper"; overrides = pkgs: rec { @@ -227,7 +231,7 @@ rec { # Construct a fourth stdenv that uses the new GCC. But coreutils is # still from the bootstrap tools. stage4 = stageFun { - inherit (stage3.pkgs) gccPlain glibc binutils; + inherit (stage3.pkgs) gccPlain glibc binutils gnugrep; coreutils = bootstrapTools; name = ""; @@ -244,7 +248,7 @@ rec { isGNU = true; cc = stage4.stdenv.cc.cc; libc = stage4.pkgs.glibc; - inherit (stage4.pkgs) binutils coreutils; + inherit (stage4.pkgs) binutils coreutils gnugrep; name = ""; stdenv = stage4.stdenv; shell = stage4.pkgs.bash + "/bin/bash"; From 8f48a9756b462c8b2eeaf8326feab8abf751ecd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 25 Jan 2016 09:54:10 +0100 Subject: [PATCH 3/4] cc-wrapper: quote when saving $PATH --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 4 ++-- pkgs/build-support/cc-wrapper/gnat-wrapper.sh | 4 ++-- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index f7541b15a82..6e12a0d8bc8 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -1,5 +1,5 @@ #! @shell@ -e -path_backup=$PATH +path_backup="$PATH" if [ -n "@coreutils@" ]; then PATH="@coreutils@/bin:@gnugrep@/bin" fi @@ -145,5 +145,5 @@ if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then source "$NIX_CC_WRAPPER_EXEC_HOOK" fi -PATH=$path_backup +PATH="$path_backup" exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" diff --git a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh index 603275e4e69..ae46b40ac63 100644 --- a/pkgs/build-support/cc-wrapper/gnat-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/gnat-wrapper.sh @@ -1,5 +1,5 @@ #! @shell@ -e -path_backup=$PATH +path_backup="$PATH" if [ -n "@coreutils@" ]; then PATH="@coreutils@/bin" fi @@ -104,5 +104,5 @@ if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then source "$NIX_GNAT_WRAPPER_EXEC_HOOK" fi -PATH=$path_backup +PATH="$path_backup" exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index a7ed2f364cd..6ef06eb7034 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -1,5 +1,5 @@ #! @shell@ -e -path_backup=$PATH +path_backup="$PATH" if [ -n "@coreutils@" ]; then PATH="@coreutils@/bin" fi @@ -167,5 +167,5 @@ if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then source "$NIX_LD_WRAPPER_EXEC_HOOK" fi -PATH=$path_backup +PATH="$path_backup" exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]} From 98c7e70a3fde4821bfd45c1cfbbb81adbe8a7ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 25 Jan 2016 09:55:00 +0100 Subject: [PATCH 4/4] linux stdenv bootstrap: avoid building grep twice It's perfectly enough when we use the bootstrapped grep everywhere except the one put into the final stdenv and final pkgs. --- pkgs/stdenv/linux/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 4ddf62f0aef..ac7d8f5c706 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -231,7 +231,8 @@ rec { # Construct a fourth stdenv that uses the new GCC. But coreutils is # still from the bootstrap tools. stage4 = stageFun { - inherit (stage3.pkgs) gccPlain glibc binutils gnugrep; + inherit (stage3.pkgs) gccPlain glibc binutils; + gnugrep = bootstrapTools; coreutils = bootstrapTools; name = "";