Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / test / make-binary-wrapper / default.nix
blob4c6fffd100a726fcc6e968d89bbd1f9b6d0fea58
1 { lib
2 , stdenv
3 , pkgsCross
4 , makeBinaryWrapper
5 , writeText
6 , runCommand
7 , runCommandCC
8 }:
10 let
11   env = { nativeBuildInputs = [ makeBinaryWrapper ]; };
12   envCheck = runCommandCC "envcheck" env ''
13     cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
14   '';
15   makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
16     mkdir -p tmp/foo # for the chdir test
18     params=$(<"${./.}/${testname}.cmdline")
19     eval "makeCWrapper /send/me/flags $params" > wrapper.c
21     diff wrapper.c "${./.}/${testname}.c"
23     if [ -f "${./.}/${testname}.env" ]; then
24       eval "makeWrapper ${envCheck} wrapped $params"
25       env -i ./wrapped > env.txt
26       sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \
27         "${./.}/${testname}.env" > golden-env.txt
28       if ! diff env.txt golden-env.txt; then
29         echo "env/argv should be:"
30         cat golden-env.txt
31         echo "env/argv output is:"
32         cat env.txt
33         exit 1
34       fi
35     else
36       # without a golden env, we expect the wrapper compilation to fail
37       ! eval "makeWrapper ${envCheck} wrapped $params" &> error.txt
38     fi
40     cp wrapper.c $out
41   '';
42   tests = lib.genAttrs [
43     "add-flags"
44     "argv0"
45     "basic"
46     "chdir"
47     "combination"
48     "env"
49     "inherit-argv0"
50     "invalid-env"
51     "overlength-strings"
52     "prefix"
53     "suffix"
54   ] makeGoldenTest // lib.optionalAttrs (! stdenv.isDarwin) {
55     cross = pkgsCross.${if stdenv.buildPlatform.isAarch64 then "gnu64" else "aarch64-multiplatform"}.callPackage ./cross.nix { };
56   };
59 writeText "make-binary-wrapper-tests" ''
60   ${lib.concatStringsSep "\n" (builtins.attrValues tests)}
61 '' // tests