CompilerAdaptor: add support for opt_flags/debug_flags (#50126)
This commit is contained in:
@@ -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")
|
||||
|
Reference in New Issue
Block a user