Skip to content

Commit 76f6874

Browse files
bruchar1dcbaker
authored andcommitted
Fix base and compiler options not reconfigurable.
Fixes mesonbuild#12920.
1 parent 4ed6d75 commit 76f6874

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

mesonbuild/compilers/detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic
106106
if comp is None:
107107
return comp
108108
assert comp.for_machine == for_machine
109-
env.coredata.process_new_compiler(lang, comp, env)
109+
env.coredata.process_compiler_options(lang, comp, env)
110110
if not skip_sanity_check:
111111
comp.sanity_check(env.get_scratch_dir(), env)
112112
env.coredata.compilers[comp.for_machine][lang] = comp

mesonbuild/coredata.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ def add_compiler_options(self, options: 'MutableKeyedOptionDictType', lang: str,
10171017
value = env.options.get(k)
10181018
if value is not None:
10191019
o.set_value(value)
1020+
self.options[k] = o # override compiler option on reconfigure
10201021
self.options.setdefault(k, o)
10211022

10221023
def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
@@ -1028,20 +1029,20 @@ def add_lang_args(self, lang: str, comp: T.Type['Compiler'],
10281029
# `self.options.update()`` is perfectly safe.
10291030
self.options.update(compilers.get_global_options(lang, comp, for_machine, env))
10301031

1031-
def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
1032+
def process_compiler_options(self, lang: str, comp: 'Compiler', env: 'Environment') -> None:
10321033
from . import compilers
10331034

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

10361037
enabled_opts: T.List[OptionKey] = []
10371038
for key in comp.base_options:
1038-
if key in self.options:
1039-
continue
1040-
oobj = copy.deepcopy(compilers.base_options[key])
1041-
if key in env.options:
1042-
oobj.set_value(env.options[key])
1043-
enabled_opts.append(key)
1044-
self.options[key] = oobj
1039+
if key not in self.options:
1040+
self.options[key] = copy.deepcopy(compilers.base_options[key])
1041+
if key in env.options:
1042+
self.options[key].set_value(env.options[key])
1043+
enabled_opts.append(key)
1044+
elif key in env.options:
1045+
self.options[key].set_value(env.options[key])
10451046
self.emit_base_options_warnings(enabled_opts)
10461047

10471048
def emit_base_options_warnings(self, enabled_opts: T.List[OptionKey]) -> None:

mesonbuild/interpreter/interpreter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ def add_languages_for(self, args: T.List[str], required: bool, for_machine: Mach
15181518
continue
15191519
else:
15201520
raise
1521+
else:
1522+
# update new values from commandline, if it applies
1523+
self.coredata.process_compiler_options(lang, comp, self.environment)
15211524

15221525
# Add per-subproject compiler options. They inherit value from main project.
15231526
if self.subproject:

run_project_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ def have_working_compiler(lang: str, use_tmp: bool) -> bool:
981981
return False
982982
if not compiler:
983983
return False
984-
env.coredata.process_new_compiler(lang, compiler, env)
984+
env.coredata.process_compiler_options(lang, compiler, env)
985985
try:
986986
compiler.sanity_check(env.get_scratch_dir(), env)
987987
except mesonlib.MesonException:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project('reconfigure', 'c',
2+
default_options: ['c_std=c89'])
3+
4+
message('b_ndebug: ' + get_option('b_ndebug'))
5+
message('c_std: ' + get_option('c_std'))

unittests/platformagnostictests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,13 @@ def test_error_configuring_subdir(self):
275275
self.assertIn('first statement must be a call to project()', out)
276276
# provide guidance diagnostics by finding a file whose first AST statement is project()
277277
self.assertIn(f'Did you mean to run meson from the directory: "{testdir}"?', out)
278+
279+
def test_reconfigure_base_options(self):
280+
testdir = os.path.join(self.unit_test_dir, '122 reconfigure base options')
281+
out = self.init(testdir, extra_args=['-Db_ndebug=true'])
282+
self.assertIn('\nMessage: b_ndebug: true\n', out)
283+
self.assertIn('\nMessage: c_std: c89\n', out)
284+
285+
out = self.init(testdir, extra_args=['--reconfigure', '-Db_ndebug=if-release', '-Dc_std=c99'])
286+
self.assertIn('\nMessage: b_ndebug: if-release\n', out)
287+
self.assertIn('\nMessage: c_std: c99\n', out)

0 commit comments

Comments
 (0)