introspection: export all sources for custom targets

Also adds some test cases for source files in target_sources.
pull/8701/head
Jason Francis 4 years ago committed by Jussi Pakkanen
parent bb12587e0b
commit 39c751b94c
  1. 2
      mesonbuild/backend/backends.py
  2. 26
      run_unittests.py
  3. 11
      test cases/unit/57 introspection/meson.build

@ -1523,6 +1523,8 @@ class Backend:
source_list += [j.absolute_path(self.source_dir, self.build_dir)]
elif isinstance(j, str):
source_list += [os.path.join(self.source_dir, j)]
elif isinstance(j, (build.CustomTarget, build.BuildTarget)):
source_list += [os.path.join(self.build_dir, j.get_subdir(), o) for o in j.get_outputs()]
source_list = list(map(lambda x: os.path.normpath(x), source_list))
compiler = []

@ -4678,10 +4678,12 @@ class AllPlatformTests(BasePlatformTests):
# Match target ids to input and output files for ease of reference
src_to_id = {}
out_to_id = {}
name_to_out = {}
for i in res['targets']:
print(json.dump(i, sys.stdout))
out_to_id.update({os.path.relpath(out, self.builddir): i['id']
for out in i['filename']})
name_to_out.update({i['name']: i['filename']})
for group in i['target_sources']:
src_to_id.update({os.path.relpath(src, testdir): i['id']
for src in group['sources']})
@ -4690,7 +4692,7 @@ class AllPlatformTests(BasePlatformTests):
tests_to_find = ['test case 1', 'test case 2', 'benchmark 1']
deps_to_find = {'test case 1': [src_to_id['t1.cpp']],
'test case 2': [src_to_id['t2.cpp'], src_to_id['t3.cpp']],
'benchmark 1': [out_to_id['file2'], src_to_id['t3.cpp']]}
'benchmark 1': [out_to_id['file2'], out_to_id['file3'], out_to_id['file4'], src_to_id['t3.cpp']]}
for i in res['benchmarks'] + res['tests']:
assertKeyTypes(test_keylist, i)
if i['name'] in tests_to_find:
@ -4737,11 +4739,22 @@ class AllPlatformTests(BasePlatformTests):
# Check targets
targets_to_find = {
'sharedTestLib': ('shared library', True, False, 'sharedlib/meson.build'),
'staticTestLib': ('static library', True, False, 'staticlib/meson.build'),
'test1': ('executable', True, True, 'meson.build'),
'test2': ('executable', True, False, 'meson.build'),
'test3': ('executable', True, False, 'meson.build'),
'sharedTestLib': ('shared library', True, False, 'sharedlib/meson.build',
[os.path.join(testdir, 'sharedlib', 'shared.cpp')]),
'staticTestLib': ('static library', True, False, 'staticlib/meson.build',
[os.path.join(testdir, 'staticlib', 'static.c')]),
'custom target test 1': ('custom', False, False, 'meson.build',
[os.path.join(testdir, 'cp.py')]),
'custom target test 2': ('custom', False, False, 'meson.build',
name_to_out['custom target test 1']),
'test1': ('executable', True, True, 'meson.build',
[os.path.join(testdir, 't1.cpp')]),
'test2': ('executable', True, False, 'meson.build',
[os.path.join(testdir, 't2.cpp')]),
'test3': ('executable', True, False, 'meson.build',
[os.path.join(testdir, 't3.cpp')]),
'custom target test 3': ('custom', False, False, 'meson.build',
name_to_out['test3']),
}
for i in res['targets']:
assertKeyTypes(targets_typelist, i)
@ -4754,6 +4767,7 @@ class AllPlatformTests(BasePlatformTests):
targets_to_find.pop(i['name'], None)
for j in i['target_sources']:
assertKeyTypes(targets_sources_typelist, j)
self.assertEqual(j['sources'], [os.path.normpath(f) for f in tgt[4]])
self.assertDictEqual(targets_to_find, {})
def test_introspect_file_dump_equals_all(self):

@ -27,13 +27,18 @@ var1 = '1'
var2 = 2.to_string()
var3 = 'test3'
cus = custom_target('custom target test', output: 'file2', input: 'cp.py',
command: [find_program('cp.py'), '@INPUT@', '@OUTPUT@'])
cus1 = custom_target('custom target test 1', output: 'file2', input: 'cp.py',
command: [find_program('cp.py'), '@INPUT@', '@OUTPUT@'])
cus2 = custom_target('custom target test 2', output: 'file3', input: cus1,
command: [find_program('cp.py'), '@INPUT@', '@OUTPUT@'])
t1 = executable('test' + var1, ['t1.cpp'], link_with: [sharedlib], install: not false, build_by_default: get_option('test_opt2'))
t2 = executable('test@0@'.format('@0@'.format(var2)), sources: ['t2.cpp'], link_with: [staticlib])
t3 = executable(var3, 't3.cpp', link_with: [sharedlib, staticlib], dependencies: [dep1])
cus3 = custom_target('custom target test 3', output: 'file4', input: t3,
command: [find_program('cp.py'), '@INPUT@', '@OUTPUT@'])
### BEGIN: Test inspired by taisei: https://github.com/taisei-project/taisei/blob/master/meson.build#L293
systype = '@0@'.format(host_machine.system())
systype = '@0@, @1@, @2@'.format(systype, host_machine.cpu_family(), host_machine.cpu())
@ -49,7 +54,7 @@ message(osmesa_lib_name) # Infinite recursion gets triggered here when the param
test('test case 1', t1)
test('test case 2', t2, depends: t3)
benchmark('benchmark 1', t3, args: cus)
benchmark('benchmark 1', t3, args: [cus1, cus2, cus3])
### Stuff to test the AST JSON printer
foreach x : ['a', 'b', 'c']

Loading…
Cancel
Save