From 37a962e90c38f094819973d5d45fa25054caa1ca Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Tue, 19 Feb 2019 01:10:35 +0100 Subject: [PATCH] Allow File arguments in extract_objects() arguments Passed strings are converted to Files, but passing a File directly wasn't supported yet. --- docs/markdown/snippets/extract_objects-file-arg.md | 4 ++++ mesonbuild/build.py | 9 ++++++--- test cases/common/23 object extraction/meson.build | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 docs/markdown/snippets/extract_objects-file-arg.md diff --git a/docs/markdown/snippets/extract_objects-file-arg.md b/docs/markdown/snippets/extract_objects-file-arg.md new file mode 100644 index 000000000..eff9a5492 --- /dev/null +++ b/docs/markdown/snippets/extract_objects-file-arg.md @@ -0,0 +1,4 @@ +## `extract_objects` accepts `File` arguments + +The `extract_objects` function now supports File objects to tell it +what to extract. Previously, file paths could only be passed as strings. diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 702b338da..e8aa8f418 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -722,9 +722,12 @@ class BuildTarget(Target): def extract_objects(self, srclist): obj_src = [] for src in srclist: - if not isinstance(src, str): - raise MesonException('Object extraction arguments must be strings.') - src = File(False, self.subdir, src) + if isinstance(src, str): + src = File(False, self.subdir, src) + elif isinstance(src, File): + FeatureNew('File argument for extract_objects', '0.50.0').use(self.subproject) + else: + raise MesonException('Object extraction arguments must be strings or Files.') # FIXME: It could be a generated source if src not in self.sources: raise MesonException('Tried to extract unknown source %s.' % src) diff --git a/test cases/common/23 object extraction/meson.build b/test cases/common/23 object extraction/meson.build index d99ec8444..6776b1412 100644 --- a/test cases/common/23 object extraction/meson.build +++ b/test cases/common/23 object extraction/meson.build @@ -8,10 +8,13 @@ else obj1 = lib1.extract_objects('src/lib.c') obj2 = lib2.extract_objects(['lib.c']) + obj3 = lib2.extract_objects(files('lib.c')) e1 = executable('main1', 'main.c', objects : obj1) e2 = executable('main2', 'main.c', objects : obj2) + e3 = executable('main3', 'main.c', objects : obj3) test('extraction test 1', e1) test('extraction test 2', e2) + test('extraction test 3', e3) endif