diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-05-06 18:35:40 +0200 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2025-05-15 02:03:46 -0400 |
| commit | 2d1c67f095e5bf709a1fa2a21a99e8c1d543961c (patch) | |
| tree | 8c9021545aa5ea5b1cb5f251c516d031e871f4a2 /mesonbuild/compilers/compilers.py | |
| parent | d11fa36196b6f037d95304772efd6e51b39b8379 (diff) | |
| download | meson-2d1c67f095e5bf709a1fa2a21a99e8c1d543961c.tar.gz | |
options: restore special behavior of CFLAGS vs. c_args
For compatibility with Autotools, CFLAGS is added to the linker command
line if the compiler acts as a linker driver. However, this behavior
was lost in commit d37d649b0 ("Make all Meson level options overridable
per subproject.", 2025-02-13).
The issue is that (for example) c_link_args is stored in env.options, and
from that point on it is treated as a machine-file option. This includes
not being able to override it in compilers.get_global_options:
- initialize_from_top_level_project_call places it in pending_options
- add_lang_args passes the right value to add_compiler_option
- add_compiler_option calls add_system_option_internal
- add_system_option_internal fishes the value out of pending_options
and ignores what get_global_options provided.
Instead, store the putative values of the compiler options coming from
the environment in a separate dictionary, that is only accessed by
get_global_options. This way it never appears in pending_options, and
also there is no internal *_env_args variable anymore.
Fixes: #14533
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index ad252a136..d0934fc73 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1424,12 +1424,19 @@ def get_global_options(lang: str, description = f'Extra arguments passed to the {lang}' argkey = OptionKey(f'{lang}_args', machine=for_machine) largkey = OptionKey(f'{lang}_link_args', machine=for_machine) - envkey = OptionKey(f'{lang}_env_args', machine=for_machine) - comp_key = argkey if argkey in env.options else envkey + comp_args_from_envvar = False + comp_options = env.coredata.optstore.get_pending_value(argkey) + if comp_options is None: + comp_args_from_envvar = True + comp_options = env.env_opts.get(argkey, []) + + link_args_from_envvar = False + link_options = env.coredata.optstore.get_pending_value(largkey) + if link_options is None: + link_args_from_envvar = True + link_options = env.env_opts.get(largkey, []) - comp_options = env.options.get(comp_key, []) - link_options = env.options.get(largkey, []) assert isinstance(comp_options, (str, list)), 'for mypy' assert isinstance(link_options, (str, list)), 'for mypy' @@ -1443,7 +1450,7 @@ def get_global_options(lang: str, description + ' linker', link_options, split_args=True, allow_dups=True) - if comp.INVOKES_LINKER and comp_key == envkey: + if comp.INVOKES_LINKER and comp_args_from_envvar and link_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 # arguments, then put the compiler flags in the linker flags as well. |
