Skip to content

Commit 16cf71f

Browse files
committed
Handle top level options set in subprojects. Closes mesonbuild#13847.
1 parent 0b41b36 commit 16cf71f

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

mesonbuild/coredata.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,20 @@ def set_options(self, opts_to_set: T.Dict[OptionKey, T.Any], subproject: str = '
658658
elif k.machine != MachineChoice.BUILD and not self.optstore.is_compiler_option(k):
659659
unknown_options.append(k)
660660
if unknown_options:
661-
unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options))
662-
sub = f'In subproject {subproject}: ' if subproject else ''
663-
raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"')
661+
if subproject:
662+
# The subproject may have top-level options that should be used
663+
# when it is not a subproject. Ignore those for now. With option
664+
# refactor they will get per-subproject values.
665+
really_unknown = []
666+
for uo in unknown_options:
667+
topkey = uo.evolve(subproject='')
668+
if topkey not in self.optstore:
669+
really_unknown.append(uo)
670+
unknown_options = really_unknown
671+
if unknown_options:
672+
unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options))
673+
sub = f'In subproject {subproject}: ' if subproject else ''
674+
raise MesonException(f'{sub}Unknown options: "{unknown_options_str}"')
664675

665676
if not self.is_cross_build():
666677
dirty |= self.copy_build_options_from_regular_ones()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project('pkg_opt_test')
2+
3+
subproject('sub')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project('subproject', default_options: 'pkgconfig.relocatable=true')

unittests/linuxliketests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,3 +1863,7 @@ def test_complex_link_cases(self):
18631863
self.assertIn('build t9-e1: c_LINKER t9-e1.p/main.c.o | libt9-s1.a libt9-s2.a libt9-s3.a\n', content)
18641864
self.assertIn('build t12-e1: c_LINKER t12-e1.p/main.c.o | libt12-s1.a libt12-s2.a libt12-s3.a\n', content)
18651865
self.assertIn('build t13-e1: c_LINKER t13-e1.p/main.c.o | libt12-s1.a libt13-s3.a\n', content)
1866+
1867+
def test_top_options_in_sp(self):
1868+
testdir = os.path.join(self.unit_test_dir, '123 pkgsubproj')
1869+
self.init(testdir)

0 commit comments

Comments
 (0)