environment: get environment variables for both host and build machines

Fixes #8605
pull/8606/head
Dylan Baker 4 years ago
parent 848cacc38c
commit f99ed692c4
  1. 23
      mesonbuild/compilers/compilers.py
  2. 8
      mesonbuild/environment.py

@ -1236,19 +1236,26 @@ def get_global_options(lang: str,
largkey = argkey.evolve('link_args')
envkey = argkey.evolve('env_args')
comp_key = argkey if argkey in env.options else envkey
comp_options = env.options.get(comp_key, [])
link_options = env.options.get(largkey, [])
cargs = coredata.UserArrayOption(
description + ' compiler',
env.options.get(argkey, []), split_args=True, user_input=True, allow_dups=True)
# the compiler args always gets the environemtn variable arguments
cargs.extend_value(env.options.get(envkey, []))
comp_options, split_args=True, user_input=True, allow_dups=True)
largs = coredata.UserArrayOption(
description + ' linker',
env.options.get(largkey, []), split_args=True, user_input=True, allow_dups=True)
# The linker gets the compiler environment variable only if the comiler
# acts as the linker
if comp.INVOKES_LINKER:
largs.extend_value(env.options.get(envkey, []))
link_options, split_args=True, user_input=True, allow_dups=True)
if comp.INVOKES_LINKER and comp_key == envkey:
# 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.
# This is how autotools works, and the env vars freature is for
# autotools compatibility.
largs.extend_value(comp_options)
opts: 'KeyedOptionDictType' = {argkey: cargs, largkey: largs}

@ -798,11 +798,7 @@ class Environment:
env_opts: T.DefaultDict[OptionKey, T.List[str]] = collections.defaultdict(list)
if self.is_cross_build():
for_machine = MachineChoice.BUILD
else:
for_machine = MachineChoice.HOST
for evar, keyname in opts:
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:
# these may contain duplicates, which must be removed, else
@ -832,7 +828,7 @@ class Environment:
key = key.evolve(lang=lang)
env_opts[key].extend(p_list)
elif keyname == 'cppflags':
key = OptionKey('args', machine=for_machine, lang='c')
key = OptionKey('env_args', machine=for_machine, lang='c')
for lang in compilers.compilers.LANGUAGES_USING_CPPFLAGS:
key = key.evolve(lang=lang)
env_opts[key].extend(p_list)

Loading…
Cancel
Save