Fix base and compiler options not reconfigurable.

Fixes #12920.
pull/12910/head
Charles Brunet 11 months ago committed by Dylan Baker
parent 4ed6d75d96
commit 76f6874e48
  1. 2
      mesonbuild/compilers/detect.py
  2. 17
      mesonbuild/coredata.py
  3. 3
      mesonbuild/interpreter/interpreter.py
  4. 2
      run_project_tests.py
  5. 5
      test cases/unit/122 reconfigure base options/meson.build
  6. 10
      unittests/platformagnostictests.py

@ -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

@ -1017,6 +1017,7 @@ class CoreData:
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'],
@ -1028,20 +1029,20 @@ class CoreData:
# `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:
continue
oobj = copy.deepcopy(compilers.base_options[key])
if key in env.options:
oobj.set_value(env.options[key])
enabled_opts.append(key)
self.options[key] = oobj
if key not in self.options:
self.options[key] = copy.deepcopy(compilers.base_options[key])
if key in env.options:
self.options[key].set_value(env.options[key])
enabled_opts.append(key)
elif key in env.options:
self.options[key].set_value(env.options[key])
self.emit_base_options_warnings(enabled_opts)
def emit_base_options_warnings(self, enabled_opts: T.List[OptionKey]) -> None:

@ -1518,6 +1518,9 @@ class Interpreter(InterpreterBase, HoldableObject):
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:

@ -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:

@ -0,0 +1,5 @@
project('reconfigure', 'c',
default_options: ['c_std=c89'])
message('b_ndebug: ' + get_option('b_ndebug'))
message('c_std: ' + get_option('c_std'))

@ -275,3 +275,13 @@ class PlatformAgnosticTests(BasePlatformTests):
self.assertIn('first statement must be a call to project()', out)
# provide guidance diagnostics by finding a file whose first AST statement is project()
self.assertIn(f'Did you mean to run meson from the directory: "{testdir}"?', out)
def test_reconfigure_base_options(self):
testdir = os.path.join(self.unit_test_dir, '122 reconfigure base options')
out = self.init(testdir, extra_args=['-Db_ndebug=true'])
self.assertIn('\nMessage: b_ndebug: true\n', out)
self.assertIn('\nMessage: c_std: c89\n', out)
out = self.init(testdir, extra_args=['--reconfigure', '-Db_ndebug=if-release', '-Dc_std=c99'])
self.assertIn('\nMessage: b_ndebug: if-release\n', out)
self.assertIn('\nMessage: c_std: c99\n', out)

Loading…
Cancel
Save