diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2020-12-13 17:22:27 -0800 |
---|---|---|
committer | Tamara Dahlgren <dahlgren1@llnl.gov> | 2021-02-17 17:07:29 -0800 |
commit | 6c6631cfdce3b63a491590eea7c2bc7d487eb0a3 (patch) | |
tree | 89aca7a8937e5c3034977c7609b7120d954e5eb0 /lib | |
parent | ea617f807ffd696f6c254317bc54c7cde2108c29 (diff) | |
download | spack-6c6631cfdce3b63a491590eea7c2bc7d487eb0a3.tar.gz spack-6c6631cfdce3b63a491590eea7c2bc7d487eb0a3.tar.bz2 spack-6c6631cfdce3b63a491590eea7c2bc7d487eb0a3.tar.xz spack-6c6631cfdce3b63a491590eea7c2bc7d487eb0a3.zip |
concretizer: spec_clauses should traverse dependencies
There are currently no places where we do not want to traverse
dependencies in `spec_clauses()`, so simplify the logic by consolidating
`spec_traverse_clauses()` with `spec_clauses()`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/solver/asp.py | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index c7a3dda21d..9de674ab60 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -750,7 +750,7 @@ class SpackSolverSetup(object): ) ) else: - clauses = self.spec_traverse_clauses(named_cond) + clauses = self.spec_clauses(named_cond, body=True) self.gen.rule( fn.declared_dependency( @@ -776,17 +776,11 @@ class SpackSolverSetup(object): clause, self.gen._and( fn.depends_on(dep.pkg.name, dep.spec.name), - *self.spec_traverse_clauses(named_cond) + *self.spec_clauses(named_cond, body=True) ) ) self.gen.newline() - def spec_traverse_clauses(self, named_cond): - clauses = [] - for d in named_cond.traverse(): - clauses.extend(self.spec_clauses(d, body=True)) - return clauses - def virtual_preferences(self, pkg_name, func): """Call func(vspec, provider, i) for each of pkg's provider prefs.""" config = spack.config.get("packages") @@ -957,13 +951,15 @@ class SpackSolverSetup(object): self.gen.fact(fn.compiler_version_flag( compiler.name, compiler.version, name, flag)) - def spec_clauses(self, spec, body=False): + def spec_clauses(self, spec, body=False, transitive=True): """Return a list of clauses for a spec mandates are true. Arguments: spec (Spec): the spec to analyze body (bool): if True, generate clauses to be used in rule bodies (final values) instead of rule heads (setters). + transitive (bool): if False, don't generate clauses from + dependencies (default True) """ clauses = [] @@ -1049,8 +1045,17 @@ class SpackSolverSetup(object): for flag in flags: clauses.append(f.node_flag(spec.name, flag_type, flag)) - # TODO - # namespace + # TODO: namespace + + # dependencies + if spec.concrete: + clauses.append(fn.concrete(spec.name)) + # TODO: add concrete depends_on() facts for concrete dependencies + + # add all clauses from dependencies + if transitive: + for dep in spec.traverse(root=False): + clauses.extend(self.spec_clauses(dep, body, transitive=False)) return clauses @@ -1266,6 +1271,7 @@ class SpackSolverSetup(object): def define_virtual_constraints(self): for vspec_str in sorted(self.virtual_constraints): vspec = spack.spec.Spec(vspec_str) + self.gen.h2("Virtual spec: {0}".format(vspec_str)) providers = spack.repo.path.providers_for(vspec_str) candidates = self.providers_by_vspec_name[vspec.name] @@ -1427,15 +1433,13 @@ class SpackSolverSetup(object): else: self.gen.fact(fn.virtual_root(spec.name)) - for dep in spec.traverse(): - self.gen.h2('Spec: %s' % str(dep)) - if dep.virtual: - for clause in self.virtual_spec_clauses(dep): - self.gen.fact(clause) - continue - - for clause in self.spec_clauses(dep): - self.gen.fact(clause) + self.gen.h2('Spec: %s' % str(spec)) + if spec.virtual: + clauses = self.virtual_spec_clauses(spec) + else: + clauses = self.spec_clauses(spec) + for clause in clauses: + self.gen.fact(clause) self.gen.h1("Variant Values defined in specs") self.define_variant_values() |