lol

Merge pull request #229754 from rrbutani/fix/cc-wrapper-extra-positional-args

Support `--` in `cc-wrapper`

authored by

John Ericson and committed by
GitHub
f4868c6c e7799046

+41
+18
pkgs/build-support/cc-wrapper/cc-wrapper.sh
··· 33 33 expandResponseParams "$@" 34 34 linkType=$(checkLinkType "${params[@]}") 35 35 36 + declare -ag positionalArgs=() 36 37 declare -i n=0 37 38 nParams=${#params[@]} 38 39 while (( "$n" < "$nParams" )); do ··· 53 54 *-header) dontLink=1 ;; 54 55 c++*) isCxx=1 ;; 55 56 esac 57 + ;; 58 + --) # Everything else is positional args! 59 + # See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74 60 + 61 + # Any positional arg (i.e. any argument after `--`) will be 62 + # interpreted as a "non flag" arg: 63 + if [[ -v "params[$n]" ]]; then nonFlagArgs=1; fi 64 + 65 + positionalArgs=("${params[@]:$n}") 66 + params=("${params[@]:0:$((n - 1))}") 67 + break; 56 68 ;; 57 69 -?*) ;; 58 70 *) nonFlagArgs=1 ;; # Includes a solitary dash (`-`) which signifies standard input; it is not a flag ··· 205 217 if [ "$cc1" = 1 ]; then 206 218 extraAfter=() 207 219 extraBefore=() 220 + fi 221 + 222 + # Finally, if we got any positional args, append them to `extraAfter` 223 + # now: 224 + if [[ "${#positionalArgs[@]}" -gt 0 ]]; then 225 + extraAfter+=(-- "${positionalArgs[@]}") 208 226 fi 209 227 210 228 # Optionally print debug info.
+23
pkgs/test/cc-wrapper/default.nix
··· 13 13 name = "cc-wrapper-test"; 14 14 15 15 buildCommand = '' 16 + set -o pipefail 17 + 16 18 NIX_DEBUG=1 $CC -v 17 19 NIX_DEBUG=1 $CXX -v 18 20 ··· 41 43 $CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c} 42 44 ${emulator} ./cc-static-pie 43 45 ''} 46 + ''} 47 + 48 + ${# See: https://github.com/llvm/llvm-project/commit/ed1d07282cc9d8e4c25d585e03e5c8a1b6f63a74 49 + # `gcc` does not support this so we gate the test on `clang` 50 + lib.optionalString stdenv.cc.isClang '' 51 + printf "checking whether cc-wrapper accepts -- followed by positional (file) args..." >&2 52 + mkdir -p positional 53 + 54 + # Make sure `--` is not parsed as a "non flag arg"; we should get an 55 + # input file error here and *not* a linker error. 56 + { ! $CC --; } |& grep -q "no input files" 57 + 58 + # And that positional file args _must_ be files (this is just testing 59 + # that we remembered to put the `--` back in the args to the compiler): 60 + { ! $CC -c -- -o foo ${./foo.c}; } \ 61 + |& grep -q "no such file or directory: '-o'" 62 + 63 + # Now check that we accept single and multiple positional file args: 64 + $CC -c -DVALUE=42 -o positional/foo.o -- ${./foo.c} 65 + $CC -o positional/main -- positional/foo.o ${./ldflags-main.c} 66 + ${emulator} ./positional/main 44 67 ''} 45 68 46 69 printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2