summaryrefslogtreecommitdiff
path: root/pkgs/build-support/setup-hooks/arrayUtilities/getRunpathEntries/tests.nix
blob: d6d84ba5f485eecf405d94033fb1c13a8171de41 (plain)
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
# NOTE: Tests related to getRunpathEntries go here.
{
  emptyFile,
  getRunpathEntries,
  hello,
  lib,
  pkgsStatic,
  stdenv,
  testers,
}:
let
  inherit (lib.attrsets) recurseIntoAttrs;
  inherit (testers)
    shellcheck
    shfmt
    testBuildFailure'
    testEqualArrayOrMap
    ;

  check =
    {
      name,
      elfFile,
      runpathEntries,
    }:
    (testEqualArrayOrMap {
      inherit name;
      expectedArray = runpathEntries;
      script = ''
        set -eu
        nixLog "running getRunpathEntries with ''${elfFile@Q} to populate actualArray"
        getRunpathEntries "$elfFile" actualArray || {
          nixErrorLog "getRunpathEntries failed"
          exit 1
        }
      '';
    }).overrideAttrs
      (prevAttrs: {
        inherit elfFile;
        nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ getRunpathEntries ];
        meta = prevAttrs.meta or { } // {
          platforms = lib.platforms.linux;
        };
      });
in
recurseIntoAttrs {
  shellcheck = shellcheck {
    name = "getRunpathEntries";
    src = ./getRunpathEntries.bash;
  };

  shfmt = shfmt {
    name = "getRunpathEntries";
    src = ./getRunpathEntries.bash;
  };
}
# Only tested on Linux.
// lib.optionalAttrs stdenv.hostPlatform.isLinux {
  # Not an ELF file
  notElfFileFails = testBuildFailure' {
    name = "notElfFileFails";
    drv = check {
      name = "notElfFile";
      elfFile = emptyFile;
      runpathEntries = [ ];
    };
    expectedBuilderLogEntries = [
      "getRunpathEntries failed"
    ];
  };

  # Not a dynamic ELF file
  staticElfFileFails = testBuildFailure' {
    name = "staticElfFileFails";
    drv = check {
      name = "staticElfFile";
      elfFile = lib.getExe pkgsStatic.hello;
      runpathEntries = [ ];
    };
    expectedBuilderLogEntries = [
      "getRunpathEntries failed"
    ];
  };

  hello = check {
    name = "hello";
    elfFile = lib.getExe hello;
    runpathEntries = [
      "${lib.getLib stdenv.cc.libc}/lib"
    ];
  };

  libstdcplusplus = check {
    name = "libstdcplusplus";
    elfFile = "${lib.getLib stdenv.cc.cc}/lib/libstdc++.so";
    runpathEntries = [
      "${lib.getLib stdenv.cc.cc}/lib"
      "${lib.getLib stdenv.cc.libc}/lib"
    ];
  };
}