concretizer: break output up into easier-to-understand sections

This commit is contained in:
Todd Gamblin 2019-08-10 19:26:00 -07:00
parent d94d957536
commit 34ea3d20cf
3 changed files with 37 additions and 22 deletions

View file

@ -112,14 +112,20 @@ def __init__(self, out):
self.out = out
self.func = AspFunctionBuilder()
def title(self, name):
def title(self, name, char):
self.out.write('\n')
self.out.write("%" + ("-" * 76))
self.out.write("%" + (char * 76))
self.out.write('\n')
self.out.write("%% %s\n" % name)
self.out.write("%" + ("-" * 76))
self.out.write("%" + (char * 76))
self.out.write('\n')
def h1(self, name):
self.title(name, "=")
def h2(self, name):
self.title(name, "-")
def section(self, name):
self.out.write("\n")
self.out.write("%\n")
@ -186,6 +192,7 @@ def pkg_rules(self, pkg):
# versions
self.pkg_version_rules(pkg)
self.out.write('\n')
# variants
for name, variant in pkg.variants.items():
@ -258,23 +265,23 @@ def generate_asp_program(self, specs):
pkgs = list(set(spack.package.possible_dependencies(*pkgs))
| set(pkg_names))
self.out.write(pkgutil.get_data('spack.solver', 'concretize.lp'))
concretize_lp = pkgutil.get_data('spack.solver', 'concretize.lp')
self.out.write(concretize_lp.decode("utf-8"))
self.title('Package Constraints')
self.h1('Package Constraints')
for pkg in pkgs:
self.section('Package: %s' % pkg)
self.h2('Package: %s' % pkg)
self.pkg_rules(pkg)
self.out.write('\n')
self.title('Spec Constraints')
self.h1('Spec Constraints')
for spec in specs:
for dep in spec.traverse():
self.section('Spec: %s' % str(dep))
self.h2('Spec: %s' % str(dep))
self.spec_rules(dep)
self.out.write('\n')
self.out.write(pkgutil.get_data('spack.solver', 'display.lp'))
self.out.write('\n')
display_lp = pkgutil.get_data('spack.solver', 'display.lp')
self.out.write(display_lp.decode("utf-8"))
class ResultParser(object):
@ -375,7 +382,7 @@ def highlight(string):
string = re.sub(r'(\w[\w-]+)\(([^)]*)\)', r'@C{\1}@w{(}\2@w{)}', string)
# comments
string = re.sub(r'(%.*)$', r'@K\1@.', string, flags=re.MULTILINE)
string = re.sub(r'(%.*)$', r'@w\1@.', string, flags=re.MULTILINE)
# strings
string = re.sub(r'("[^"]*")', r'@m{\1}', string)

View file

@ -1,6 +1,6 @@
% -----------------------------------------
%=============================================================================
% 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).
@ -11,16 +11,15 @@
{ 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).
%-----------------------------------------------------------------------------
% Variant semantics
%-----------------------------------------------------------------------------
% if a variant is set to anything, it is considered 'set'.
variant_set(P, V) :- variant_set(P, V, _).
@ -35,3 +34,12 @@ variant_set(P, V) :- variant_set(P, V, _).
variant_value(P, V, X) :- node(P), variant(P, V), variant_set(P, V, X).
variant_value(P, V, X) :- node(P), variant(P, V), not variant_set(P, V),
variant_default_value(P, V, X).
%-----------------------------------------------------------------------------
% Architecture semantics
%-----------------------------------------------------------------------------
% 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).

View file

@ -1,8 +1,8 @@
% ----------------------------------------------------------------------------
%=============================================================================-
% 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.