blob: ea7a52e6fe2c96bf03a52f7c3d1386dc98424aaf (
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
|
{
lib,
runCommand,
python3Packages,
makeWrapper,
writableTmpDirAsHomeHook,
}:
{
feature ? "cuda",
name ? if feature == null then "cpu" else feature,
libraries ? [ ], # [PythonPackage] | (PackageSet -> [PythonPackage])
gpuCheckArgs ? { },
...
}@args:
let
inherit (builtins) isFunction all;
librariesFun = if isFunction libraries then libraries else (_: libraries);
in
assert lib.assertMsg (
isFunction libraries || all (python3Packages.hasPythonModule) libraries
) "writeGpuTestPython was passed `libraries` from the wrong python release";
content:
let
interpreter = python3Packages.python.withPackages librariesFun;
tester =
runCommand "tester-${name}"
(
lib.removeAttrs args [
"gpuCheckArgs"
"libraries"
"name"
]
// {
inherit content;
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ makeWrapper ];
passAsFile = args.passAsFile or [ ] ++ [ "content" ];
}
)
''
mkdir -p "$out"/bin
cat << EOF >"$out/bin/$name"
#!${lib.getExe interpreter}
EOF
cat "$contentPath" >>"$out/bin/$name"
chmod +x "$out/bin/$name"
if [[ -n "''${makeWrapperArgs+''${makeWrapperArgs[@]}}" ]] ; then
wrapProgram "$out/bin/$name" ''${makeWrapperArgs[@]}
fi
'';
tester' = tester.overrideAttrs (oldAttrs: {
passthru.gpuCheck =
runCommand "test-${name}"
(
gpuCheckArgs
// {
nativeBuildInputs = [
tester'
]
++ gpuCheckArgs.nativeBuildInputs or [ ];
requiredSystemFeatures =
lib.optionals (feature != null) [ feature ] ++ gpuCheckArgs.requiredSystemFeatures or [ ];
}
)
''
set -e
${tester.meta.mainProgram or (lib.getName tester')}
touch $out
'';
});
in
tester'
|