Skip to content

Commit

Permalink
Handle top level options set in subprojects. Closes #13847.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Dec 16, 2024
1 parent 0b41b36 commit e329879
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,20 @@ def set_options(self, opts_to_set: T.Dict[OptionKey, T.Any], subproject: str = '
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()
Expand Down
3 changes: 3 additions & 0 deletions test cases/unit/123 pkgsubproj/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project('pkg_opt_test', 'c')

subproject('sub')
1 change: 1 addition & 0 deletions test cases/unit/123 pkgsubproj/subprojects/sub/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project('subproject', 'c', default_options: 'pkgconfig.relocatable=true')
5 changes: 5 additions & 0 deletions unittests/linuxliketests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1863,3 +1863,8 @@ def test_complex_link_cases(self):
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)

0 comments on commit e329879

Please sign in to comment.