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/environment.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/environment.py')
| -rw-r--r-- | mesonbuild/environment.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index a3b8cd5f2..2a9cf165b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -648,6 +648,11 @@ class Environment: # 'optimization' and 'debug' keys, it override them. self.options: T.MutableMapping[OptionKey, ElementaryOptionValues] = collections.OrderedDict() + # Environment variables with the name converted into an OptionKey type. + # These have subtly different behavior compared to machine files, so do + # not store them in self.options. See _set_default_options_from_env. + self.env_opts: T.MutableMapping[OptionKey, ElementaryOptionValues] = {} + self.machinestore = machinefile.MachineFileStore(self.coredata.config_files, self.coredata.cross_files, self.source_dir) ## Read in native file(s) to override build machine configuration @@ -819,35 +824,35 @@ class Environment: env_opts[key].extend(p_list) elif keyname == 'cppflags': for lang in compilers.compilers.LANGUAGES_USING_CPPFLAGS: - key = OptionKey(f'{lang}_env_args', machine=for_machine) + key = OptionKey(f'{lang}_args', machine=for_machine) env_opts[key].extend(p_list) else: key = OptionKey.from_string(keyname).evolve(machine=for_machine) if evar in compilers.compilers.CFLAGS_MAPPING.values(): - # If this is an environment variable, we have to - # store it separately until the compiler is - # instantiated, as we don't know whether the - # compiler will want to use these arguments at link - # time and compile time (instead of just at compile - # time) until we're instantiating that `Compiler` - # object. This is required so that passing - # `-Dc_args=` on the command line and `$CFLAGS` - # have subtly different behavior. `$CFLAGS` will be - # added to the linker command line if the compiler - # acts as a linker driver, `-Dc_args` will not. - # - # We still use the original key as the base here, as - # we want to inherit the machine and the compiler - # language lang = key.name.split('_', 1)[0] - key = key.evolve(f'{lang}_env_args') + key = key.evolve(f'{lang}_args') env_opts[key].extend(p_list) - for k, v in env_opts.items(): + # If this is an environment variable, we have to + # store it separately until the compiler is + # instantiated, as we don't know whether the + # compiler will want to use these arguments at link + # time and compile time (instead of just at compile + # time) until we're instantiating that `Compiler` + # object. This is required so that passing + # `-Dc_args=` on the command line and `$CFLAGS` + # have subtly different behavior. `$CFLAGS` will be + # added to the linker command line if the compiler + # acts as a linker driver, `-Dc_args` will not. + for (_, keyname), for_machine in itertools.product(NON_LANG_ENV_OPTIONS, MachineChoice): + key = OptionKey.from_string(keyname).evolve(machine=for_machine) # Only store options that are not already in self.options, # otherwise we'd override the machine files - if k not in self.options: - self.options[k] = v + if key in env_opts and key not in self.options: + self.options[key] = env_opts[key] + del env_opts[key] + + self.env_opts.update(env_opts) def _set_default_binaries_from_env(self) -> None: """Set default binaries from the environment. |
