aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/environment.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-02-16 10:48:20 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2021-02-17 14:46:15 +0200
commit10d94a12b85ba19dc2bcfc6296632eaf74f5d4f0 (patch)
tree5c3d1544f8870c004bcc7cb91adddfa2968363cd /mesonbuild/environment.py
parent7812ceec5fe6147bfe8a5a265b58db1282d2cabc (diff)
downloadmeson-10d94a12b85ba19dc2bcfc6296632eaf74f5d4f0.zip
meson-10d94a12b85ba19dc2bcfc6296632eaf74f5d4f0.tar.gz
meson-10d94a12b85ba19dc2bcfc6296632eaf74f5d4f0.tar.bz2
Environment: Fix passing envrionment variables CPPFLAGS and CFLAGS
Or other language flags that use CPPFLAGS (like CXXFLAGS). The problem here is actually rather simple, `dict.setdefault()` doesn't work like I thought it did, I thought it created a weak entry, but it actually is equivalent to: ```python if k not in dict: dict[k] = v ``` Instead we'll use an intermediate dictionary (a default dictionary actually, since that makes things a little cleaner) and then add the keys from that dict to self.options as applicable. Test case written by Jussi, Fix by Dylan Co-authored-by: Jussi Pakkanen Fixes: #8361 Fixes: #8345
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r--mesonbuild/environment.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index b12728b..7e9118e 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -788,6 +788,8 @@ class Environment:
]
)
+ env_opts: T.DefaultDict[OptionKey, T.List[str]] = collections.defaultdict(list)
+
for (evar, keyname), for_machine in itertools.product(opts, MachineChoice):
p_env = _get_env_var(for_machine, self.is_cross_build(), evar)
if p_env is not None:
@@ -805,7 +807,7 @@ class Environment:
p_list = list(mesonlib.OrderedSet(p_env.split(':')))
else:
p_list = split_args(p_env)
- p_list = [e for e in p_list if e] # filter out any empty eelemnts
+ p_list = [e for e in p_list if e] # filter out any empty elements
# Take env vars only on first invocation, if the env changes when
# reconfiguring it gets ignored.
@@ -816,18 +818,21 @@ class Environment:
key = OptionKey('link_args', machine=for_machine, lang='c') # needs a language to initialize properly
for lang in compilers.compilers.LANGUAGES_USING_LDFLAGS:
key = key.evolve(lang=lang)
- v = mesonlib.listify(self.options.get(key, []))
- self.options.setdefault(key, v + p_list)
+ env_opts[key].extend(p_list)
elif keyname == 'cppflags':
key = OptionKey('args', machine=for_machine, lang='c')
for lang in compilers.compilers.LANGUAGES_USING_CPPFLAGS:
key = key.evolve(lang=lang)
- v = mesonlib.listify(self.options.get(key, []))
- self.options.setdefault(key, v + p_list)
+ env_opts[key].extend(p_list)
else:
key = OptionKey.from_string(keyname).evolve(machine=for_machine)
- v = mesonlib.listify(self.options.get(key, []))
- self.options.setdefault(key, v + p_list)
+ env_opts[key].extend(p_list)
+
+ # Only store options that are not already in self.options,
+ # otherwise we'd override the machine files
+ for k, v in env_opts.items():
+ if k not in self.options:
+ self.options[k] = v
def _set_default_binaries_from_env(self) -> None:
"""Set default binaries from the environment.