lol

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 "<nixpkgs>" -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

+24 -6
+5
pkgs/build-support/cc-wrapper/cc-wrapper.sh
··· 1 1 #! @shell@ -e 2 + path_backup=$PATH 3 + if [ -n "@coreutils@" ]; then 4 + PATH="@coreutils@/bin:@gnugrep@/bin" 5 + fi 2 6 3 7 if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then 4 8 source "$NIX_CC_WRAPPER_START_HOOK" ··· 141 145 source "$NIX_CC_WRAPPER_EXEC_HOOK" 142 146 fi 143 147 148 + PATH=$path_backup 144 149 exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
+8 -5
pkgs/build-support/cc-wrapper/default.nix
··· 9 9 , cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell 10 10 , zlib ? null, extraPackages ? [], extraBuildCommands ? "" 11 11 , dyld ? null # TODO: should this be a setup-hook on dyld? 12 - , isGNU ? false, isClang ? cc.isClang or false 12 + , isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null 13 13 }: 14 14 15 15 with stdenv.lib; 16 16 17 17 assert nativeTools -> nativePrefix != ""; 18 - assert !nativeTools -> cc != null && binutils != null && coreutils != null; 18 + assert !nativeTools -> 19 + cc != null && binutils != null && coreutils != null && gnugrep != null; 19 20 assert !nativeLibc -> libc != null; 20 21 21 22 # For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper. ··· 37 38 38 39 inherit cc shell; 39 40 libc = if nativeLibc then null else libc; 40 - binutils = if nativeTools then null else binutils; 41 - # The wrapper scripts use 'cat', so we may need coreutils. 42 - coreutils = if nativeTools then null else coreutils; 41 + binutils = if nativeTools then "" else binutils; 42 + # The wrapper scripts use 'cat' and 'grep', so we may need coreutils 43 + # and gnugrep. 44 + coreutils = if nativeTools then "" else coreutils; 45 + gnugrep = if nativeTools then "" else gnugrep; 43 46 44 47 passthru = { inherit nativeTools nativeLibc nativePrefix isGNU isClang; }; 45 48
+5
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
··· 1 1 #! @shell@ -e 2 + path_backup=$PATH 3 + if [ -n "@coreutils@" ]; then 4 + PATH="@coreutils@/bin" 5 + fi 2 6 3 7 if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then 4 8 source "$NIX_GNAT_WRAPPER_START_HOOK" ··· 100 104 source "$NIX_GNAT_WRAPPER_EXEC_HOOK" 101 105 fi 102 106 107 + PATH=$path_backup 103 108 exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
+5
pkgs/build-support/cc-wrapper/ld-wrapper.sh
··· 1 1 #! @shell@ -e 2 + path_backup=$PATH 3 + if [ -n "@coreutils@" ]; then 4 + PATH="@coreutils@/bin" 5 + fi 2 6 3 7 if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then 4 8 source "$NIX_LD_WRAPPER_START_HOOK" ··· 163 167 source "$NIX_LD_WRAPPER_EXEC_HOOK" 164 168 fi 165 169 170 + PATH=$path_backup 166 171 exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
+1 -1
pkgs/stdenv/darwin/default.nix
··· 278 278 inherit stdenv shell; 279 279 nativeTools = false; 280 280 nativeLibc = false; 281 - inherit (pkgs) coreutils binutils; 281 + inherit (pkgs) coreutils binutils gnugrep; 282 282 inherit (pkgs.darwin) dyld; 283 283 cc = pkgs.llvmPackages.clang-unwrapped; 284 284 libc = pkgs.darwin.Libsystem;