From 4b0b44aface1cd9ed073733dd80b040b5aaf4c99 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 8 Dec 2020 11:08:37 -0800 Subject: move handling of CFLAGS and friends to environment This has a bunch of nice features. It obviously centralizes everything, which is nice. It also means that env is only re-read at `meson --wipe`, not `meson --reconfigure`. And it's going to allow more cleanups. --- mesonbuild/compilers/compilers.py | 75 ++++++++------------------------------- 1 file changed, 15 insertions(+), 60 deletions(-) (limited to 'mesonbuild/compilers/compilers.py') diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 23a3bc5..cf9f35b 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -22,13 +22,9 @@ from functools import lru_cache from .. import coredata from .. import mlog from .. import mesonlib -from ..linkers import LinkerEnvVarsMixin from ..mesonlib import ( EnvironmentException, MachineChoice, MesonException, - Popen_safe, split_args, LibType, TemporaryDirectoryWinProof, OptionKey, -) -from ..envconfig import ( - get_env_var + Popen_safe, LibType, TemporaryDirectoryWinProof, OptionKey, ) from ..arglist import CompilerArgs @@ -105,7 +101,7 @@ CFLAGS_MAPPING: T.Mapping[str, str] = { CEXE_MAPPING: T.Mapping = { 'c': 'CC', - 'cpp': 'CXX', + 'cpp': 'CXX', } # All these are only for C-linkable languages; see `clink_langs` above. @@ -591,11 +587,6 @@ class Compiler(metaclass=abc.ABCMeta): """ return [] - 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) -> 'KeyedOptionDictType': return {} @@ -1203,68 +1194,32 @@ class Compiler(metaclass=abc.ABCMeta): def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]: raise EnvironmentException('{} does not know how to do prelinking.'.format(self.id)) -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 - """ - if lang not in CFLAGS_MAPPING: - return [], [] - - compile_flags = [] # type: T.List[str] - link_flags = [] # type: T.List[str] - - 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: - 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 - # too. This is also what Autotools does. However, we don't want to do - # this when the linker is stand-alone such as with MSVC C/C++, etc. - link_flags = compile_flags + link_flags - - # Pre-processor flags for certain languages - 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], for_machine: MachineChoice, - is_cross: bool) -> 'KeyedOptionDictType': + env: 'Environment') -> 'KeyedOptionDictType': """Retreive options that apply to all compilers for a given language.""" description = 'Extra arguments passed to the {}'.format(lang) argkey = OptionKey('args', lang=lang, machine=for_machine) largkey = argkey.evolve('link_args') + + # We shouldn't need listify here, but until we have a separate + # linker-driver representation and can have that do the combine we have to + # do it htis way. + compile_args = mesonlib.listify(env.options.get(argkey, [])) + link_args = mesonlib.listify(env.options.get(largkey, [])) + + if comp.INVOKES_LINKER: + link_args = compile_args + link_args + opts: 'KeyedOptionDictType' = { argkey: coredata.UserArrayOption( description + ' compiler', - [], split_args=True, user_input=True, allow_dups=True), + compile_args, split_args=True, user_input=True, allow_dups=True), largkey: coredata.UserArrayOption( description + ' linker', - [], split_args=True, user_input=True, allow_dups=True), + link_args, split_args=True, user_input=True, allow_dups=True), } - # Get from env vars. - compile_args, link_args = get_args_from_envvars( - lang, - for_machine, - is_cross, - comp.INVOKES_LINKER) - - opts[argkey].set_value(compile_args) - opts[largkey].set_value(link_args) - return opts -- cgit v1.1