diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index d8f48f3e00ef..dbc2b4879208 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.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 diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 25a506848b2b..b81c98b32ac7 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -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'], @@ -1028,7 +1029,7 @@ 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) @@ -1036,6 +1037,9 @@ def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') 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: diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 79a61ed0ea2e..e5a201e053e4 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -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: diff --git a/run_project_tests.py b/run_project_tests.py index 60ff56f70851..6fc9cb7f77fa 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -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: