CompilerAdaptor: add support for opt_flags/debug_flags (#50126)
This commit is contained in:
parent
41ff0500f9
commit
a3c430e810
@ -47,6 +47,11 @@ class CompilerPackage(spack.package_base.PackageBase):
|
||||
#: Relative path to compiler wrappers
|
||||
compiler_wrapper_link_paths: Dict[str, str] = {}
|
||||
|
||||
#: Optimization flags
|
||||
opt_flags: Sequence[str] = []
|
||||
#: Flags for generating debug information
|
||||
debug_flags: Sequence[str] = []
|
||||
|
||||
def __init__(self, spec: "spack.spec.Spec"):
|
||||
super().__init__(spec)
|
||||
msg = f"Supported languages for {spec} are not a subset of possible supported languages"
|
||||
|
@ -18,6 +18,10 @@ class Languages(enum.Enum):
|
||||
|
||||
|
||||
class CompilerAdaptor:
|
||||
"""Provides access to compiler attributes via `Package.compiler`. Useful for
|
||||
packages which do not yet access compiler properties via `self.spec[language]`.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, compiled_spec: spack.spec.Spec, compilers: Dict[Languages, spack.spec.Spec]
|
||||
) -> None:
|
||||
@ -79,6 +83,14 @@ def implicit_rpaths(self) -> List[str]:
|
||||
result.extend(CompilerPropertyDetector(compiler).implicit_rpaths())
|
||||
return result
|
||||
|
||||
@property
|
||||
def opt_flags(self) -> List[str]:
|
||||
return next(iter(self.compilers.values())).package.opt_flags
|
||||
|
||||
@property
|
||||
def debug_flags(self) -> List[str]:
|
||||
return next(iter(self.compilers.values())).package.debug_flags
|
||||
|
||||
@property
|
||||
def openmp_flag(self) -> str:
|
||||
return next(iter(self.compilers.values())).package.openmp_flag
|
||||
|
@ -1365,6 +1365,18 @@ def test_splice_swap_names_mismatch_virtuals(self, default_mock_concretization,
|
||||
with pytest.raises(spack.spec.SpliceError, match="virtual"):
|
||||
vt.splice(vh, transitive)
|
||||
|
||||
def test_adaptor_optflags(self):
|
||||
"""Tests that we can obtain the list of optflags, and debugflags,
|
||||
from the compiler adaptor, and that this list is taken from the
|
||||
appropriate compiler package.
|
||||
"""
|
||||
# pkg-a depends on c, so only the gcc compiler should be chosen
|
||||
spec = spack.concretize.concretize_one(Spec("pkg-a %gcc"))
|
||||
assert "-Otestopt" in spec.package.compiler.opt_flags
|
||||
# This is not set, make sure we get an empty list
|
||||
for x in spec.package.compiler.debug_flags:
|
||||
pass
|
||||
|
||||
def test_spec_override(self):
|
||||
init_spec = Spec("pkg-a foo=baz foobar=baz cflags=-O3 cxxflags=-O1")
|
||||
change_spec = Spec("pkg-a foo=fee cflags=-O2")
|
||||
|
@ -40,6 +40,8 @@ class Gcc(CompilerPackage, Package):
|
||||
compiler_version_regex = r"(?<!clang version)\s?([0-9.]+)"
|
||||
compiler_version_argument = ("-dumpfullversion", "-dumpversion")
|
||||
|
||||
opt_flags = ["-Otestopt"]
|
||||
|
||||
compiler_wrapper_link_paths = {
|
||||
"c": os.path.join("gcc", "gcc"),
|
||||
"cxx": os.path.join("gcc", "g++"),
|
||||
|
@ -659,8 +659,8 @@ def find_optional_library(name, prefix):
|
||||
|
||||
if cxxflags:
|
||||
# Add opt/debug flags if they are not present in global cxx flags
|
||||
opt_flag_found = any(f in self.compiler.opt_flags for f in cxxflags)
|
||||
debug_flag_found = any(f in self.compiler.debug_flags for f in cxxflags)
|
||||
opt_flag_found = any(f in self["cxx"].opt_flags for f in cxxflags)
|
||||
debug_flag_found = any(f in self["cxx"].debug_flags for f in cxxflags)
|
||||
|
||||
if "+debug" in spec:
|
||||
if not debug_flag_found:
|
||||
|
Loading…
Reference in New Issue
Block a user