Skip to content

Commit d40f73f

Browse files
committed
Simplified YAML structure for detection tests
1 parent d1c916b commit d40f73f

5 files changed

Lines changed: 79 additions & 106 deletions

File tree

lib/spack/docs/packaging_guide.rst

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6186,16 +6186,10 @@ the ``paths`` attribute:
61866186
61876187
paths:
61886188
- layout:
6189-
- subdir: [bin]
6190-
name: clang-3.9
6191-
output: |
6192-
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
6193-
echo "Target: x86_64-pc-linux-gnu"
6194-
echo "Thread model: posix"
6195-
echo "InstalledDir: /usr/bin"
6196-
- subdir: [bin]
6197-
name: clang++-3.9
6198-
output: |
6189+
- executables:
6190+
- "bin/clang-3.9"
6191+
- "bin/clang++-3.9"
6192+
script: |
61996193
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
62006194
echo "Target: x86_64-pc-linux-gnu"
62016195
echo "Thread model: posix"
@@ -6220,15 +6214,11 @@ package detection and checking that the outcome matches the expected
62206214
- Specifies the filesystem tree used for the test
62216215
- List of objects
62226216
- Yes
6223-
* - ``layout:[0]:subdir``
6224-
- Subdirectory for this executable
6217+
* - ``layout:[0]:executables``
6218+
- Relative paths for the mock executables to be created
62256219
- List of strings
62266220
- Yes
6227-
* - ``layout:[0]:name``
6228-
- Name of the executable
6229-
- A valid filename
6230-
- Yes
6231-
* - ``layout:[0]:output``
6221+
* - ``layout:[0]:script``
62326222
- Mock logic for the executable
62336223
- Any valid shell script
62346224
- Yes

lib/spack/spack/audit.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _search_duplicate_compilers(error_cls):
4343
import inspect
4444
import itertools
4545
import os.path
46+
import pathlib
4647
import pickle
4748
import re
4849
import tempfile
@@ -845,15 +846,21 @@ def _test_detection_by_executable(pkgs, error_cls):
845846

846847
errors, tmpdir = [], tempfile.mkdtemp()
847848

848-
def mock_executable(name, output, subdir=("bin",)):
849-
file_parts = list(subdir) + [name]
850-
f = os.path.join(tmpdir, *file_parts)
851-
llnl.util.filesystem.mkdirp(os.path.dirname(f))
852-
t = jinja2.Template("#!/bin/bash\n{{ output }}\n")
853-
with open(f, "w") as fs:
854-
fs.write(t.render(output=output))
855-
llnl.util.filesystem.set_executable(f)
856-
return f
849+
def create_executable_scripts(layout_entry):
850+
relative_paths = layout_entry["executables"]
851+
script = layout_entry["script"]
852+
script_template = jinja2.Template("#!/bin/bash\n{{ script }}\n")
853+
tmp_path = pathlib.Path(tmpdir)
854+
855+
result = []
856+
for mock_exe_path in relative_paths:
857+
rel_path = pathlib.Path(mock_exe_path)
858+
abs_path = tmp_path / rel_path
859+
abs_path.parent.mkdir(parents=True, exist_ok=True)
860+
abs_path.write_text(script_template.render(script=script))
861+
llnl.util.filesystem.set_executable(abs_path)
862+
result.append(abs_path)
863+
return result
857864

858865
def detection_tests_for(pkg):
859866
pkg_dir = os.path.dirname(spack.repo.PATH.filename_for_package_name(pkg))
@@ -864,15 +871,17 @@ def detection_tests_for(pkg):
864871
@contextlib.contextmanager
865872
def setup_test_layout(layout):
866873
hints, to_be_removed = set(), []
867-
for binary in layout:
868-
exe = mock_executable(binary["name"], binary["output"], subdir=binary["subdir"])
869-
to_be_removed.append(exe)
870-
hints.add(os.path.dirname(str(exe)))
874+
for entry in layout:
875+
exes = create_executable_scripts(entry)
876+
to_be_removed.extend(exes)
877+
878+
for mock_executable in exes:
879+
hints.add(str(mock_executable.parent))
871880

872881
yield list(hints)
873882

874883
for exe in to_be_removed:
875-
os.unlink(exe)
884+
exe.unlink()
876885

877886
# Filter the packages and retain only the ones with detection tests
878887
pkgs_with_tests = packages_with_detection_tests()
Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
11
paths:
22
# Ubuntu 18.04, system compilers without Fortran
33
- layout:
4-
- subdir: [bin]
5-
name: gcc
6-
output: "echo 7.5.0"
7-
- subdir: [bin]
8-
name: g++
9-
output: "echo 7.5.0"
4+
- executables:
5+
- "bin/gcc"
6+
- "bin/g++"
7+
script: "echo 7.5.0"
108
results:
119
- spec: "gcc@7.5.0 languages=c,c++"
1210
# Mock a version < 7 of GCC that requires -dumpversion and
1311
# errors with -dumpfullversion
1412
- layout:
15-
- subdir: [bin]
16-
name: gcc-5
17-
output: |
13+
- executables:
14+
- "bin/gcc-5"
15+
- "bin/g++-5"
16+
- "bin/gfortran-5"
17+
script: |
1818
if [[ "$1" == "-dumpversion" ]] ; then
1919
echo "5.5.0"
2020
else
2121
echo "gcc-5: fatal error: no input files"
2222
echo "compilation terminated."
2323
exit 1
2424
fi
25-
- subdir: [bin]
26-
name: g++-5
27-
output: "echo 5.5.0"
28-
- subdir: [bin]
29-
name: gfortran-5
30-
output: "echo 5.5.0"
3125
results:
3226
- spec: "gcc@5.5.0 languages=c,c++,fortran"
3327
# Multiple compilers present at the same time
3428
- layout:
35-
- subdir: [bin]
36-
name: x86_64-linux-gnu-gcc-6
37-
output: 'echo 6.5.0'
38-
- subdir: [bin]
39-
name: x86_64-linux-gnu-gcc-10
40-
output: "echo 10.1.0"
41-
- subdir: [bin]
42-
name: x86_64-linux-gnu-g++-10
43-
output: "echo 10.1.0"
29+
- executables:
30+
- "bin/x86_64-linux-gnu-gcc-6"
31+
script: 'echo 6.5.0'
32+
- executables:
33+
- "bin/x86_64-linux-gnu-gcc-10"
34+
- "bin/x86_64-linux-gnu-g++-10"
35+
script: "echo 10.1.0"
4436
results:
4537
- spec: "gcc@6.5.0 languages=c"
4638
- spec: "gcc@10.1.0 languages=c,c++"

