aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2024-12-16 13:29:15 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2024-12-16 13:29:15 +0200
commite32987981f81ca875a45bae001110ccc60c91c12 (patch)
treea7ddeb764859571901b4dea02e8583fc4e9d80b9
parent0b41b364be716064285928c00330d1fc6b07cd88 (diff)
downloadmeson-optstorefix.zip
meson-optstorefix.tar.gz
meson-optstorefix.tar.bz2
Handle top level options set in subprojects. Closes #13847.optstorefix
-rw-r--r--mesonbuild/coredata.py17
-rw-r--r--test cases/unit/123 pkgsubproj/meson.build3
-rw-r--r--test cases/unit/123 pkgsubproj/subprojects/sub/meson.build1
-rw-r--r--unittests/linuxliketests.py5
4 files changed, 23 insertions, 3 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 98656b2..8576ace 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -658,9 +658,20 @@ class CoreData:
elif k.machine != MachineChoice.BUILD and not self.optstore.is_compiler_option(k):
unknown_options.append(k)
if unknown_options:
- unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options))
- sub = f'In subproject {subproject}: ' if subproject else ''
- raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"')
+ if subproject:
+ # The subproject may have top-level options that should be used
+ # when it not a subproject. Ignore those for now. With option
+ # refactor they will get per-subproject values.
+ really_unknown = []
+ for uo in unknown_options:
+ topkey = uo.evolve(subproject='')
+ if topkey not in self.optstore:
+ really_unknown.append(uo)
+ unknown_options = really_unknown
+ if unknown_options:
+ unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options))
+ sub = f'In subproject {subproject}: ' if subproject else ''
+ raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"')
if not self.is_cross_build():
dirty |= self.copy_build_options_from_regular_ones()
diff --git a/test cases/unit/123 pkgsubproj/meson.build b/test cases/unit/123 pkgsubproj/meson.build
new file mode 100644
index 0000000..6075949
--- /dev/null
+++ b/test cases/unit/123 pkgsubproj/meson.build
@@ -0,0 +1,3 @@
+project('pkg_opt_test', 'c')
+
+subproject('sub')
diff --git a/test cases/unit/123 pkgsubproj/subprojects/sub/meson.build b/test cases/unit/123 pkgsubproj/subprojects/sub/meson.build
new file mode 100644
index 0000000..e0217df
--- /dev/null
+++ b/test cases/unit/123 pkgsubproj/subprojects/sub/meson.build
@@ -0,0 +1 @@
+project('subproject', 'c', default_options: 'pkgconfig.relocatable=true')
diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py
index 1e9e38d..adc6033 100644
--- a/unittests/linuxliketests.py
+++ b/unittests/linuxliketests.py
@@ -1863,3 +1863,8 @@ class LinuxlikeTests(BasePlatformTests):
self.assertIn('build t9-e1: c_LINKER t9-e1.p/main.c.o | libt9-s1.a libt9-s2.a libt9-s3.a\n', content)
self.assertIn('build t12-e1: c_LINKER t12-e1.p/main.c.o | libt12-s1.a libt12-s2.a libt12-s3.a\n', content)
self.assertIn('build t13-e1: c_LINKER t13-e1.p/main.c.o | libt12-s1.a libt13-s3.a\n', content)
+
+ def test_sp_options(self):
+ testdir = os.path.join(self.unit_test_dir, '123 pkgsubproj')
+ self.init(testdir)
+