concretizer: try hard to infer the real version of compilers (#20099)

fixes #20055

Compiler with custom versions like gcc@foo are not currently
matched to the appropriate targets. This is because the
version of spec doesn't match the "real" version of the
compiler.

This PR replicates the strategy used in the original
concretizer to deal with that and tries to detect the real
version of compilers if the version in the spec returns no
results.
This commit is contained in:
Massimiliano Culpo 2020-12-02 20:30:28 +01:00 committed by GitHub
parent 007ff2a6b0
commit 05848c87c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 3 deletions

View file

@ -31,6 +31,7 @@
import spack
import spack.architecture
import spack.cmd
import spack.compilers
import spack.config
import spack.dependency
import spack.error
@ -829,6 +830,18 @@ def compiler_defaults(self):
f = fn.default_compiler_preference(cspec.name, cspec.version, i)
self.gen.fact(f)
# Enumerate target families. This may be redundant, but compilers with
# custom versions will be able to concretize properly.
for entry in spack.compilers.all_compilers_config():
compiler_entry = entry['compiler']
cspec = spack.spec.CompilerSpec(compiler_entry['spec'])
if not compiler_entry.get('target', None):
continue
self.gen.fact(fn.compiler_supports_target(
cspec.name, cspec.version, compiler_entry['target']
))
def compiler_supports_os(self):
compilers_yaml = spack.compilers.all_compilers_config()
for entry in compilers_yaml:
@ -1230,7 +1243,7 @@ def build_version_dict(self, possible_pkgs, specs):
if dep.versions.concrete:
self.possible_versions[dep.name].add(dep.version)
def _supported_targets(self, compiler, targets):
def _supported_targets(self, compiler_name, compiler_version, targets):
"""Get a list of which targets are supported by the compiler.
Results are ordered most to least recent.
@ -1239,7 +1252,7 @@ def _supported_targets(self, compiler, targets):
for target in targets:
try:
target.optimization_flags(compiler.name, compiler.version)
target.optimization_flags(compiler_name, compiler_version)
supported.append(target)
except archspec.cpu.UnsupportedMicroarchitecture:
continue
@ -1289,7 +1302,22 @@ def target_defaults(self, specs):
# TODO: investigate this.
best_targets = set([uarch.family.name])
for compiler in sorted(compilers):
supported = self._supported_targets(compiler, compatible_targets)
supported = self._supported_targets(
compiler.name, compiler.version, compatible_targets
)
# If we can't find supported targets it may be due to custom
# versions in the spec, e.g. gcc@foo. Try to match the
# real_version from the compiler object to get more accurate
# results.
if not supported:
compiler_obj = spack.compilers.compilers_for_spec(compiler)
compiler_obj = compiler_obj[0]
supported = self._supported_targets(
compiler.name,
compiler_obj.real_version,
compatible_targets
)
if not supported:
continue

View file

@ -959,3 +959,11 @@ def test_variant_not_default(self):
# Check that non-default variant values are forced on the dependency
d = s['dep-with-variants']
assert '+foo+bar+baz' in d
@pytest.mark.regression('20055')
def test_custom_compiler_version(self):
if spack.config.get('config:concretizer') == 'original':
pytest.xfail('Known failure of the original concretizer')
s = Spec('a %gcc@foo os=redhat6').concretized()
assert '%gcc@foo' in s

View file

@ -8,6 +8,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
spec: gcc@4.5.0
operating_system: {0.name}{0.version}
@ -17,6 +18,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
spec: clang@3.3
operating_system: CNL
@ -35,6 +37,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
spec: clang@3.3
operating_system: yosemite
@ -44,6 +47,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
paths:
cc: /path/to/gcc
@ -62,6 +66,7 @@ compilers:
operating_system: SuSE11
spec: gcc@4.5.0
modules: 'None'
target: x86_64
- compiler:
paths:
cc: /path/to/gcc
@ -71,6 +76,7 @@ compilers:
operating_system: yosemite
spec: gcc@4.5.0
modules: 'None'
target: x86_64
- compiler:
paths:
cc: /path/to/gcc
@ -80,6 +86,7 @@ compilers:
operating_system: elcapitan
spec: gcc@4.5.0
modules: 'None'
target: x86_64
- compiler:
spec: clang@3.3
operating_system: elcapitan
@ -89,6 +96,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
spec: gcc@4.7.2
operating_system: redhat6
@ -102,6 +110,7 @@ compilers:
cxxflags: -O0 -g
fflags: -O0 -g
modules: 'None'
target: x86_64
- compiler:
spec: gcc@4.4.0
operating_system: redhat6
@ -123,6 +132,7 @@ compilers:
cflags: -O3
cxxflags: -O3
modules: 'None'
target: x86_64
- compiler:
spec: clang@8.0.0
operating_system: redhat7
@ -135,6 +145,7 @@ compilers:
cflags: -O3
cxxflags: -O3
modules: 'None'
target: x86_64
- compiler:
spec: apple-clang@9.1.0
operating_system: elcapitan
@ -144,6 +155,7 @@ compilers:
f77: None
fc: None
modules: 'None'
target: x86_64
- compiler:
spec: gcc@foo
operating_system: redhat6
@ -153,6 +165,7 @@ compilers:
f77: /path/to/gfortran
fc: /path/to/gfortran
modules: 'None'
target: x86_64
- compiler:
spec: gcc@4.4.0-special
operating_system: redhat6
@ -162,3 +175,4 @@ compilers:
f77: /path/to/gfortran
fc: /path/to/gfortran
modules: 'None'
target: x86_64