abi.py: fix typo, add type-hints (#38216)
Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
parent
da0813b049
commit
37bafce384
@ -8,8 +8,8 @@
|
|||||||
from llnl.util.lang import memoized
|
from llnl.util.lang import memoized
|
||||||
|
|
||||||
import spack.spec
|
import spack.spec
|
||||||
|
import spack.version
|
||||||
from spack.compilers.clang import Clang
|
from spack.compilers.clang import Clang
|
||||||
from spack.spec import CompilerSpec
|
|
||||||
from spack.util.executable import Executable, ProcessError
|
from spack.util.executable import Executable, ProcessError
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +17,9 @@ class ABI:
|
|||||||
"""This class provides methods to test ABI compatibility between specs.
|
"""This class provides methods to test ABI compatibility between specs.
|
||||||
The current implementation is rather rough and could be improved."""
|
The current implementation is rather rough and could be improved."""
|
||||||
|
|
||||||
def architecture_compatible(self, target, constraint):
|
def architecture_compatible(
|
||||||
|
self, target: spack.spec.Spec, constraint: spack.spec.Spec
|
||||||
|
) -> bool:
|
||||||
"""Return true if architecture of target spec is ABI compatible
|
"""Return true if architecture of target spec is ABI compatible
|
||||||
to the architecture of constraint spec. If either the target
|
to the architecture of constraint spec. If either the target
|
||||||
or constraint specs have no architecture, target is also defined
|
or constraint specs have no architecture, target is also defined
|
||||||
@ -34,7 +36,7 @@ def _gcc_get_libstdcxx_version(self, version):
|
|||||||
a compiler's libstdc++ or libgcc_s"""
|
a compiler's libstdc++ or libgcc_s"""
|
||||||
from spack.build_environment import dso_suffix
|
from spack.build_environment import dso_suffix
|
||||||
|
|
||||||
spec = CompilerSpec("gcc", version)
|
spec = spack.spec.CompilerSpec("gcc", version)
|
||||||
compilers = spack.compilers.compilers_for_spec(spec)
|
compilers = spack.compilers.compilers_for_spec(spec)
|
||||||
if not compilers:
|
if not compilers:
|
||||||
return None
|
return None
|
||||||
@ -77,16 +79,20 @@ def _gcc_compiler_compare(self, pversion, cversion):
|
|||||||
return False
|
return False
|
||||||
return plib == clib
|
return plib == clib
|
||||||
|
|
||||||
def _intel_compiler_compare(self, pversion, cversion):
|
def _intel_compiler_compare(
|
||||||
|
self, pversion: spack.version.ClosedOpenRange, cversion: spack.version.ClosedOpenRange
|
||||||
|
) -> bool:
|
||||||
"""Returns true iff the intel version pversion and cversion
|
"""Returns true iff the intel version pversion and cversion
|
||||||
are ABI compatible"""
|
are ABI compatible"""
|
||||||
|
|
||||||
# Test major and minor versions. Ignore build version.
|
# Test major and minor versions. Ignore build version.
|
||||||
if len(pversion.version) < 2 or len(cversion.version) < 2:
|
pv = pversion.lo
|
||||||
return False
|
cv = cversion.lo
|
||||||
return pversion.version[:2] == cversion.version[:2]
|
return pv.up_to(2) == cv.up_to(2)
|
||||||
|
|
||||||
def compiler_compatible(self, parent, child, **kwargs):
|
def compiler_compatible(
|
||||||
|
self, parent: spack.spec.Spec, child: spack.spec.Spec, loose: bool = False
|
||||||
|
) -> bool:
|
||||||
"""Return true if compilers for parent and child are ABI compatible."""
|
"""Return true if compilers for parent and child are ABI compatible."""
|
||||||
if not parent.compiler or not child.compiler:
|
if not parent.compiler or not child.compiler:
|
||||||
return True
|
return True
|
||||||
@ -95,7 +101,7 @@ def compiler_compatible(self, parent, child, **kwargs):
|
|||||||
# Different compiler families are assumed ABI incompatible
|
# Different compiler families are assumed ABI incompatible
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if kwargs.get("loose", False):
|
if loose:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# TODO: Can we move the specialized ABI matching stuff
|
# TODO: Can we move the specialized ABI matching stuff
|
||||||
@ -116,9 +122,10 @@ def compiler_compatible(self, parent, child, **kwargs):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def compatible(self, target, constraint, **kwargs):
|
def compatible(
|
||||||
|
self, target: spack.spec.Spec, constraint: spack.spec.Spec, loose: bool = False
|
||||||
|
) -> bool:
|
||||||
"""Returns true if target spec is ABI compatible to constraint spec"""
|
"""Returns true if target spec is ABI compatible to constraint spec"""
|
||||||
loosematch = kwargs.get("loose", False)
|
|
||||||
return self.architecture_compatible(target, constraint) and self.compiler_compatible(
|
return self.architecture_compatible(target, constraint) and self.compiler_compatible(
|
||||||
target, constraint, loose=loosematch
|
target, constraint, loose=loose
|
||||||
)
|
)
|
||||||
|
@ -155,7 +155,7 @@ def _valid_virtuals_and_externals(self, spec):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def choose_virtual_or_external(self, spec):
|
def choose_virtual_or_external(self, spec: spack.spec.Spec):
|
||||||
"""Given a list of candidate virtual and external packages, try to
|
"""Given a list of candidate virtual and external packages, try to
|
||||||
find one that is most ABI compatible.
|
find one that is most ABI compatible.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user