summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/cxx/package.py
blob: 481f2c83c037de0ec1b02921594bac4393da6ec6 (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
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os

from spack.package import *


class Cxx(Package):
    """Virtual package for the C++ language."""

    homepage = "https://isocpp.org/std/the-standard"
    virtual = True

    def test(self):
        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

            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)