concretizer bugfix: fix generations of conditionals for dependencies

Spack was generating the same dependency connstraints twice in the output ASP:

```
declared_dependency("abinit", "hdf5", "link")
    :- node("abinit"),
       variant_value("abinit", "mpi", "True"),
       variant_value("abinit", "mpi", "True").
```

This was because `AspFunction` was modifying itself when called.

- [x] fix `AspFunction` so that every call returns a new object
This commit is contained in:
Todd Gamblin 2020-01-02 19:51:19 -08:00
parent e31be3da56
commit 9b1f05df00

View file

@ -73,13 +73,12 @@ def _id(thing):
class AspFunction(AspObject): class AspFunction(AspObject):
def __init__(self, name): def __init__(self, name, args=None):
self.name = name self.name = name
self.args = [] self.args = [] if args is None else args
def __call__(self, *args): def __call__(self, *args):
self.args[:] = args return AspFunction(self.name, args)
return self
def __getitem___(self, *args): def __getitem___(self, *args):
self.args[:] = args self.args[:] = args
@ -89,6 +88,9 @@ def __str__(self):
return "%s(%s)" % ( return "%s(%s)" % (
self.name, ', '.join(_id(arg) for arg in self.args)) self.name, ', '.join(_id(arg) for arg in self.args))
def __repr__(self):
return str(self)
class AspAnd(AspObject): class AspAnd(AspObject):
def __init__(self, *args): def __init__(self, *args):
@ -394,6 +396,7 @@ def pkg_rules(self, pkg):
*self.spec_clauses(named_cond, body=True) *self.spec_clauses(named_cond, body=True)
) )
) )
self.out.write('\n')
# virtual preferences # virtual preferences
self.virtual_preferences( self.virtual_preferences(