aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/compilers.py
diff options
context:
space:
mode:
authorJohn Ericson <git@JohnEricson.me>2019-08-02 14:29:40 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2020-03-23 17:51:36 +0200
commit3a4388e51dee5e7e58f1e5ad4e60fb73b4aacf08 (patch)
tree8f0637e630777cc4a5707c16a30c4d980b888371 /mesonbuild/compilers/compilers.py
parentf6b0425576640e1613f64503951c7c604b868947 (diff)
downloadmeson-3a4388e51dee5e7e58f1e5ad4e60fb73b4aacf08.zip
meson-3a4388e51dee5e7e58f1e5ad4e60fb73b4aacf08.tar.gz
meson-3a4388e51dee5e7e58f1e5ad4e60fb73b4aacf08.tar.bz2
Fix legacy env var support with cross
Fix #3969
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r--mesonbuild/compilers/compilers.py62
1 files changed, 30 insertions, 32 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index a0d752c..de8fb70 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -18,7 +18,10 @@ import itertools
import typing as T
from functools import lru_cache
-from ..linkers import StaticLinker, GnuLikeDynamicLinkerMixin, SolarisDynamicLinker
+from ..linkers import (
+ GnuLikeDynamicLinkerMixin, LinkerEnvVarsMixin, SolarisDynamicLinker,
+ StaticLinker,
+)
from .. import coredata
from .. import mlog
from .. import mesonlib
@@ -27,7 +30,7 @@ from ..mesonlib import (
Popen_safe, split_args
)
from ..envconfig import (
- Properties,
+ Properties, get_env_var
)
if T.TYPE_CHECKING:
@@ -79,7 +82,9 @@ clink_suffixes += ('h', 'll', 's')
all_suffixes = set(itertools.chain(*lang_suffixes.values(), clink_suffixes))
# Languages that should use LDFLAGS arguments when linking.
-languages_using_ldflags = ('objcpp', 'cpp', 'objc', 'c', 'fortran', 'd', 'cuda')
+languages_using_ldflags = {'objcpp', 'cpp', 'objc', 'c', 'fortran', 'd', 'cuda'}
+# Languages that should use CPPFLAGS arguments when linking.
+languages_using_cppflags = {'c', 'cpp', 'objc', 'objcpp'}
soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$')
# Environment variables that each lang uses.
@@ -855,8 +860,10 @@ class Compiler:
"""
return []
- def get_linker_args_from_envvars(self) -> T.List[str]:
- return self.linker.get_args_from_envvars()
+ def get_linker_args_from_envvars(self,
+ for_machine: MachineChoice,
+ is_cross: bool) -> T.List[str]:
+ return self.linker.get_args_from_envvars(for_machine, is_cross)
def get_options(self) -> T.Dict[str, coredata.UserOption]:
return {}
@@ -1208,37 +1215,27 @@ def get_largefile_args(compiler):
return []
-def get_args_from_envvars(lang: str, use_linker_args: bool) -> T.Tuple[T.List[str], T.List[str]]:
+def get_args_from_envvars(lang: str,
+ for_machine: MachineChoice,
+ is_cross: bool,
+ use_linker_args: bool) -> T.Tuple[T.List[str], T.List[str]]:
"""
Returns a tuple of (compile_flags, link_flags) for the specified language
from the inherited environment
"""
- def log_var(var, val: T.Optional[str]):
- if val:
- mlog.log('Appending {} from environment: {!r}'.format(var, val))
- else:
- mlog.debug('No {} in the environment, not changing global flags.'.format(var))
-
if lang not in cflags_mapping:
return [], []
compile_flags = [] # type: T.List[str]
link_flags = [] # type: T.List[str]
- env_compile_flags = os.environ.get(cflags_mapping[lang])
- log_var(cflags_mapping[lang], env_compile_flags)
+ env_compile_flags = get_env_var(for_machine, is_cross, cflags_mapping[lang])
if env_compile_flags is not None:
compile_flags += split_args(env_compile_flags)
# Link flags (same for all languages)
if lang in languages_using_ldflags:
- # This is duplicated between the linkers, but I'm not sure how else
- # to handle this
- env_link_flags = split_args(os.environ.get('LDFLAGS', ''))
- else:
- env_link_flags = []
- log_var('LDFLAGS', env_link_flags)
- link_flags += env_link_flags
+ link_flags += LinkerEnvVarsMixin.get_args_from_envvars(for_machine, is_cross)
if use_linker_args:
# When the compiler is used as a wrapper around the linker (such as
# with GCC and Clang), the compile flags can be needed while linking
@@ -1247,16 +1244,18 @@ def get_args_from_envvars(lang: str, use_linker_args: bool) -> T.Tuple[T.List[st
link_flags = compile_flags + link_flags
# Pre-processor flags for certain languages
- if lang in {'c', 'cpp', 'objc', 'objcpp'}:
- env_preproc_flags = os.environ.get('CPPFLAGS')
- log_var('CPPFLAGS', env_preproc_flags)
+ if lang in languages_using_cppflags:
+ env_preproc_flags = get_env_var(for_machine, is_cross, 'CPPFLAGS')
if env_preproc_flags is not None:
compile_flags += split_args(env_preproc_flags)
return compile_flags, link_flags
-def get_global_options(lang: str, comp: T.Type[Compiler],
+def get_global_options(lang: str,
+ comp: T.Type[Compiler],
+ for_machine: MachineChoice,
+ is_cross: bool,
properties: Properties) -> T.Dict[str, coredata.UserOption]:
"""Retreive options that apply to all compilers for a given language."""
description = 'Extra arguments passed to the {}'.format(lang)
@@ -1269,13 +1268,12 @@ def get_global_options(lang: str, comp: T.Type[Compiler],
[], split_args=True, user_input=True, allow_dups=True),
}
- if properties.fallback:
- # Get from env vars.
- # XXX: True here is a hack
- compile_args, link_args = get_args_from_envvars(lang, comp.INVOKES_LINKER)
- else:
- compile_args = []
- link_args = []
+ # Get from env vars.
+ compile_args, link_args = get_args_from_envvars(
+ lang,
+ for_machine,
+ is_cross,
+ comp.INVOKES_LINKER)
for k, o in opts.items():
if k in properties: