aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.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/build.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/build.py')
-rw-r--r--mesonbuild/build.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index c54abbd..d3c0b54 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -425,7 +425,7 @@ class BuildTarget(Target):
if s not in added_sources:
self.sources.append(s)
added_sources[s] = True
- elif isinstance(s, (GeneratedList, CustomTarget)):
+ elif isinstance(s, (GeneratedList, CustomTarget, CustomTargetIndex)):
self.generated.append(s)
else:
msg = 'Bad source of type {!r} in target {!r}.'.format(type(s).__name__, self.name)
@@ -1676,6 +1676,15 @@ class CustomTarget(Target):
def type_suffix(self):
return "@cus"
+ def __getitem__(self, index):
+ return CustomTargetIndex(self, self.outputs[index])
+
+ def __setitem__(self, index, value):
+ raise NotImplementedError
+
+ def __delitem__(self, index):
+ raise NotImplementedError
+
class RunTarget(Target):
def __init__(self, name, command, args, dependencies, subdir):
super().__init__(name, subdir, False)
@@ -1735,6 +1744,29 @@ class Jar(BuildTarget):
pass
+class CustomTargetIndex:
+
+ """A special opaque object returned by indexing a CustomTaget. This object
+ exists in meson, but acts as a proxy in the backends, making targets depend
+ on the CustomTarget it's derived from, but only adding one source file to
+ the sources.
+ """
+
+ def __init__(self, target, output):
+ self.target = target
+ self.output = output
+
+ def __repr__(self):
+ return '<CustomTargetIndex: {!r}[{}]>'.format(
+ self.target, self.target.output.index(self.output))
+
+ def get_outputs(self):
+ return [self.output]
+
+ def get_subdir(self):
+ return self.target.get_subdir()
+
+
class ConfigureFile:
def __init__(self, subdir, sourcename, targetname, configuration_data):