diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-21 16:09:24 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-21 17:28:31 +0200 |
| commit | 9a4127a1d5eeac122cb478b0e03d42c9698c41be (patch) | |
| tree | f31f04aba7944545ac288c10012c3cda5aec6b42 /kconfiglib.py | |
| parent | d23accda70935ddbf6d01f3c0043f17bffad3706 (diff) | |
Allow programmatically expanding preprocessor functions with args
Add a Variable.expanded_value_w_args() function for expanding a
preprocessor function with particular arguments. This is what
expanded_value should have been, because expanded_value_w_args() is more
general (expanded_value corresponds to zero arguments). Keep
expanded_value for backwards compatibility though.
Also add a simple __repr__() to Variable. It could show the expanded
value, but that might mean calling shell functions or user-defined
functions as a side effect (possibly with missing arguments). Not sure
that's a good idea, so just show the unexpanded value.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 670b312..a93ca0d 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5112,7 +5112,11 @@ class Variable(object): expanded_value: The expanded value of the variable. For simple variables (those defined with :=), this will equal 'value'. Accessing this property will raise a - KconfigError if any variable in the expansion expands to itself. + KconfigError if the expansion seems to be stuck in a loop. + + Note: Accessing this field is the same as calling expanded_value_w_args() + with no arguments. I hadn't considered function arguments when adding it. + It is retained for backwards compatibility though. is_recursive: True if the variable is recursive (defined with =). @@ -5130,7 +5134,22 @@ class Variable(object): """ See the class documentation. """ - return self.kconfig._expand_whole(self.value, ()) + return self.expanded_value_w_args() + + def expanded_value_w_args(self, *args): + """ + Returns the expanded value of the variable/function. Any arguments + passed will be substituted for $(1), $(2), etc. + + Raises a KconfigError if the expansion seems to be stuck in a loop. + """ + return self.kconfig._fn_val((self.name,) + args) + + def __repr__(self): + return "<variable {}, {}, value '{}'>" \ + .format(self.name, + "recursive" if self.is_recursive else "immediate", + self.value) class KconfigError(Exception): """ |
