summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/backend/backends.py22
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--mesonbuild/backend/vs2010backend.py3
-rw-r--r--test cases/unit/131 custom target index test/meson.build16
-rw-r--r--unittests/allplatformstests.py8
5 files changed, 41 insertions, 12 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 5be2ade27..db7b5785c 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -1374,21 +1374,25 @@ class Backend:
result[name] = b
return result
- def get_testlike_targets(self, benchmark: bool = False) -> T.OrderedDict[str, T.Union[build.BuildTarget, build.CustomTarget]]:
- result: T.OrderedDict[str, T.Union[build.BuildTarget, build.CustomTarget]] = OrderedDict()
+ def get_testlike_targets(self, benchmark: bool = False) -> T.Iterable[T.Union[build.BuildTarget, build.CustomTarget]]:
targets = self.build.get_benchmarks() if benchmark else self.build.get_tests()
for t in targets:
exe = t.exe
- if isinstance(exe, (build.CustomTarget, build.BuildTarget)):
- result[exe.get_id()] = exe
+ if isinstance(exe, build.CustomTargetIndex):
+ yield exe.target
+ elif isinstance(exe, (build.CustomTarget, build.BuildTarget)):
+ yield exe
for arg in t.cmd_args:
- if not isinstance(arg, (build.CustomTarget, build.BuildTarget)):
- continue
- result[arg.get_id()] = arg
+ if isinstance(arg, build.CustomTargetIndex):
+ yield arg.target
+ elif isinstance(arg, (build.CustomTarget, build.BuildTarget)):
+ yield arg
for dep in t.depends:
assert isinstance(dep, (build.CustomTarget, build.BuildTarget, build.CustomTargetIndex))
- result[dep.get_id()] = dep
- return result
+ if isinstance(dep, build.CustomTargetIndex):
+ yield dep.target
+ else:
+ yield dep
@lru_cache(maxsize=None)
def get_custom_target_provided_by_generated_source(self, generated_source: build.CustomTarget) -> 'ImmutableListProtocol[str]':
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index ba3f1d36e..3510d19b4 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -3961,11 +3961,11 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
def generate_ending(self) -> None:
for targ, deps in [
- ('all', self.get_build_by_default_targets()),
+ ('all', self.get_build_by_default_targets().values()),
('meson-test-prereq', self.get_testlike_targets()),
('meson-benchmark-prereq', self.get_testlike_targets(True))]:
targetlist = []
- for t in deps.values():
+ for t in deps:
# Add the first output of each target to the 'all' target so that
# they are all built
#Add archive file if shared library in AIX for build all.
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index 2c79be557..9c9f61259 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -416,7 +416,8 @@ class Vs2010Backend(backends.Backend):
def generate_solution(self, sln_filename: str, projlist: T.List[Project]) -> None:
default_projlist = self.get_build_by_default_targets()
- default_projlist.update(self.get_testlike_targets())
+ for t in self.get_testlike_targets():
+ default_projlist[t.get_id()] = t
sln_filename_tmp = sln_filename + '~'
# Note using the utf-8 BOM requires the blank line, otherwise Visual Studio Version Selector fails.
# Without the BOM, VSVS fails if there is a blank line.
diff --git a/test cases/unit/131 custom target index test/meson.build b/test cases/unit/131 custom target index test/meson.build
new file mode 100644
index 000000000..adbbb4df4
--- /dev/null
+++ b/test cases/unit/131 custom target index test/meson.build
@@ -0,0 +1,16 @@
+# testcase by blue42u
+project('test')
+python3 = find_program('python3')
+
+gen_code = '''
+import sys, pathlib
+pathlib.Path(sys.argv[1]).write_text("foo")
+pathlib.Path(sys.argv[2]).write_text("bar")'''
+foobar_txt = custom_target(command: [python3, '-c', gen_code, '@OUTPUT@'], output: ['foo.txt', 'bar.txt'])
+
+test_code = '''
+import sys, pathlib
+sys.exit(0 if pathlib.Path(sys.argv[1]).read_text() == sys.argv[2] else 4)'''
+
+test('foo.txt', python3, args: ['-c', test_code, foobar_txt[0], 'foo'])
+test('bar.txt', python3, args: ['-c', test_code, foobar_txt[1], 'bar'])
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index cf3427aeb..557fe2a52 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -4471,6 +4471,14 @@ class AllPlatformTests(BasePlatformTests):
self.build()
self.run_tests()
+ def test_custom_target_index_as_test_prereq(self):
+ if self.backend is not Backend.ninja:
+ raise SkipTest('ninja backend needed for "meson test" to build test dependencies')
+
+ testdir = os.path.join(self.unit_test_dir, '131 custom target index test')
+ self.init(testdir)
+ self.run_tests()
+
@skipUnless(is_linux() and (re.search('^i.86$|^x86$|^x64$|^x86_64$|^amd64$', platform.processor()) is not None),
'Requires ASM compiler for x86 or x86_64 platform currently only available on Linux CI runners')
def test_nostdlib(self):