var/spack/repos/builtin/packages/intel/detection_test.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
paths:
22
- layout:
3-
- subdir: [bin, intel64]
4-
name: icc
5-
output: |
3+
- executables:
4+
- "bin/intel64/icc"
5+
script: |
66
echo "icc (ICC) 18.0.5 20180823"
77
echo "Copyright (C) 1985-2018 Intel Corporation. All rights reserved."
8-
- subdir: [bin, intel64]
9-
name: icpc
10-
output: |
8+
- executables:
9+
- "bin/intel64/icpc"
10+
script: |
1111
echo "icpc (ICC) 18.0.5 20180823"
1212
echo "Copyright (C) 1985-2018 Intel Corporation. All rights reserved."
13-
- subdir: [bin, intel64]
14-
name: ifort
15-
output: |
13+
- executables:
14+
- "bin/intel64/ifort"
15+
script: |
1616
echo "ifort (IFORT) 18.0.5 20180823"
1717
echo "Copyright (C) 1985-2018 Intel Corporation. All rights reserved."
1818
results:

var/spack/repos/builtin/packages/llvm/detection_test.yaml

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
paths:
22
- layout:
3-
- subdir: [bin]
4-
name: clang-3.9
5-
output: |
3+
- executables:
4+
- "bin/clang-3.9"
5+
script: |
66
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
77
echo "Target: x86_64-pc-linux-gnu"
88
echo "Thread model: posix"
99
echo "InstalledDir: /usr/bin"
10-
- subdir: [bin]
11-
name: clang++-3.9
12-
output: |
10+
- executables:
11+
- "bin/clang++-3.9"
12+
script: |
1313
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
1414
echo "Target: x86_64-pc-linux-gnu"
1515
echo "Thread model: posix"
@@ -18,36 +18,24 @@ paths:
1818
- spec: 'llvm@3.9.1 +clang~lld~lldb'
1919
# Multiple LLVM packages in the same prefix
2020
- layout:
21-
- subdir: [bin]
22-
name: clang-8
23-
output: |
21+
- executables:
22+
- "bin/clang-8"
23+
- "bin/clang++-8"
24+
script: |
2425
echo "clang version 8.0.0-3~ubuntu18.04.2 (tags/RELEASE_800/final)"
2526
echo "Target: x86_64-pc-linux-gnu"
2627
echo "Thread model: posix"
2728
echo "InstalledDir: /usr/bin"
28-
- subdir: [bin]
29-
name: clang++-8
30-
output: |
31-
echo "clang version 8.0.0-3~ubuntu18.04.2 (tags/RELEASE_800/final)"
32-
echo "Target: x86_64-pc-linux-gnu"
33-
echo "Thread model: posix"
34-
echo "InstalledDir: /usr/bin"
35-
- subdir: [bin]
36-
name: ld.lld-8
37-
output: 'echo "LLD 8.0.0 (compatible with GNU linkers)"'
38-
- subdir: [bin]
39-
name: lldb
40-
output: 'echo "lldb version 8.0.0"'
41-
- subdir: [bin]
42-
name: clang-3.9
43-
output: |
44-
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
45-
echo "Target: x86_64-pc-linux-gnu"
46-
echo "Thread model: posix"
47-
echo "InstalledDir: /usr/bin"
48-
- subdir: [bin]
49-
name: clang++-3.9
50-
output: |
29+
- executables:
30+
- "bin/ld.lld-8"
31+
script: 'echo "LLD 8.0.0 (compatible with GNU linkers)"'
32+
- executables:
33+
- "bin/lldb"
34+
script: 'echo "lldb version 8.0.0"'
35+
- executables:
36+
- "bin/clang-3.9"
37+
- "bin/clang++-3.9"
38+
script: |
5139
echo "clang version 3.9.1-19ubuntu1 (tags/RELEASE_391/rc2)"
5240
echo "Target: x86_64-pc-linux-gnu"
5341
echo "Thread model: posix"
@@ -57,16 +45,10 @@ paths:
5745
- spec: 'llvm@3.9.1+clang~lld~lldb'
5846
# Apple Clang should not be detected
5947
- layout:
60-
- subdir: [bin]
61-
name: clang
62-
output: |
63-
echo "Apple clang version 11.0.0 (clang-1100.0.33.8)"
64-
echo "Target: x86_64-apple-darwin19.5.0"
65-
echo "Thread model: posix"
66-
echo "InstalledDir: /Library/Developer/CommandLineTools/usr/bin"
67-
- subdir: [bin]
68-
name: 'clang++'
69-
output: |
48+
- executables:
49+
- "bin/clang"
50+
- "bin/clang++"
51+
script: |
7052
echo "Apple clang version 11.0.0 (clang-1100.0.33.8)"
7153
echo "Target: x86_64-apple-darwin19.5.0"
7254
echo "Thread model: posix"

0 commit comments

Comments
 (0)