concretizer: avoid redundant grounding on dependency types

This commit is contained in:
Massimiliano Culpo 2020-12-16 14:03:37 +01:00 committed by Todd Gamblin
parent bb78a73ed3
commit d8dc4b141e
2 changed files with 24 additions and 27 deletions

View File

@ -728,7 +728,7 @@ def pkg_rules(self, pkg, tests):
def package_dependencies_rules(self, pkg, tests): def package_dependencies_rules(self, pkg, tests):
"""Translate 'depends_on' directives into ASP logic.""" """Translate 'depends_on' directives into ASP logic."""
for name, conditions in sorted(pkg.dependencies.items()): for _, conditions in sorted(pkg.dependencies.items()):
for cond_id, (cond, dep) in enumerate(sorted(conditions.items())): for cond_id, (cond, dep) in enumerate(sorted(conditions.items())):
named_cond = cond.copy() named_cond = cond.copy()
named_cond.name = named_cond.name or pkg.name named_cond.name = named_cond.name or pkg.name
@ -751,19 +751,16 @@ def package_dependencies_rules(self, pkg, tests):
continue continue
# there is a declared dependency of type t # there is a declared dependency of type t
# TODO: this ends up being redundant in the output --
# TODO: not sure if we really need it anymore.
# TODO: Look at simplifying the logic in concretize.lp
self.gen.fact( self.gen.fact(
fn.declared_dependency(dep.pkg.name, dep.spec.name, t)) fn.declared_dependency(dep.pkg.name, dep.spec.name, cond_id, t)
)
# if it has conditions, declare them. # if it has conditions, declare them.
conditions = self.spec_clauses(named_cond, body=True) conditions = self.spec_clauses(named_cond, body=True)
for cond in conditions: for cond in conditions:
self.gen.fact( self.gen.fact(
fn.dep_cond( fn.dep_cond(
dep.pkg.name, dep.spec.name, t, cond_id, dep.pkg.name, dep.spec.name, cond_id,
cond.name, *cond.args cond.name, *cond.args
) )
) )

View File

@ -55,32 +55,32 @@ depends_on(Package, Dependency, Type)
not external(Package). not external(Package).
% if any individual condition below is true, trigger the dependency. % if any individual condition below is true, trigger the dependency.
dependency_conditions(P, D, T) :- dependency_conditions(P, D, T, _). dependency_conditions(P, D, T) :-
dependency_conditions_hold(P, D, I), declared_dependency(P, D, I, T).
% collect all the dependency condtions into a single conditional rule % collect all the dependency condtions into a single conditional rule
dependency_conditions(P, D, T, I) :- dependency_conditions_hold(P, D, I) :-
node(Package) node(Package)
: dep_cond(P, D, T, I, "node", Package); : dep_cond(P, D, I, "node", Package);
version(Package, Version) version(Package, Version)
: dep_cond(P, D, T, I, "version", Package, Version); : dep_cond(P, D, I, "version", Package, Version);
version_satisfies(Package, Constraint) version_satisfies(Package, Constraint)
: dep_cond(P, D, T, I, "version_satisfies", Package, Constraint); : dep_cond(P, D, I, "version_satisfies", Package, Constraint);
node_platform(Package, Platform) node_platform(Package, Platform)
: dep_cond(P, D, T, I, "node_platform", Package, Platform); : dep_cond(P, D, I, "node_platform", Package, Platform);
node_os(Package, OS) node_os(Package, OS)
: dep_cond(P, D, T, I, "node_os", Package, OS); : dep_cond(P, D, I, "node_os", Package, OS);
node_target(Package, Target) node_target(Package, Target)
: dep_cond(P, D, T, I, "node_target", Package, Target); : dep_cond(P, D, I, "node_target", Package, Target);
variant_value(Package, Variant, Value) variant_value(Package, Variant, Value)
: dep_cond(P, D, T, I, "variant_value", Package, Variant, Value); : dep_cond(P, D, I, "variant_value", Package, Variant, Value);
node_compiler(Package, Compiler) node_compiler(Package, Compiler)
: dep_cond(P, D, T, I, "node_compiler", Package, Compiler); : dep_cond(P, D, I, "node_compiler", Package, Compiler);
node_compiler_version(Package, Compiler, Version) node_compiler_version(Package, Compiler, Version)
: dep_cond(P, D, T, I, "node_compiler_version", Package, Compiler, Version); : dep_cond(P, D, I, "node_compiler_version", Package, Compiler, Version);
node_flag(Package, FlagType, Flag) node_flag(Package, FlagType, Flag)
: dep_cond(P, D, T, I, "node_flag", Package, FlagType, Flag); : dep_cond(P, D, I, "node_flag", Package, FlagType, Flag);
dependency_condition(P, D, I); dependency_condition(P, D, I);
declared_dependency(P, D, T);
node(P). node(P).
% if a virtual was required by some root spec, one provider is in the DAG % if a virtual was required by some root spec, one provider is in the DAG