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 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"; 54 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 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 - ''); 92 93 # The dynamic linker has different names on different platforms. This is a 94 # shell glob that ought to match it. ··· 129 gnugrep_bin = if nativeTools then "" else gnugrep; 130 131 binPrefix = prefix; 132 133 passthru = { 134 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile 135 - prefix infixSalt infixSalt_ _infixSalt; 136 137 emacsBufferSetup = pkgs: '' 138 ; We should handle propagation here too 139 (mapc (lambda (arg) 140 (when (file-directory-p (concat arg "/include")) 141 - (setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include"))) 142 (when (file-directory-p (concat arg "/lib")) 143 - (setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib"))) 144 (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)})) 146 ''; 147 }; 148 ··· 268 # Solaris needs an additional ld wrapper. 269 ldPath="${nativePrefix}/bin" 270 exec="$ldPath/${prefix}ld" 271 - wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh} 272 '') 273 274 + '' ··· 282 '' + (if !useMacosReexportHack then '' 283 wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld} 284 '' else '' 285 - export binPrefix=${prefix} 286 ldInner="${prefix}ld-reexport-delegate" 287 wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld} 288 wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner" ··· 290 '') + '' 291 292 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then 293 - wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold 294 fi 295 296 if [ -e ${binutils_bin}/bin/ld.bfd ]; then 297 - wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd 298 fi 299 300 # We export environment variables pointing to the wrapped nonstandard ··· 306 export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" 307 308 if [ -e $ccPath/${prefix}gcc ]; then 309 - wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc 310 ln -s ${prefix}gcc $out/bin/${prefix}cc 311 export named_cc=${prefix}gcc 312 export named_cxx=${prefix}g++ 313 elif [ -e $ccPath/clang ]; then 314 - wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang 315 ln -s ${prefix}clang $out/bin/${prefix}cc 316 export named_cc=${prefix}clang 317 export named_cxx=${prefix}clang++ 318 fi 319 320 if [ -e $ccPath/${prefix}g++ ]; then 321 - wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++ 322 ln -s ${prefix}g++ $out/bin/${prefix}c++ 323 elif [ -e $ccPath/clang++ ]; then 324 - wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++ 325 ln -s ${prefix}clang++ $out/bin/${prefix}c++ 326 fi 327 328 if [ -e $ccPath/cpp ]; then 329 - wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp 330 fi 331 '' 332 333 + optionalString cc.langFortran or false '' 334 - wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran 335 ln -sv ${prefix}gfortran $out/bin/${prefix}g77 336 ln -sv ${prefix}gfortran $out/bin/${prefix}f77 337 '' 338 339 + optionalString cc.langJava or false '' 340 - wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj 341 '' 342 343 + optionalString cc.langGo or false '' 344 - wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo 345 '' 346 347 + 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 352 '' 353 354 + optionalString cc.langVhdl or false '' ··· 356 '' 357 358 + '' 359 - substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp 360 cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook 361 rm $out/nix-support/setup-hook.tmp 362 ··· 375 '' 376 377 + '' 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 381 '' 382 + extraBuildCommands; 383
··· 53 "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"; 54 55 dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config; 56 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; 63 64 # The dynamic linker has different names on different platforms. This is a 65 # shell glob that ought to match it. ··· 100 gnugrep_bin = if nativeTools then "" else gnugrep; 101 102 binPrefix = prefix; 103 + inherit infixSalt; 104 105 passthru = { 106 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile 107 + prefix; 108 109 emacsBufferSetup = pkgs: '' 110 ; We should handle propagation here too 111 (mapc (lambda (arg) 112 (when (file-directory-p (concat arg "/include")) 113 + (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include"))) 114 (when (file-directory-p (concat arg "/lib")) 115 + (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib"))) 116 (when (file-directory-p (concat arg "/lib64")) 117 + (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) 118 ''; 119 }; 120 ··· 240 # Solaris needs an additional ld wrapper. 241 ldPath="${nativePrefix}/bin" 242 exec="$ldPath/${prefix}ld" 243 + wrap ld-solaris ${./ld-solaris-wrapper.sh} 244 '') 245 246 + '' ··· 254 '' + (if !useMacosReexportHack then '' 255 wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld} 256 '' else '' 257 ldInner="${prefix}ld-reexport-delegate" 258 wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld} 259 wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner" ··· 261 '') + '' 262 263 if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then 264 + wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold 265 fi 266 267 if [ -e ${binutils_bin}/bin/ld.bfd ]; then 268 + wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd 269 fi 270 271 # We export environment variables pointing to the wrapped nonstandard ··· 277 export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" 278 279 if [ -e $ccPath/${prefix}gcc ]; then 280 + wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc 281 ln -s ${prefix}gcc $out/bin/${prefix}cc 282 export named_cc=${prefix}gcc 283 export named_cxx=${prefix}g++ 284 elif [ -e $ccPath/clang ]; then 285 + wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang 286 ln -s ${prefix}clang $out/bin/${prefix}cc 287 export named_cc=${prefix}clang 288 export named_cxx=${prefix}clang++ 289 fi 290 291 if [ -e $ccPath/${prefix}g++ ]; then 292 + wrap ${prefix}g++ ${./cc-wrapper.sh} $ccPath/${prefix}g++ 293 ln -s ${prefix}g++ $out/bin/${prefix}c++ 294 elif [ -e $ccPath/clang++ ]; then 295 + wrap ${prefix}clang++ ${./cc-wrapper.sh} $ccPath/clang++ 296 ln -s ${prefix}clang++ $out/bin/${prefix}c++ 297 fi 298 299 if [ -e $ccPath/cpp ]; then 300 + wrap ${prefix}cpp ${./cc-wrapper.sh} $ccPath/cpp 301 fi 302 '' 303 304 + optionalString cc.langFortran or false '' 305 + wrap ${prefix}gfortran ${./cc-wrapper.sh} $ccPath/${prefix}gfortran 306 ln -sv ${prefix}gfortran $out/bin/${prefix}g77 307 ln -sv ${prefix}gfortran $out/bin/${prefix}f77 308 '' 309 310 + optionalString cc.langJava or false '' 311 + wrap ${prefix}gcj ${./cc-wrapper.sh} $ccPath/${prefix}gcj 312 '' 313 314 + optionalString cc.langGo or false '' 315 + wrap ${prefix}gccgo ${./cc-wrapper.sh} $ccPath/${prefix}gccgo 316 '' 317 318 + optionalString cc.langAda or false '' 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 323 '' 324 325 + optionalString cc.langVhdl or false '' ··· 327 '' 328 329 + '' 330 + substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook.tmp 331 cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook 332 rm $out/nix-support/setup-hook.tmp 333 ··· 346 '' 347 348 + '' 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 352 '' 353 + extraBuildCommands; 354