nixpkgs/pkgs/test/make-binary-wrapper/default.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

84 lines
2.0 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