cxx: new test API (#45462)

* cxx: new test API
* gcc: provide cxx
* default providers:  cxx provided by gcc
* cxx: cleanup stand-alone test
  - test_c -> test_cxx
  - simplify compilation and execution
  - corrected output checks

---------

Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
This commit is contained in:
AcriusWinter 2024-08-08 22:23:05 -07:00 committed by GitHub
parent 7bec524dd5
commit 899ac78887
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 22 deletions

View File

@ -20,6 +20,7 @@ packages:
awk: [gawk]
armci: [armcimpi]
blas: [openblas, amdblis]
cxx: [gcc]
D: [ldc]
daal: [intel-oneapi-daal]
elf: [elfutils]

View File

@ -14,28 +14,27 @@ class Cxx(Package):
homepage = "https://isocpp.org/std/the-standard"
virtual = True
def test(self):
def test_cxx(self):
"""Compile and run 'Hello World'"""
cxx = which(os.environ["CXX"])
expected = ["Hello world", "YES!"]
test_source = self.test_suite.current_test_data_dir
for test in os.listdir(test_source):
filepath = os.path.join(test_source, test)
exe_name = "%s.exe" % test
exe_name = f"{test}.exe"
filepath = test_source.join(test)
with test_part(self, f"test_cxx_{test}", f"build and run {exe_name}"):
# standard options
# Hack to get compiler attributes
# TODO: remove this when compilers are dependencies
c_name = clang if self.spec.satisfies("llvm+clang") else self.name
c_spec = spack.spec.CompilerSpec(c_name, self.spec.version)
c_cls = spack.compilers.class_for_compiler_name(c_name)
compiler = c_cls(c_spec, None, None, ["fakecc", "fakecxx"])
cxx_opts = [compiler.cxx11_flag] if "c++11" in test else []
cxx_opts += ["-o", exe_name, filepath]
cxx_exe = os.environ["CXX"]
# standard options
# Hack to get compiler attributes
# TODO: remove this when compilers are dependencies
c_name = clang if self.spec.satisfies("llvm+clang") else self.name
c_spec = spack.spec.CompilerSpec(c_name, self.spec.version)
c_cls = spack.compilers.class_for_compiler_name(c_name)
compiler = c_cls(c_spec, None, None, ["fakecc", "fakecxx"])
cxx_opts = [compiler.cxx11_flag] if "c++11" in test else []
cxx_opts += ["-o", exe_name, filepath]
compiled = self.run_test(cxx_exe, options=cxx_opts, installed=True)
if compiled:
expected = ["Hello world", "YES!"]
self.run_test(exe_name, expected=expected)
cxx(*cxx_opts)
exe = which(exe_name)
out = exe(output=str.split, error=str.split)
check_outputs(expected, out)

View File

@ -34,6 +34,8 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage, CompilerPackage):
license("GPL-2.0-or-later AND LGPL-2.1-or-later")
provides("cxx")
version("master", branch="master")
version("14.2.0", sha256="a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9")