11 env = { nativeBuildInputs = [ makeBinaryWrapper ]; };
12 envCheck = runCommandCC "envcheck" env ''
13 cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
15 makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
16 mkdir -p tmp/foo # for the chdir test
18 source=${lib.fileset.toSource {
20 fileset = lib.fileset.unions [
21 (./. + "/${testname}.cmdline")
22 (./. + "/${testname}.c")
23 (lib.fileset.maybeMissing (./. + "/${testname}.env"))
27 params=$(<"$source/${testname}.cmdline")
28 eval "makeCWrapper /send/me/flags $params" > wrapper.c
30 diff wrapper.c "$source/${testname}.c"
32 if [ -f "$source/${testname}.env" ]; then
33 eval "makeWrapper ${envCheck} wrapped $params"
34 env -i ./wrapped > env.txt
35 sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
36 "$source/${testname}.env" > golden-env.txt
37 if ! diff env.txt golden-env.txt; then
38 echo "env/argv should be:"
40 echo "env/argv output is:"
45 # without a golden env, we expect the wrapper compilation to fail
46 ! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt
51 tests = lib.genAttrs [
63 ] makeGoldenTest // lib.optionalAttrs (! stdenv.hostPlatform.isDarwin) {
64 cross = pkgsCross.${if stdenv.buildPlatform.isAarch64 then "gnu64" else "aarch64-multiplatform"}.callPackage ./cross.nix { };
68 writeText "make-binary-wrapper-tests" ''
69 ${lib.concatStringsSep "\n" (builtins.attrValues tests)}