Skip to content

Commit

Permalink
coredata: Allow setting suproject options from the default_options of
Browse files Browse the repository at this point in the history
the superproject

This only allows the super project to do this, and not for subprojects
to affect each other, as that would create race conditions and just be
really difficult to make work without a two pass interpreter. This
should probably be deprecated in favor of the default_options argument
to subproject() anyway.

Fixes mesonbuild#7573
  • Loading branch information
dcbaker authored and Ericson2314 committed Oct 6, 2020
1 parent 8fee22e commit 4d8438c
Show file tree
Hide file tree
Showing 3 changed files with 16 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 @@ -779,7 +779,9 @@ def make_key(key: str) -> str:
# split arguments that can be set now, and those that cannot so they
# can be set later, when they've been initialized.
for k, v in default_options.items():
if k.startswith(lang_prefixes):
if ':' in k:
continue
elif k.startswith(lang_prefixes):
lang, key = k.split('_', 1)
for machine in MachineChoice:
if key not in env.compiler_options[machine][lang]:
Expand Down Expand Up @@ -808,11 +810,20 @@ def make_key(key: str) -> str:
for k, v in default_options.items():
if k in BUILTIN_OPTIONS and not BUILTIN_OPTIONS[k].yielding:
continue

subp = subproject
if ':' in k:
# We don't honor subproject options from one subproject to
# another, only from the superproject
if subproject:
continue

subp, k = k.split(':')
for machine in MachineChoice:
if machine is MachineChoice.BUILD and not self.is_cross_build():
continue
if k not in env.meson_options[machine][subproject]:
env.meson_options[machine][subproject][k] = v
if k not in env.meson_options[machine][subp]:
env.meson_options[machine][subp][k] = v

self.set_options(options, subproject=subproject)

Expand Down
1 change: 1 addition & 0 deletions test cases/common/230 persubproject options/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project('persubproject options', 'c',
default_options : ['default_library=both',
'werror=true',
'sub1:werror=false',
'warning_level=3'])

assert(get_option('default_library') == 'both', 'Parent default_library should be "both"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project('sub1', 'c',

assert(get_option('default_library') == 'both', 'Should inherit parent project default_library')
assert(get_option('warning_level') == '0')
assert(get_option('werror') == false)

# Check it build both by calling a method only both_libraries target implement
lib = library('lib1', 'foo.c')
Expand Down

0 comments on commit 4d8438c

Please sign in to comment.