Skip to content

Commit

Permalink
Fix base and compiler options not reconfigurable.
Browse files Browse the repository at this point in the history
WIP:
- need to add tests
- need to handle case when a base option is configured with no compilers
  for it.

Fixes #12920.
  • Loading branch information
bruchar1 committed Feb 28, 2024
1 parent 17dff9d commit f89c702
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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_new_compiler(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
6 changes: 5 additions & 1 deletion mesonbuild/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ def add_compiler_options(self, options: 'MutableKeyedOptionDictType', lang: str,
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)

def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
Expand All @@ -1028,14 +1029,17 @@ 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_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
def process_compiler_options(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
from . import compilers

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

enabled_opts: T.List[OptionKey] = []
for key in comp.base_options:
if key in self.options:
if key in env.options:
# Override from commandline, when reconfiguring
self.options[key].set_value(env.options[key])
continue
oobj = copy.deepcopy(compilers.base_options[key])
if key in env.options:
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,9 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
continue
else:
raise
else:
# update new values from commandline, if it applies
self.coredata.process_compiler_options(lang, comp, self.environment)

# Add per-subproject compiler options. They inherit value from main project.
if self.subproject:
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_new_compiler(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

0 comments on commit f89c702

Please sign in to comment.