concretizer: move dump logic into solver.asp
- moving the dump logic into spack.solver.asp.solve() allows us to print out useful debug info sooner - prior approach required a successful solve to print out anyhting.
This commit is contained in:
parent
81e187e410
commit
3637b611a7
@ -93,24 +93,6 @@ def solve(parser, args):
|
||||
if not result.satisfiable:
|
||||
tty.die("Unsatisfiable spec.")
|
||||
|
||||
# dump generated ASP program
|
||||
if 'asp' in dump:
|
||||
tty.msg('ASP program:')
|
||||
sys.stdout.write(result.asp)
|
||||
|
||||
# dump any warnings generated by the solver
|
||||
if 'warnings' in dump:
|
||||
if result.warnings:
|
||||
tty.msg('Clingo gave the following warnings:')
|
||||
sys.stdout.write(result.warnings)
|
||||
else:
|
||||
tty.msg('No warnings.')
|
||||
|
||||
# dump the raw output of the solver
|
||||
if 'output' in dump:
|
||||
tty.msg('Clingo output:')
|
||||
sys.stdout.write(result.output)
|
||||
|
||||
# dump the solutions as concretized specs
|
||||
if 'solutions' in dump:
|
||||
for i, answer in enumerate(result.answers):
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
import collections
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
import types
|
||||
from six import string_types
|
||||
@ -259,6 +260,10 @@ def spec_rules(self, spec):
|
||||
self.fact(fn.arch_os(spec.name, arch.os))
|
||||
self.fact(fn.arch_target(spec.name, arch.target))
|
||||
|
||||
# variants
|
||||
for vname, variant in spec.variants.items():
|
||||
self.fact(fn.variant_value(spec.name, vname, variant.value))
|
||||
|
||||
# TODO
|
||||
# dependencies
|
||||
# compiler
|
||||
@ -403,6 +408,10 @@ def solve(specs, dump=None, models=1):
|
||||
result = Result(program.read())
|
||||
program.seek(0)
|
||||
|
||||
if 'asp' in dump:
|
||||
tty.msg('ASP program:')
|
||||
sys.stdout.write(result.asp)
|
||||
|
||||
with tempfile.TemporaryFile("w+") as output:
|
||||
with tempfile.TemporaryFile() as warnings:
|
||||
clingo(
|
||||
@ -412,13 +421,26 @@ def solve(specs, dump=None, models=1):
|
||||
error=warnings,
|
||||
fail_on_error=False)
|
||||
|
||||
warnings.seek(0)
|
||||
result.warnings = warnings.read()
|
||||
|
||||
# dump any warnings generated by the solver
|
||||
if 'warnings' in dump:
|
||||
if result.warnings:
|
||||
tty.msg('Clingo gave the following warnings:')
|
||||
sys.stdout.write(result.warnings)
|
||||
else:
|
||||
tty.msg('No warnings.')
|
||||
|
||||
output.seek(0)
|
||||
result.output = output.read()
|
||||
|
||||
# dump the raw output of the solver
|
||||
if 'output' in dump:
|
||||
tty.msg('Clingo output:')
|
||||
sys.stdout.write(result.output)
|
||||
|
||||
output.seek(0)
|
||||
parser.parse(output, result)
|
||||
|
||||
warnings.seek(0)
|
||||
result.warnings = warnings.read()
|
||||
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user