summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-07-09 11:07:35 +0200
committerDylan Baker <dylan@pnwbakers.com>2025-07-10 09:47:49 -0700
commit1c14c08aabfd4852451d194a6f5aee9568fe4455 (patch)
tree69e3d3b1697ef1c96663bfc28b3a8d1d4c887ca5
parent5736120edc2322476a01622b1e5106877f08d327 (diff)
downloadmeson-1c14c08aabfd4852451d194a6f5aee9568fe4455.tar.gz
options: apply CFLAGS even if c_link_args exists
This restores the behavior before 1.8's option store refactoring. The bug arises because c_link_args has been stored in pending_options, and therefore the extended value (which get_global_options correctly computes) is overwritten by the value passed on the command line. In fact, this bug is the reason why I added the "link_args_from_envvar" check: the CFLAGS would be ignored anyway, so I put that logic in code instead of relying on the option store's behavior. The fix is to extend the value *after* the option has been added and the pending_options resolved. This requires a tiny refactoring of the split between CoreData.add_lang_args and compilers.get_global_options. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/compilers/compilers.py11
-rw-r--r--mesonbuild/coredata.py6
2 files changed, 6 insertions, 11 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 3845f3465..057868f7a 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1419,10 +1419,10 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
std.choices = value
-def get_global_options(lang: str,
+def add_global_options(lang: str,
comp: T.Type[Compiler],
for_machine: MachineChoice,
- env: 'Environment') -> dict[OptionKey, options.AnyOptionType]:
+ env: 'Environment'):
"""Retrieve options that apply to all compilers for a given language."""
description = f'Extra arguments passed to the {lang}'
argkey = OptionKey(f'{lang}_args', machine=for_machine)
@@ -1451,6 +1451,9 @@ def get_global_options(lang: str,
description + ' linker',
link_options, split_args=True, allow_dups=True)
+ env.coredata.optstore.add_compiler_option(lang, argkey, cargs)
+ env.coredata.optstore.add_compiler_option(lang, largkey, largs)
+
if comp.INVOKES_LINKER and comp_args_from_envvar:
# If the compiler acts as a linker driver, and we're using the
# environment variable flags for both the compiler and linker
@@ -1458,7 +1461,3 @@ def get_global_options(lang: str,
# This is how autotools works, and the env vars feature is for
# autotools compatibility.
largs.extend_value(comp_options)
-
- opts: dict[OptionKey, options.AnyOptionType] = {argkey: cargs, largkey: largs}
-
- return opts
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 26ef1b805..320b34b44 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -588,11 +588,7 @@ class CoreData:
for_machine: MachineChoice, env: 'Environment') -> None:
"""Add global language arguments that are needed before compiler/linker detection."""
from .compilers import compilers
- # These options are all new at this point, because the compiler is
- # responsible for adding its own options, thus calling
- # `self.optstore.update()`` is perfectly safe.
- for gopt_key, gopt_valobj in compilers.get_global_options(lang, comp, for_machine, env).items():
- self.optstore.add_compiler_option(lang, gopt_key, gopt_valobj)
+ compilers.add_global_options(lang, comp, for_machine, env)
def process_compiler_options(self, lang: str, comp: Compiler, subproject: str) -> None:
self.add_compiler_options(comp.get_options(), lang, comp.for_machine)