2022-05-29 17:26:23 +02:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, pkgsCross
|
|
|
|
, makeBinaryWrapper
|
|
|
|
, writeText
|
|
|
|
, runCommand
|
|
|
|
, runCommandCC
|
|
|
|
}:
|
2021-10-04 22:35:09 +02:00
|
|
|
|
|
|
|
let
|
2022-05-29 17:26:23 +02:00
|
|
|
env = { nativeBuildInputs = [ makeBinaryWrapper ]; };
|
|
|
|
envCheck = runCommandCC "envcheck" env ''
|
|
|
|
cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
|
2021-12-07 18:39:38 +01:00
|
|
|
'';
|
2022-05-29 17:26:23 +02:00
|
|
|
makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
|
|
|
|
mkdir -p tmp/foo # for the chdir test
|
2021-12-07 18:39:38 +01:00
|
|
|
|
|
|
|
params=$(<"${./.}/${testname}.cmdline")
|
|
|
|
eval "makeCWrapper /send/me/flags $params" > wrapper.c
|
|
|
|
|
|
|
|
diff wrapper.c "${./.}/${testname}.c"
|
|
|
|
|
|
|
|
if [ -f "${./.}/${testname}.env" ]; then
|
2021-12-09 12:31:35 +01:00
|
|
|
eval "makeWrapper ${envCheck} wrapped $params"
|
2021-12-07 18:39:38 +01:00
|
|
|
env -i ./wrapped > env.txt
|
|
|
|
sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
|
|
|
|
"${./.}/${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
|
2021-10-04 22:35:09 +02:00
|
|
|
else
|
2021-12-07 18:39:38 +01:00
|
|
|
# without a golden env, we expect the wrapper compilation to fail
|
2021-12-09 12:31:35 +01:00
|
|
|
! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt
|
2021-10-04 22:35:09 +02:00
|
|
|
fi
|
|
|
|
|
2021-12-07 18:39:38 +01:00
|
|
|
cp wrapper.c $out
|
|
|
|
'';
|
2022-05-29 17:26:23 +02:00
|
|
|
tests = lib.genAttrs [
|
|
|
|
"add-flags"
|
|
|
|
"argv0"
|
|
|
|
"basic"
|
|
|
|
"chdir"
|
|
|
|
"combination"
|
|
|
|
"env"
|
|
|
|
"inherit-argv0"
|
|
|
|
"invalid-env"
|
|
|
|
"overlength-strings"
|
|
|
|
"prefix"
|
|
|
|
"suffix"
|
|
|
|
] makeGoldenTest // lib.optionalAttrs (! stdenv.isDarwin) {
|
|
|
|
cross = pkgsCross.aarch64-multiplatform.callPackage ./cross.nix { };
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
writeText "make-binary-wrapper-tests" ''
|
|
|
|
${lib.concatStringsSep "\n" (builtins.attrValues tests)}
|
2021-12-07 18:39:38 +01:00
|
|
|
'' // tests
|