aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/environment.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-03-23 20:52:49 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2021-03-30 18:52:17 +0300
commit2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17 (patch)
tree8a403fc8589838c8305f34cdb22b0e8db72ea8ce /mesonbuild/environment.py
parent692f6733122b2bf053299f8a0cdbcab3d5bfbfb5 (diff)
downloadmeson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.zip
meson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.tar.gz
meson-2cd0723c42ae2076c7ba2b888fd7a5235d5cbf17.tar.bz2
Split environment variable and command line cflags
They are supposed to have different behavior. The environment variables apply to both the compiler and linker when the compiler acts as a linker, but the command line ones do not. Fixes #8345
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r--mesonbuild/environment.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index f59eb87..373c063 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -798,7 +798,11 @@ class Environment:
env_opts: T.DefaultDict[OptionKey, T.List[str]] = collections.defaultdict(list)
- for (evar, keyname), for_machine in itertools.product(opts, MachineChoice):
+ if self.is_cross_build():
+ for_machine = MachineChoice.BUILD
+ else:
+ for_machine = MachineChoice.HOST
+ for evar, keyname in opts:
p_env = _get_env_var(for_machine, self.is_cross_build(), evar)
if p_env is not None:
# these may contain duplicates, which must be removed, else
@@ -834,6 +838,23 @@ class Environment:
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 subtely differen behavior. `$CFLAGS` will be
+ # added to the linker command line if the compiler
+ # acts as a linker driver, `-Dc_args` will not.
+ #
+ # We stil use the original key as the base here, as
+ # we want to inhert the machine and the compiler
+ # language
+ key = key.evolve('env_args')
env_opts[key].extend(p_list)
# Only store options that are not already in self.options,