aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-09-25 13:46:07 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2017-09-27 22:01:24 +0300
commitdda5e8cadbfdeee3267b1a0943c014e06bcd0100 (patch)
tree049a70c550729d722e23c67d8312c2eaa820da6f /mesonbuild/interpreterbase.py
parentdfc2b75ee2dba3245ac23bb3d7f0156e47773ed5 (diff)
downloadmeson-dda5e8cadbfdeee3267b1a0943c014e06bcd0100.zip
meson-dda5e8cadbfdeee3267b1a0943c014e06bcd0100.tar.gz
meson-dda5e8cadbfdeee3267b1a0943c014e06bcd0100.tar.bz2
Allow CustomTarget's to be indexed
This allows a CustomTarget to be indexed, and the resulting indexed value (a CustomTargetIndex type), to be used as a source in other targets. This will confer a dependency on the original target, but only inserts the source file returning by index the original target's outputs. This can allow a CustomTarget that creates both a header and a code file to have it's outputs split, for example. Fixes #1470
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 1dd2f02..cb82e56 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -369,14 +369,16 @@ class InterpreterBase:
def evaluate_indexing(self, node):
assert(isinstance(node, mparser.IndexNode))
iobject = self.evaluate_statement(node.iobject)
- if not isinstance(iobject, list):
- raise InterpreterException('Tried to index a non-array object.')
+ if not hasattr(iobject, '__getitem__'):
+ raise InterpreterException(
+ 'Tried to index an object that doesn\'t support indexing.')
index = self.evaluate_statement(node.index)
if not isinstance(index, int):
raise InterpreterException('Index value is not an integer.')
- if index < -len(iobject) or index >= len(iobject):
+ try:
+ return iobject[index]
+ except IndexError:
raise InterpreterException('Index %d out of bounds of array of size %d.' % (index, len(iobject)))
- return iobject[index]
def function_call(self, node):
func_name = node.func_name