cc-wrapper: Stop preWrapping

This is an ugly temp hack for cross compilation, but now we have something better on the way.

Bind `infixSalt` as an environment variable as it will be used in it.

+30 -59
+30 -59
pkgs/build-support/cc-wrapper/default.nix
··· 53 53 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"; 54 54 55 55 dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config; 56 - # TODO(@Ericson2314) Make unconditional 57 - infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) dashlessTarget; 58 - infixSalt_ = stdenv.lib.optionalString (targetPlatform != hostPlatform) (dashlessTarget + "_"); 59 - _infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) ("_" + dashlessTarget); 60 56 61 - # We want to prefix all NIX_ flags with the target triple 62 - preWrap = textFile: 63 - # TODO: Do even when not cross on next mass-rebuild 64 - # TODO: use @target_tripple@ for consistency 65 - if targetPlatform == hostPlatform 66 - then textFile 67 - else runCommand "sed-nix-env-vars" {} ('' 68 - cp --no-preserve=mode ${textFile} $out 69 - 70 - sed -i $out \ 71 - -e 's^NIX_^NIX_${infixSalt_}^g' \ 72 - -e 's^addCVars^addCVars${_infixSalt}^g' \ 73 - -e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g' 74 - 75 - # NIX_ things which we don't both use and define, we revert them 76 - #asymmetric=$( 77 - # for pre in "" "\\$" 78 - # do 79 - # grep -E -ho $pre'NIX_[a-zA-Z_]*' ./* | sed 's/\$//' | sort | uniq 80 - # done | sort | uniq -c | sort -nr | sed -n 's/^1 NIX_//gp') 81 - 82 - # hard-code for now 83 - asymmetric=("CXXSTDLIB_COMPILE" "CC") 84 - 85 - # The ([^a-zA-Z_]|$) bussiness is to ensure environment variables that 86 - # begin with `NIX_CC` don't also get blacklisted. 87 - for var in "''${asymmetric[@]}" 88 - do 89 - sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g" 90 - done 91 - ''); 57 + # The "infix salt" is a arbitrary string added in the middle of env vars 58 + # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used 59 + # without interfering. For the moment, it is defined as the target triple, 60 + # adjusted to be a valid bash identifier. This should be considered an 61 + # unstable implementation detail, however. 62 + infixSalt = dashlessTarget; 92 63 93 64 # The dynamic linker has different names on different platforms. This is a 94 65 # shell glob that ought to match it. ··· 129 100 gnugrep_bin = if nativeTools then "" else gnugrep; 130 101 131 102 binPrefix = prefix; 103 + inherit infixSalt; 132 104 133 105 passthru = { 134 106 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile 135 - prefix infixSalt infixSalt_ _infixSalt; 107 + prefix; 136 108 137 109 emacsBufferSetup = pkgs: '' 138 110 ; We should handle propagation here too 139 111 (mapc (lambda (arg) 140 112 (when (file-directory-p (concat arg "/include")) 141 - (setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include"))) 113 + (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include"))) 142 114 (when (file-directory-p (concat arg "/lib")) 143 - (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib"))) 115 + (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib"))) 144 116 (when (file-directory-p (concat arg "/lib64")) 145 - (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) 117 + (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) 146 118 ''; 147 119 }; 148 120 ··· 268 240 # Solaris needs an additional ld wrapper. 269 241 ldPath="${nativePrefix}/bin" 270 242 exec="$ldPath/${prefix}ld" 271 - wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh} 243 + wrap ld-solaris ${./ld-solaris-wrapper.sh} 272 244 '') 273 245 274 246 + '' ··· 282 254 '' + (if !useMacosReexportHack then '' 283 255 wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld} 284 256 '' else '' 285 - export binPrefix=${prefix} 286 257 ldInner="${prefix}ld-reexport-delegate" 287 258 wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld} 288 259 wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner" ··· 290 261 '') + '' 291 262 292 263 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then 293 - wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold 264 + wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold 294 265 fi 295 266 296 267 if [ -e ${binutils_bin}/bin/ld.bfd ]; then 297 - wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd 268 + wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd 298 269 fi 299 270 300 271 # We export environment variables pointing to the wrapped nonstandard ··· 306 277 export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" 307 278 308 279 if [ -e $ccPath/${prefix}gcc ]; then 309 - wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc 280 + wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc 310 281 ln -s ${prefix}gcc $out/bin/${prefix}cc 311 282 export named_cc=${prefix}gcc 312 283 export named_cxx=${prefix}g++ 313 284 elif [ -e $ccPath/clang ]; then 314 - wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang 285 + wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang 315 286 ln -s ${prefix}clang $out/bin/${prefix}cc 316 287 export named_cc=${prefix}clang 317 288 export named_cxx=${prefix}clang++ 318 289 fi 319 290 320 291 if [ -e $ccPath/${prefix}g++ ]; then 321 - wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++ 292 + wrap ${prefix}g++ ${./cc-wrapper.sh} $ccPath/${prefix}g++ 322 293 ln -s ${prefix}g++ $out/bin/${prefix}c++ 323 294 elif [ -e $ccPath/clang++ ]; then 324 - wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++ 295 + wrap ${prefix}clang++ ${./cc-wrapper.sh} $ccPath/clang++ 325 296 ln -s ${prefix}clang++ $out/bin/${prefix}c++ 326 297 fi 327 298 328 299 if [ -e $ccPath/cpp ]; then 329 - wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp 300 + wrap ${prefix}cpp ${./cc-wrapper.sh} $ccPath/cpp 330 301 fi 331 302 '' 332 303 333 304 + optionalString cc.langFortran or false '' 334 - wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran 305 + wrap ${prefix}gfortran ${./cc-wrapper.sh} $ccPath/${prefix}gfortran 335 306 ln -sv ${prefix}gfortran $out/bin/${prefix}g77 336 307 ln -sv ${prefix}gfortran $out/bin/${prefix}f77 337 308 '' 338 309 339 310 + optionalString cc.langJava or false '' 340 - wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj 311 + wrap ${prefix}gcj ${./cc-wrapper.sh} $ccPath/${prefix}gcj 341 312 '' 342 313 343 314 + optionalString cc.langGo or false '' 344 - wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo 315 + wrap ${prefix}gccgo ${./cc-wrapper.sh} $ccPath/${prefix}gccgo 345 316 '' 346 317 347 318 + optionalString cc.langAda or false '' 348 - wrap ${prefix}gnatgcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gnatgcc 349 - wrap ${prefix}gnatmake ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatmake 350 - wrap ${prefix}gnatbind ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatbind 351 - wrap ${prefix}gnatlink ${preWrap ./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink 319 + wrap ${prefix}gnatgcc ${./cc-wrapper.sh} $ccPath/${prefix}gnatgcc 320 + wrap ${prefix}gnatmake ${./gnat-wrapper.sh} $ccPath/${prefix}gnatmake 321 + wrap ${prefix}gnatbind ${./gnat-wrapper.sh} $ccPath/${prefix}gnatbind 322 + wrap ${prefix}gnatlink ${./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink 352 323 '' 353 324 354 325 + optionalString cc.langVhdl or false '' ··· 356 327 '' 357 328 358 329 + '' 359 - substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp 330 + substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook.tmp 360 331 cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook 361 332 rm $out/nix-support/setup-hook.tmp 362 333 ··· 375 346 '' 376 347 377 348 + '' 378 - substituteAll ${preWrap ./add-flags.sh} $out/nix-support/add-flags.sh 379 - substituteAll ${preWrap ./add-hardening.sh} $out/nix-support/add-hardening.sh 380 - substituteAll ${preWrap ./utils.sh} $out/nix-support/utils.sh 349 + substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh 350 + substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh 351 + substituteAll ${./utils.sh} $out/nix-support/utils.sh 381 352 '' 382 353 + extraBuildCommands; 383 354