aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2022-12-19 13:31:40 +0100
committerDylan Baker <dylan@pnwbakers.com>2023-01-04 09:44:32 -0800
commit8d2940024bd16919bf7772334dd0048604abecfb (patch)
treeea1e632bf53aa68b7328cf4dcb120a1e51969553
parent5ef824b2f3649bde1239d4b23c2bd20ecea795cf (diff)
downloadmeson-8d2940024bd16919bf7772334dd0048604abecfb.zip
meson-8d2940024bd16919bf7772334dd0048604abecfb.tar.gz
meson-8d2940024bd16919bf7772334dd0048604abecfb.tar.bz2
allow passing generated objects in the "objects" keyword argument
Generated objects can already be passed in the "objects" keyword argument as long as you go through an extract_objects() indirection. Allow the same even directly, since that is more intuitive than having to add them to "sources". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--docs/markdown/snippets/gen_objects.md6
-rw-r--r--docs/yaml/functions/_build_target_base.yaml7
-rw-r--r--mesonbuild/build.py11
-rw-r--r--test cases/unit/15 prebuilt object/meson.build6
4 files changed, 22 insertions, 8 deletions
diff --git a/docs/markdown/snippets/gen_objects.md b/docs/markdown/snippets/gen_objects.md
new file mode 100644
index 0000000..fecd701
--- /dev/null
+++ b/docs/markdown/snippets/gen_objects.md
@@ -0,0 +1,6 @@
+## Generated objects can be passed in the `objects:` keyword argument
+
+In previous versions of Meson, generated objects could only be
+passed as sources of a build target. This was confusing, therefore
+generated objects can now be passed in the `objects:` keyword
+argument as well.
diff --git a/docs/yaml/functions/_build_target_base.yaml b/docs/yaml/functions/_build_target_base.yaml
index 46eedc1..767c4da 100644
--- a/docs/yaml/functions/_build_target_base.yaml
+++ b/docs/yaml/functions/_build_target_base.yaml
@@ -194,8 +194,11 @@ kwargs:
type: list[extracted_obj | file | str]
description: |
List of object files that should be linked in this target.
- These can include third party products you don't have source to,
- or object files produced by other build targets.
+
+ **Since 1.1.0** this can include generated files in addition to
+ object files that you don't have source to or that object files
+ produced by other build targets. In earlier release, generated
+ object files had to be placed in `sources`.
name_prefix:
type: str | list[void]
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index db2c309..9d55bf9 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -777,12 +777,11 @@ class BuildTarget(Target):
for s in objects:
if isinstance(s, (str, File, ExtractedObjects)):
self.objects.append(s)
- elif isinstance(s, (GeneratedList, CustomTarget)):
- msg = 'Generated files are not allowed in the \'objects\' kwarg ' + \
- f'for target {self.name!r}.\nIt is meant only for ' + \
- 'pre-built object files that are shipped with the\nsource ' + \
- 'tree. Try adding it in the list of sources.'
- raise InvalidArguments(msg)
+ elif isinstance(s, (CustomTarget, CustomTargetIndex, GeneratedList)):
+ non_objects = [o for o in s.get_outputs() if not is_object(o)]
+ if non_objects:
+ raise InvalidArguments(f'Generated file {non_objects[0]} in the \'objects\' kwarg is not an object.')
+ self.generated.append(s)
else:
raise InvalidArguments(f'Bad object of type {type(s).__name__!r} in target {self.name!r}.')
diff --git a/test cases/unit/15 prebuilt object/meson.build b/test cases/unit/15 prebuilt object/meson.build
index b542d1c..81aa2ae 100644
--- a/test cases/unit/15 prebuilt object/meson.build
+++ b/test cases/unit/15 prebuilt object/meson.build
@@ -35,6 +35,12 @@ e += executable('exe5', 'main.c', ct[0])
sl2 = static_library('lib6', sources: ct)
e += executable('exe6', sources: 'main.c', objects: sl2.extract_all_objects(recursive: true))
+e += executable('exe7', sources: 'main.c', objects: ct)
+e += executable('exe8', sources: 'main.c', objects: ct[0])
+
+sl3 = static_library('lib9', objects: ct)
+e += executable('exe9', sources: 'main.c', objects: sl2.extract_all_objects(recursive: true))
+
foreach i : e
test(i.name(), i)
endforeach