aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-06-18 18:06:03 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-06-22 10:40:38 +0200
commita656febccf6614008086bf124858826615924df7 (patch)
tree53a896814e6e6055a45570be90a003aa76e48d76
parentd729ea3f6936dd7ea68a41cf178ee6a9afcf0ddd (diff)
downloadmeson-a656febccf6614008086bf124858826615924df7.zip
meson-a656febccf6614008086bf124858826615924df7.tar.gz
meson-a656febccf6614008086bf124858826615924df7.tar.bz2
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.
-rw-r--r--docs/markdown/Reference-manual.md4
-rw-r--r--test cases/common/22 object extraction/check-obj.py21
-rw-r--r--test cases/common/22 object extraction/meson.build6
3 files changed, 30 insertions, 1 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 18f30b3..f3f87cc 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -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
diff --git a/test cases/common/22 object extraction/check-obj.py b/test cases/common/22 object extraction/check-obj.py
new file mode 100644
index 0000000..99c2cc5
--- /dev/null
+++ b/test cases/common/22 object extraction/check-obj.py
@@ -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)
diff --git a/test cases/common/22 object extraction/meson.build b/test cases/common/22 object extraction/meson.build
index 18be1db..407c5e8 100644
--- a/test cases/common/22 object extraction/meson.build
+++ b/test cases/common/22 object extraction/meson.build
@@ -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)