Skip to content

Commit

Permalink
Fix unknown compiler options not detected in commandline arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
bruchar1 committed Feb 28, 2024
1 parent 3e65171 commit f92e06f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _add_languages(self, raw_langs: T.List[TYPE_var], required: bool, for_machin
v = copy.copy(self.coredata.options[k])
k = k.evolve(subproject=self.subproject)
options[k] = v
self.coredata.add_compiler_options(options, lang, for_machine, self.environment)
self.coredata.add_compiler_options(options, lang, 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
2 changes: 1 addition & 1 deletion mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic
if comp is None:
return comp
assert comp.for_machine == for_machine
env.coredata.process_compiler_options(lang, comp, env)
env.coredata.process_compiler_options(lang, comp, env, '')
if not skip_sanity_check:
comp.sanity_check(env.get_scratch_dir(), env)
env.coredata.compilers[comp.for_machine][lang] = comp
Expand Down
22 changes: 18 additions & 4 deletions mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,29 @@ 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, options: 'MutableKeyedOptionDictType', lang: str, for_machine: MachineChoice,
env: 'Environment') -> None:
def add_compiler_options(self, options: MutableKeyedOptionDictType, lang: str, for_machine: MachineChoice,
env: Environment, subproject: str) -> None:
for k, o in options.items():
value = env.options.get(k)
if value is not None:
o.set_value(value)
self.options[k] = o # override compiler option on reconfigure
self.options.setdefault(k, o)

if subproject:
k = k.evolve(subproject=subproject)
if k in env.options:
self.options[k] = o

unknown_options: T.List[OptionKey] = []
for k in env.options:
if k.lang == lang and k.subproject == subproject and k.evolve(subproject='') not in self.options:
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}"')

def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
for_machine: MachineChoice, env: 'Environment') -> None:
"""Add global language arguments that are needed before compiler/linker detection."""
Expand All @@ -1034,10 +1048,10 @@ def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
# `self.options.update()`` is perfectly safe.
self.options.update(compilers.get_global_options(lang, comp, for_machine, env))

def process_compiler_options(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
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)
self.add_compiler_options(comp.get_options(), lang, comp.for_machine, env, subproject)

enabled_opts: T.List[OptionKey] = []
for key in comp.base_options:
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
raise
else:
# update new values from commandline, if it applies
self.coredata.process_compiler_options(lang, comp, self.environment)
self.coredata.process_compiler_options(lang, comp, self.environment, self.subproject)

# Add per-subproject compiler options. They inherit value from main project.
if self.subproject:
Expand All @@ -1529,7 +1529,7 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
v = copy.copy(self.coredata.options[k])
k = k.evolve(subproject=self.subproject)
options[k] = v
self.coredata.add_compiler_options(options, lang, for_machine, self.environment)
self.coredata.add_compiler_options(options, lang, for_machine, self.environment, self.subproject)

if for_machine == MachineChoice.HOST or self.environment.is_cross_build():
logger_fun = mlog.log
Expand Down
2 changes: 1 addition & 1 deletion run_project_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def have_working_compiler(lang: str, use_tmp: bool) -> bool:
return False
if not compiler:
return False
env.coredata.process_compiler_options(lang, compiler, env)
env.coredata.process_compiler_options(lang, compiler, env, '')
try:
compiler.sanity_check(env.get_scratch_dir(), env)
except mesonlib.MesonException:
Expand Down
2 changes: 1 addition & 1 deletion unittests/platformagnostictests.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ def test_reconfigure_base_options(self):
def test_setup_with_unknown_option(self):
testdir = os.path.join(self.common_test_dir, '1 trivial')

for option in ('not_an_option', 'b_not_an_option'):
for option in ('not_an_option', 'b_not_an_option', 'c_not_an_option'):
out = self.init(testdir, extra_args=['--wipe', f'-D{option}=1'], inprocess=True, allow_fail=True)
self.assertIn(f'ERROR: Unknown options: "{option}"', out)

0 comments on commit f92e06f

Please sign in to comment.