tests.makeBinaryWrapper: Prevent rebuilds when Nix files change

The source included way more files than it really needed.
This commit limits it to exactly those it needs.

This also makes sure that no rebuild is necessary when any Nix
file changes, in particular useful when we reformat the Nix files.
This commit is contained in:
Silvan Mosberger 2024-07-12 04:10:29 +02:00 committed by Silvan Mosberger
parent ea17c502d2
commit 7cb66fd579

View File

@ -15,16 +15,25 @@ let
makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env '' makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
mkdir -p tmp/foo # for the chdir test mkdir -p tmp/foo # for the chdir test
params=$(<"${./.}/${testname}.cmdline") 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 eval "makeCWrapper /send/me/flags $params" > wrapper.c
diff wrapper.c "${./.}/${testname}.c" diff wrapper.c "$source/${testname}.c"
if [ -f "${./.}/${testname}.env" ]; then if [ -f "$source/${testname}.env" ]; then
eval "makeWrapper ${envCheck} wrapped $params" eval "makeWrapper ${envCheck} wrapped $params"
env -i ./wrapped > env.txt env -i ./wrapped > env.txt
sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \ sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
"${./.}/${testname}.env" > golden-env.txt "$source/${testname}.env" > golden-env.txt
if ! diff env.txt golden-env.txt; then if ! diff env.txt golden-env.txt; then
echo "env/argv should be:" echo "env/argv should be:"
cat golden-env.txt cat golden-env.txt