From 3637b611a7c4bf83a55dbf8c13f492234686b787 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 2 Aug 2019 23:19:09 -0700 Subject: 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. --- lib/spack/spack/cmd/solve.py | 18 ------------------ lib/spack/spack/solver/asp.py | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/solve.py b/lib/spack/spack/cmd/solve.py index 8955f6b2a9..7fea75233d 100644 --- a/lib/spack/spack/cmd/solve.py +++ b/lib/spack/spack/cmd/solve.py @@ -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): diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 5407103b84..30268e5224 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -7,6 +7,7 @@ from __future__ import print_function import collections import re +import sys import tempfile import types from six import string_types @@ -259,6 +260,10 @@ class AspGenerator(object): 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 -- cgit v1.2.3-70-g09d2