aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Reference-manual.md6
-rw-r--r--mesonbuild/build.py4
-rw-r--r--mesonbuild/interpreter.py27
-rw-r--r--test cases/common/144 custom target multiple outputs/meson.build13
4 files changed, 44 insertions, 6 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 57fc1f7..e3830cc 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -2299,6 +2299,8 @@ contains a target with the following methods:
NOTE: In most cases using the object itself will do the same job as
this and will also allow Meson to setup inter-target dependencies
correctly. Please file a bug if that doesn't work for you.
+ *Since 0.54.0* it can be also called on indexes objects:
+ `custom_targets[i].full_path()`.
- `[index]` returns an opaque object that references this target, and
can be used as a source in other targets. When it is used as such it
@@ -2306,6 +2308,10 @@ contains a target with the following methods:
source added will be the one that corresponds to the index of the
custom target's output argument.
+- `to_list()` *Since 0.54.0*, returns a list of opaque objects that references
+ this target, and can be used as a source in other targets. This can be used to
+ iterate outputs with `foreach` loop.
+
### `dependency` object
This object is returned by [`dependency()`](#dependency) and contains
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 1db930e..0a8ca45 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -2250,6 +2250,10 @@ class CustomTarget(Target):
def __delitem__(self, index):
raise NotImplementedError
+ def __iter__(self):
+ for i in self.outputs:
+ yield CustomTargetIndex(self, i)
+
class RunTarget(Target):
def __init__(self, name, command, args, dependencies, subdir, subproject):
self.typename = 'run'
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 0d87bab..e32e0a1 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -871,15 +871,23 @@ class JarHolder(BuildTargetHolder):
def __init__(self, target, interp):
super().__init__(target, interp)
-class CustomTargetIndexHolder(InterpreterObject, ObjectHolder):
- def __init__(self, object_to_hold):
- InterpreterObject.__init__(self)
- ObjectHolder.__init__(self, object_to_hold)
+class CustomTargetIndexHolder(TargetHolder):
+ def __init__(self, target, interp):
+ super().__init__(target, interp)
+ self.methods.update({'full_path': self.full_path_method,
+ })
+
+ @FeatureNew('custom_target[i].full_path', '0.54.0')
+ @noPosargs
+ @permittedKwargs({})
+ def full_path_method(self, args, kwargs):
+ return self.interpreter.backend.get_target_filename_abs(self.held_object)
class CustomTargetHolder(TargetHolder):
def __init__(self, target, interp):
super().__init__(target, interp)
self.methods.update({'full_path': self.full_path_method,
+ 'to_list': self.to_list_method,
})
def __repr__(self):
@@ -892,8 +900,17 @@ class CustomTargetHolder(TargetHolder):
def full_path_method(self, args, kwargs):
return self.interpreter.backend.get_target_filename_abs(self.held_object)
+ @FeatureNew('custom_target.to_list', '0.54.0')
+ @noPosargs
+ @permittedKwargs({})
+ def to_list_method(self, args, kwargs):
+ result = []
+ for i in self.held_object:
+ result.append(CustomTargetIndexHolder(i, self.interpreter))
+ return result
+
def __getitem__(self, index):
- return CustomTargetIndexHolder(self.held_object[index])
+ return CustomTargetIndexHolder(self.held_object[index], self.interpreter)
def __setitem__(self, index, value): # lgtm[py/unexpected-raise-in-special-method]
raise InterpreterException('Cannot set a member of a CustomTarget')
diff --git a/test cases/common/144 custom target multiple outputs/meson.build b/test cases/common/144 custom target multiple outputs/meson.build
index 6412864..382c9b2 100644
--- a/test cases/common/144 custom target multiple outputs/meson.build
+++ b/test cases/common/144 custom target multiple outputs/meson.build
@@ -21,8 +21,19 @@ custom_target('only-install-first',
install : true,
install_dir : [join_paths(get_option('prefix'), get_option('includedir')), false])
-custom_target('only-install-second',
+targets = custom_target('only-install-second',
output : ['second.h', 'second.sh'],
command : [gen, 'second', '@OUTDIR@'],
install : true,
install_dir : [false, join_paths(get_option('prefix'), get_option('bindir'))])
+
+paths = []
+foreach i : targets.to_list()
+ paths += i.full_path()
+endforeach
+
+# Skip on Windows because paths are not identical, '/' VS '\'.
+if host_machine.system() != 'windows'
+ assert(paths == [meson.current_build_dir() / 'second.h',
+ meson.current_build_dir() / 'second.sh'])
+endif