Skip to content

Commit

Permalink
subproject: Fix inheritance of language options
Browse files Browse the repository at this point in the history
Add handling of language args for subprojects, which was
previously only done for the main project as part of the detection
of the language compiler.

Language options were deferred for later handling during
language load. This caused default language options to break for
subprojects which were missing this loading step due to the
language compiler already being present.

Resolves #13260.

Signed-off-by: Eyal Itkin <eyal.itkin@gmail.com>
  • Loading branch information
Eyal Itkin committed Nov 22, 2024
1 parent 9f3f88f commit d4731b2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _add_languages(self, raw_langs: T.List[TYPE_var], required: bool, for_machin
v = copy.copy(self.coredata.optstore.get_value_object(k))
k = k.evolve(subproject=self.subproject)
options[k] = v
self.coredata.add_compiler_options(options, lang, for_machine, self.environment, self.subproject)
self.coredata.add_compiler_options(options, for_machine, self.environment, self.subproject)

def func_dependency(self, node: BaseNode, args: T.List[TYPE_var], kwargs: T.Dict[str, TYPE_var]) -> None:
args = self.flatten_args(args)
Expand Down
10 changes: 8 additions & 2 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def set_default_options(self, default_options: T.MutableMapping[OptionKey, str],

self.set_options(options, subproject=subproject, first_invocation=env.first_invocation)

def add_compiler_options(self, c_options: MutableKeyedOptionDictType, lang: str, for_machine: MachineChoice,
def add_compiler_options(self, c_options: MutableKeyedOptionDictType, for_machine: MachineChoice,
env: Environment, subproject: str) -> None:
for k, o in c_options.items():
value = env.options.get(k)
Expand Down Expand Up @@ -741,7 +741,13 @@ def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
def process_compiler_options(self, lang: str, comp: Compiler, env: Environment, subproject: str) -> None:
from . import compilers

self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env, subproject)
# Need to add language-related options for subprojects, as they aren't covered by the
# addition of the language, which is only done for the main project
if subproject:
lang_options = compilers.compilers.get_global_options(lang, comp, comp.for_machine, env)
self.add_compiler_options(lang_options, comp.for_machine, env, subproject)

self.add_compiler_options(comp.get_options(), comp.for_machine, env, subproject)

enabled_opts: T.List[OptionKey] = []
for key in comp.base_options:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
v = copy.copy(self.coredata.optstore.get_value_object(k))
k = k.evolve(subproject=self.subproject)
options[k] = v
self.coredata.add_compiler_options(options, lang, for_machine, self.environment, self.subproject)
self.coredata.add_compiler_options(options, for_machine, self.environment, self.subproject)

if for_machine == MachineChoice.HOST or self.environment.is_cross_build():
logger_fun = mlog.log
Expand Down
4 changes: 3 additions & 1 deletion test cases/common/87 default options/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ assert(w_level == '3', 'warning level "' + w_level + '" instead of "3"')
# assert(cc.compiles('int foobar;', no_builtin_args : true), 'No_builtin did not disable builtins.')
# endif

subproject('sub1')
subproject('sub1', default_options : [
'c_args=-Dtest',
])
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
project('sub1')
project('sub1', 'c')

assert(get_option('test_option') == false)
assert(get_option('c_args') == ['-Dtest'])
13 changes: 7 additions & 6 deletions unittests/machinefiletests.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,20 +523,21 @@ def test_builtin_options_subprojects(self):

self.init(testcase, extra_args=['--native-file', config])
configuration = self.introspect('--buildoptions')
found = 0
score = 0
for each in configuration:
# Test that no-per subproject options are inherited from the parent
# while the rest of the options are inherited as-is
if 'c_args' in each['name']:
# This path will be hit twice, once for build and once for host,
# This path will be hit twice per project: for build and for host
self.assertEqual(each['value'], ['-Dfoo'])
found += 1
score += 1
elif each['name'] == 'default_library':
self.assertEqual(each['value'], 'both')
found += 1
score += 10
elif each['name'] == 'sub:default_library':
self.assertEqual(each['value'], 'static')
found += 1
self.assertEqual(found, 4, 'Did not find all three sections')
score += 100
self.assertEqual(score, 118, 'Did not find all three sections')

def test_builtin_options_subprojects_overrides_buildfiles(self):
# If the buildfile says subproject(... default_library: shared), ensure that's overwritten
Expand Down

0 comments on commit d4731b2

Please sign in to comment.