summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-08-10 16:34:00 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2020-11-17 10:04:13 -0800
commit573a2612dc4d2bee77c673ceafb4f7d6e7482501 (patch)
treed8dfc8a74ef2aad3dddd23c188de798f1baa65b2 /lib
parent8bc1092f41741a3ef1de9d360cd98ccb3b317962 (diff)
downloadspack-573a2612dc4d2bee77c673ceafb4f7d6e7482501.tar.gz
spack-573a2612dc4d2bee77c673ceafb4f7d6e7482501.tar.bz2
spack-573a2612dc4d2bee77c673ceafb4f7d6e7482501.tar.xz
spack-573a2612dc4d2bee77c673ceafb4f7d6e7482501.zip
concretizer: split main logic program out into files
- Add `concretize.lp` and `display.lp` as independent files - Dump them instead of embedded strings
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/solver/asp.py71
-rw-r--r--lib/spack/spack/solver/concretize.lp30
-rw-r--r--lib/spack/spack/solver/display.lp12
3 files changed, 57 insertions, 56 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 55bf38ec50..a13f022a91 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -6,6 +6,7 @@
from __future__ import print_function
import collections
+import pkgutil
import re
import sys
import tempfile
@@ -24,49 +25,6 @@ from spack.util.executable import which
from spack.version import ver
-#: generate the problem space, establish cardinality constraints
-_generate = """\
-% One version, arch, etc. per package
-{ version(P, V) : version(P, V) } = 1 :- node(P).
-{ arch_platform(P, A) : arch_platform(P, A) } = 1 :- node(P).
-{ arch_os(P, A) : arch_os(P, A) } = 1 :- node(P).
-{ arch_target(P, T) : arch_target(P, T) } = 1 :- node(P).
-
-% one variant value for single-valued variants.
-{ variant_value(P, V, X) : variant_value(P, V, X) } = 1
- :- node(P), variant(P, V), not variant_single_value(P, V).
-"""
-
-#: define the rules of Spack concretization
-_define = """\
-% dependencies imply new nodes.
-node(D) :- node(P), depends_on(P, D).
-
-% propagate platform, os, target downwards
-arch_platform(D, A) :- node(D), depends_on(P, D), arch_platform(P, A).
-arch_os(D, A) :- node(D), depends_on(P, D), arch_os(P, A).
-arch_target(D, A) :- node(D), depends_on(P, D), arch_target(P, A).
-
-% if a variant is set to anything, it is considered "set".
-variant_set(P, V) :- variant_set(P, V, _).
-
-% variant_set is an explicitly set variant value. If it's not "set",
-% we revert to the default value. If it is set, we force the set value
-variant_value(P, V, X) :- node(P), variant(P, V), variant_set(P, V, X).
-"""
-
-#: what parts of the model to display to read models back in
-_display = """\
-#show node/1.
-#show depends_on/2.
-#show version/2.
-#show variant_value/3.
-#show arch_platform/2.
-#show arch_os/2.
-#show arch_target/2.
-"""
-
-
def _id(thing):
"""Quote string if needed for it to be a valid identifier."""
return '"%s"' % str(thing)
@@ -152,8 +110,11 @@ class AspGenerator(object):
def title(self, name):
self.out.write('\n')
+ self.out.write("%" + ("-" * 76))
+ self.out.write('\n')
self.out.write("%% %s\n" % name)
- self.out.write("% -----------------------------------------\n")
+ self.out.write("%" + ("-" * 76))
+ self.out.write('\n')
def section(self, name):
self.out.write("\n")
@@ -287,25 +248,22 @@ class AspGenerator(object):
pkgs = list(set(spack.package.possible_dependencies(*pkgs))
| set(pkg_names))
- self.title("Generate")
- self.out.write(_generate)
+ self.out.write(pkgutil.get_data('spack.solver', 'concretize.lp'))
- self.title("Define")
- self.out.write(_define)
-
- self.title("Package Constraints")
+ self.title('Package Constraints')
for pkg in pkgs:
- self.section(pkg)
+ self.section('Package: %s' % pkg)
self.pkg_rules(pkg)
+ self.out.write('\n')
- self.title("Spec Constraints")
+ self.title('Spec Constraints')
for spec in specs:
- self.section(str(spec))
+ self.section('Spec: %s' % pkg)
self.spec_rules(spec)
+ self.out.write('\n')
- self.title("Display")
- self.out.write(_display)
- self.out.write('\n\n')
+ self.out.write(pkgutil.get_data('spack.solver', 'display.lp'))
+ self.out.write('\n')
class ResultParser(object):
@@ -418,6 +376,7 @@ def highlight(string):
return string
+
#
# These are handwritten parts for the Spack ASP model.
#
diff --git a/lib/spack/spack/solver/concretize.lp b/lib/spack/spack/solver/concretize.lp
new file mode 100644
index 0000000000..b805583043
--- /dev/null
+++ b/lib/spack/spack/solver/concretize.lp
@@ -0,0 +1,30 @@
+% -----------------------------------------
+% Generate
+% -----------------------------------------
+% One version, arch, etc. per package
+{ version(P, V) : version(P, V)} = 1 :- node(P).
+{ arch_platform(P, A) : arch_platform(P, A) } = 1 :- node(P).
+{ arch_os(P, A) : arch_os(P, A) } = 1 :- node(P).
+{ arch_target(P, T) : arch_target(P, T) } = 1 :- node(P).
+
+% one variant value for single-valued variants.
+{ variant_value(P, V, X) : variant_value(P, V, X) } = 1
+ :- node(P), variant(P, V), not variant_single_value(P, V).
+
+% -----------------------------------------
+% Define
+% -----------------------------------------
+% dependencies imply new nodes.
+node(D) :- node(P), depends_on(P, D).
+
+% propagate platform, os, target downwards
+arch_platform(D, A) :- node(D), depends_on(P, D), arch_platform(P, A).
+arch_os(D, A) :- node(D), depends_on(P, D), arch_os(P, A).
+arch_target(D, A) :- node(D), depends_on(P, D), arch_target(P, A).
+
+% if a variant is set to anything, it is considered 'set'.
+variant_set(P, V) :- variant_set(P, V, _).
+
+% variant_set is an explicitly set variant value. If it's not 'set',
+% we revert to the default value. If it is set, we force the set value
+variant_value(P, V, X) :- node(P), variant(P, V), variant_set(P, V, X).
diff --git a/lib/spack/spack/solver/display.lp b/lib/spack/spack/solver/display.lp
new file mode 100644
index 0000000000..b9a8b4b158
--- /dev/null
+++ b/lib/spack/spack/solver/display.lp
@@ -0,0 +1,12 @@
+% ----------------------------------------------------------------------------
+% Display Results
+%
+% This section determines what parts of the model are printed at the end
+% ----------------------------------------------------------------------------
+#show node/1.
+#show depends_on/2.
+#show version/2.
+#show variant_value/3.
+#show arch_platform/2.
+#show arch_os/2.
+#show arch_target/2.