mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 00:12:56 +00:00
e0464e4788
In preparation for the deprecation of `stdenv.isX`. These shorthands are not conducive to cross-compilation because they hide the platforms. Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way One example of why this is bad and especially affects compiler packages https://www.github.com/NixOS/nixpkgs/pull/343059 There are too many files to go through manually but a treewide should get users thinking when they see a `hostPlatform.isX` in a place where it doesn't make sense. ``` fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is" fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is" fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is" ```
71 lines
1.9 KiB
Nix
71 lines
1.9 KiB
Nix
{ lib
|
|
, stdenv
|
|
, pkgsCross
|
|
, makeBinaryWrapper
|
|
, writeText
|
|
, runCommand
|
|
, runCommandCC
|
|
}:
|
|
|
|
let
|
|
env = { nativeBuildInputs = [ makeBinaryWrapper ]; };
|
|
envCheck = runCommandCC "envcheck" env ''
|
|
cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
|
|
'';
|
|
makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
|
|
mkdir -p tmp/foo # for the chdir test
|
|
|
|
source=${lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = lib.fileset.unions [
|
|
(./. + "/${testname}.cmdline")
|
|
(./. + "/${testname}.c")
|
|
(lib.fileset.maybeMissing (./. + "/${testname}.env"))
|
|
];
|
|
}}
|
|
|
|
params=$(<"$source/${testname}.cmdline")
|
|
eval "makeCWrapper /send/me/flags $params" > wrapper.c
|
|
|
|
diff wrapper.c "$source/${testname}.c"
|
|
|
|
if [ -f "$source/${testname}.env" ]; then
|
|
eval "makeWrapper ${envCheck} wrapped $params"
|
|
env -i ./wrapped > env.txt
|
|
sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
|
|
"$source/${testname}.env" > golden-env.txt
|
|
if ! diff env.txt golden-env.txt; then
|
|
echo "env/argv should be:"
|
|
cat golden-env.txt
|
|
echo "env/argv output is:"
|
|
cat env.txt
|
|
exit 1
|
|
fi
|
|
else
|
|
# without a golden env, we expect the wrapper compilation to fail
|
|
! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt
|
|
fi
|
|
|
|
cp wrapper.c $out
|
|
'';
|
|
tests = lib.genAttrs [
|
|
"add-flags"
|
|
"argv0"
|
|
"basic"
|
|
"chdir"
|
|
"combination"
|
|
"env"
|
|
"inherit-argv0"
|
|
"invalid-env"
|
|
"overlength-strings"
|
|
"prefix"
|
|
"suffix"
|
|
] makeGoldenTest // lib.optionalAttrs (! stdenv.hostPlatform.isDarwin) {
|
|
cross = pkgsCross.${if stdenv.buildPlatform.isAarch64 then "gnu64" else "aarch64-multiplatform"}.callPackage ./cross.nix { };
|
|
};
|
|
in
|
|
|
|
writeText "make-binary-wrapper-tests" ''
|
|
${lib.concatStringsSep "\n" (builtins.attrValues tests)}
|
|
'' // tests
|