make check_for_compiler_existence an instance variable

This commit is contained in:
Todd Gamblin 2018-05-17 11:43:23 -07:00 committed by scheibelp
parent e9a3e3bfbb
commit 5ef30e0a51
3 changed files with 16 additions and 18 deletions

View File

@ -169,7 +169,7 @@ def mirror_create(args):
"""Create a directory to be used as a spack mirror, and fill it with
package archives."""
# try to parse specs from the command line first.
with spack.concretize.disable_compiler_existence_check():
with spack.concretize.concretizer.disable_compiler_existence_check():
specs = spack.cmd.parse_specs(args.specs, concretize=True)
# If there is a file, parse each line as a spec and add it to the list.

View File

@ -50,10 +50,6 @@
from spack.version import ver, Version, VersionList, VersionRange
from spack.package_prefs import PackagePrefs, spec_externals, is_spec_buildable
#: controls whether we check that compiler versions actually exist during
#: concretization. Used for testing.
check_for_compiler_existence = True
#: Concretizer singleton
concretizer = llnl.util.lang.Singleton(lambda: Concretizer())
@ -63,19 +59,21 @@
_abi = llnl.util.lang.Singleton(lambda: spack.abi.ABI())
@contextmanager
def disable_compiler_existence_check():
global check_for_compiler_existence
saved = check_for_compiler_existence
check_for_compiler_existence = False
yield
check_for_compiler_existence = saved
class Concretizer(object):
"""You can subclass this class to override some of the default
concretization strategies, or you can override all of them.
"""
def __init__(self):
# controls whether we check that compiler versions actually exist
# during concretization. Used for testing and for mirror creation
self.check_for_compiler_existence = True
@contextmanager
def disable_compiler_existence_check(self):
saved = self.check_for_compiler_existence
self.check_for_compiler_existence = False
yield
self.check_for_compiler_existence = saved
def _valid_virtuals_and_externals(self, spec):
"""Returns a list of candidate virtual dep providers and external
@ -311,7 +309,7 @@ def _proper_compiler_style(cspec, aspec):
return spack.compilers.compilers_for_spec(cspec, arch_spec=aspec)
if spec.compiler and spec.compiler.concrete:
if (check_for_compiler_existence and not
if (self.check_for_compiler_existence and not
_proper_compiler_style(spec.compiler, spec.architecture)):
_compiler_concretization_failure(
spec.compiler, spec.architecture)
@ -325,7 +323,7 @@ def _proper_compiler_style(cspec, aspec):
# Check if the compiler is already fully specified
if (other_compiler and other_compiler.concrete and
not check_for_compiler_existence):
not self.check_for_compiler_existence):
spec.compiler = other_compiler.copy()
return True
@ -419,7 +417,7 @@ def concretize_compiler_flags(self, spec):
compiler = spack.compilers.compiler_for_spec(
spec.compiler, spec.architecture)
except spack.compilers.NoCompilerForSpecError:
if check_for_compiler_existence:
if self.check_for_compiler_existence:
raise
return ret
for flag in compiler.flags:

View File

@ -153,7 +153,7 @@ def test_concretize_disable_compiler_existence_check(self):
with pytest.raises(spack.concretize.UnavailableCompilerVersionError):
check_concretize('dttop %gcc@100.100')
with spack.concretize.disable_compiler_existence_check():
with spack.concretize.concretizer.disable_compiler_existence_check():
spec = check_concretize('dttop %gcc@100.100')
assert spec.satisfies('%gcc@100.100')
assert spec['dtlink3'].satisfies('%gcc@100.100')