summary refs log tree commit diff
path: root/pkgs/test/stdenv/default.nix
blob: 01f0e0fe8b834aae983596f05c653a233eeb8e2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# To run these tests:
# nix-build -A tests.stdenv

{ stdenv
, pkgs
, lib
,
}:

let
  # use a early stdenv so when hacking on stdenv this test can be run quickly
  bootStdenv = stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv;
  pkgsStructured = import pkgs.path { config = { structuredAttrsByDefault = true; }; inherit (stdenv.hostPlatform) system; };
  bootStdenvStructuredAttrsByDefault = pkgsStructured.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv.__bootPackages.stdenv;
in

{
  test-env-attrset = bootStdenv.mkDerivation {
    name = "test-env-attrset";
    dontUnpack = true;
    dontConfigure = true;
    dontBuild = true;
    dontPatch = true;
    dontFixup = true;
    env = {
      string = "testing-string";
    };

    installPhase = ''
      declare -p string
      echo "env.string = $string"
      [[ $string == "testing-string" ]] || (echo "string was not testing-string" && false)
      touch $out
    '';
  };

  test-structured-env-attrset = bootStdenv.mkDerivation {
    name = "test-structured-env-attrset";
    dontUnpack = true;
    dontConfigure = true;
    dontBuild = true;
    dontPatch = true;
    dontFixup = true;
    __structuredAttrs = true;
    env = {
      string = "testing-string";
    };

    installPhase = ''
      declare -p string
      echo "env.string = $string"
      [[ $string == "testing-string" ]] || (echo "string was not testing-string" && false)
      touch $out
    '';
  };

  test-cc-wrapper-substitutions = bootStdenv.cc.overrideAttrs (previousAttrs: {
    name = "test-cc-wrapper-substitutions";

    postFixup = previousAttrs.postFixup + ''
      declare -p wrapperName
      echo "env.wrapperName = $wrapperName"
      [[ $wrapperName == "CC_WRAPPER" ]] || (echo "wrapperName was not CC_WRAPPER" && false)
      touch $out
    '';
  });

  structuredAttrsByDefault = lib.recurseIntoAttrs {

    test-cc-wrapper-substitutions = bootStdenvStructuredAttrsByDefault.cc.overrideAttrs (previousAttrs: {
      name = "test-cc-wrapper-substitutions-structuredAttrsByDefault";

      postFixup = previousAttrs.postFixup + ''
        declare -p wrapperName
        echo "env.wrapperName = $wrapperName"
        [[ $wrapperName == "CC_WRAPPER" ]] || (echo "wrapperName was not CC_WRAPPER" && false)
        declare -p suffixSalt
        echo "env.suffixSalt = $suffixSalt"
        [[ $suffixSalt == "${bootStdenvStructuredAttrsByDefault.cc.suffixSalt}" ]] || (echo "wrapperName was not ${bootStdenvStructuredAttrsByDefault.cc.suffixSalt}" && false)

        grep -q "@out@" $out/bin/cc || echo "@out@ in $out/bin/cc was substituted"
        grep -q "@suffixSalt@" $out/bin/cc && (echo "$out/bin/cc contains unsubstituted variables" && false)

        touch $out
      '';
    });

    test-structured-env-attrset = bootStdenvStructuredAttrsByDefault.mkDerivation {
      name = "test-structured-env-attrset-structuredAttrsByDefault";
      dontUnpack = true;
      dontConfigure = true;
      dontBuild = true;
      dontPatch = true;
      dontFixup = true;
      env = {
        string = "testing-string";
      };

      installPhase = ''
        declare -p string
        echo "env.string = $string"
        [[ $string == "testing-string" ]] || (echo "string was not testing-string" && false)
        touch $out
      '';
    };
  };
}