summaryrefslogtreecommitdiffstats
path: root/test cases/common/22 object extraction
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/common/22 object extraction')
-rw-r--r--test cases/common/22 object extraction/check-obj.py21
-rw-r--r--test cases/common/22 object extraction/create-source.py3
-rw-r--r--test cases/common/22 object extraction/header.h1
-rw-r--r--test cases/common/22 object extraction/lib.c3
-rw-r--r--test cases/common/22 object extraction/lib2.c3
-rw-r--r--test cases/common/22 object extraction/main.c5
-rw-r--r--test cases/common/22 object extraction/meson.build50
-rw-r--r--test cases/common/22 object extraction/src/lib.c3
8 files changed, 89 insertions, 0 deletions
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..d6afbcc
--- /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') as f:
+ cc = json.load(f)
+ output = {x['output'] for x in cc}
+
+for obj in sys.argv[2:]:
+ if not os.path.exists(obj):
+ sys.exit(f'File {obj} not found.')
+ 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/create-source.py b/test cases/common/22 object extraction/create-source.py
new file mode 100644
index 0000000..d2e8e8b
--- /dev/null
+++ b/test cases/common/22 object extraction/create-source.py
@@ -0,0 +1,3 @@
+#! /usr/bin/env python3
+import sys
+print(f'#include "{sys.argv[1]}"')
diff --git a/test cases/common/22 object extraction/header.h b/test cases/common/22 object extraction/header.h
new file mode 100644
index 0000000..50403ce
--- /dev/null
+++ b/test cases/common/22 object extraction/header.h
@@ -0,0 +1 @@
+/* Check that extract_all_objects works with headers. */
diff --git a/test cases/common/22 object extraction/lib.c b/test cases/common/22 object extraction/lib.c
new file mode 100644
index 0000000..8180551
--- /dev/null
+++ b/test cases/common/22 object extraction/lib.c
@@ -0,0 +1,3 @@
+int func(void) {
+ return 42;
+}
diff --git a/test cases/common/22 object extraction/lib2.c b/test cases/common/22 object extraction/lib2.c
new file mode 100644
index 0000000..5020593
--- /dev/null
+++ b/test cases/common/22 object extraction/lib2.c
@@ -0,0 +1,3 @@
+int retval(void) {
+ return 43;
+}
diff --git a/test cases/common/22 object extraction/main.c b/test cases/common/22 object extraction/main.c
new file mode 100644
index 0000000..27162c5
--- /dev/null
+++ b/test cases/common/22 object extraction/main.c
@@ -0,0 +1,5 @@
+int func(void);
+
+int main(void) {
+ return func() == 42 ? 0 : 1;
+}
diff --git a/test cases/common/22 object extraction/meson.build b/test cases/common/22 object extraction/meson.build
new file mode 100644
index 0000000..37ac66d
--- /dev/null
+++ b/test cases/common/22 object extraction/meson.build
@@ -0,0 +1,50 @@
+project('object extraction', 'c')
+
+if meson.is_unity()
+ message('Skipping extraction test because this is a Unity build.')
+else
+ lib1 = library('somelib', 'src/lib.c')
+ lib2 = library('somelib2', 'lib.c', 'header.h', 'lib2.c')
+
+ obj1 = lib1.extract_objects('src/lib.c')
+ obj2 = lib2.extract_objects(['lib.c'])
+ obj3 = lib2.extract_objects(files('lib.c'))
+ obj4 = lib2.extract_objects(['lib.c', 'lib.c'])
+ obj5 = lib2.extract_objects(['lib.c', 'header.h'])
+ obj6 = lib2.extract_all_objects(recursive: true)
+
+ e1 = executable('main1', 'main.c', objects : obj1)
+ e2 = executable('main2', 'main.c', objects : obj2)
+ e3 = executable('main3', 'main.c', objects : obj3)
+ e4 = executable('main4', 'main.c', objects : obj4)
+ e5 = executable('main5', 'main.c', objects : obj5)
+ e6 = executable('main6', 'main.c', objects : obj6)
+
+ ct_src = custom_target('lib3.c', output: 'lib3.c', capture: true,
+ command: [find_program('create-source.py'), 'lib.c'])
+ lib3 = library('somelib3', ct_src)
+ e7 = executable('main7', 'main.c', objects: lib3.extract_objects(ct_src[0]))
+ e8 = executable('main8', 'main.c', objects: lib3.extract_objects(ct_src))
+
+ gen = generator(find_program('create-source.py'), arguments: ['@INPUT@'],
+ output: '@BASENAME@4.c', capture: true)
+ gen_src = gen.process('lib.c')
+ lib4 = library('somelib4', gen_src)
+ e9 = executable('main9', 'main.c', objects: lib4.extract_objects(gen_src))
+
+ custom_target('custom_target with object inputs', output: 'objs',
+ input: [obj1, obj2, obj3, obj5, obj6],
+ 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)
+ test('extraction test 4', e4)
+ test('extraction test 5', e5)
+ test('extraction test 6', e6)
+ test('extraction test 7', e7)
+ test('extraction test 8', e8)
+ test('extraction test 9', e9)
+endif
diff --git a/test cases/common/22 object extraction/src/lib.c b/test cases/common/22 object extraction/src/lib.c
new file mode 100644
index 0000000..8180551
--- /dev/null
+++ b/test cases/common/22 object extraction/src/lib.c
@@ -0,0 +1,3 @@
+int func(void) {
+ return 42;
+}