extract_objects: test and document using the result in a custom_target

QEMU would like to use the result of extract_objects in a custom_target;
examples are using objcopy, or using the object files as the key to look
up command line arguments in compile_commands.json.  This is slightly
peculiar and not covered by the test suite, but it works; in order to avoid
regressions, add a test case and document it.
pull/8900/head
Paolo Bonzini 4 years ago
parent d729ea3f69
commit a656febccf
  1. 4
      docs/markdown/Reference-manual.md
  2. 21
      test cases/common/22 object extraction/check-obj.py
  3. 6
      test cases/common/22 object extraction/meson.build

@ -2552,7 +2552,9 @@ module](#shared_module).
object files generated for those source files. This is typically used
to take single object files and link them to unit tests or to compile
some source files with custom flags. To use the object file(s)
in another build target, use the `objects:` keyword argument.
in another build target, use the [`objects:`](#executable) keyword
argument or include them in the command line of a
[`custom_target`](#custom_target)`.
- `full_path()`: returns a full path pointing to the result target file.
NOTE: In most cases using the object itself will do the same job as

@ -0,0 +1,21 @@
#! /usr/bin/env python3
import json
import sys
import os
cc = None
output = None
# Only the ninja backend produces compile_commands.json
if sys.argv[1] == 'ninja':
with open('compile_commands.json', 'r') as f:
cc = json.load(f)
output = set((x['output'] for x in cc))
for obj in sys.argv[2:]:
if not os.path.exists(obj):
sys.exit(1)
if sys.argv[1] == 'ninja' and obj not in output:
sys.exit(1)
print('Verified', obj)

@ -16,6 +16,12 @@ else
e3 = executable('main3', 'main.c', objects : obj3)
e4 = executable('main4', 'main.c', objects : obj4)
custom_target('custom_target with object inputs', output: 'objs',
input: [obj1, obj2, obj3],
build_by_default: true,
command: [find_program('check-obj.py'), meson.backend(), '@INPUT@'],
capture: true)
test('extraction test 1', e1)
test('extraction test 2', e2)
test('extraction test 3', e3)

Loading…
Cancel
Save