From 4580433b8255b9f69dfbd39a28c21bc1ec785bcf Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 8 Dec 2020 10:33:11 -0800 Subject: [PATCH] rename cflags_mapping to CFLAGS_MAPPING This is PEP8 convention for a const variable. Also, make the type Mapping, which doesn't have mutation methods. This means mypy will warn us if someone tries to change this. --- mesonbuild/compilers/compilers.py | 32 +++++++++++-------- .../modules/unstable_external_project.py | 8 ++--- run_unittests.py | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 234ce06e9..41e1036b2 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -91,18 +91,22 @@ languages_using_cppflags = {'c', 'cpp', 'objc', 'objcpp'} # type: T.Set[str] soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$') # Environment variables that each lang uses. -cflags_mapping = {'c': 'CFLAGS', - 'cpp': 'CXXFLAGS', - 'cuda': 'CUFLAGS', - 'objc': 'OBJCFLAGS', - 'objcpp': 'OBJCXXFLAGS', - 'fortran': 'FFLAGS', - 'd': 'DFLAGS', - 'vala': 'VALAFLAGS', - 'rust': 'RUSTFLAGS'} # type: T.Dict[str, str] - -cexe_mapping = {'c': 'CC', - 'cpp': 'CXX'} +CFLAGS_MAPPING: T.Mapping[str, str] = { + 'c': 'CFLAGS', + 'cpp': 'CXXFLAGS', + 'cuda': 'CUFLAGS', + 'objc': 'OBJCFLAGS', + 'objcpp': 'OBJCXXFLAGS', + 'fortran': 'FFLAGS', + 'd': 'DFLAGS', + 'vala': 'VALAFLAGS', + 'rust': 'RUSTFLAGS', +} + +CEXE_MAPPING: T.Mapping = { + 'c': 'CC', + 'cpp': 'CXX', +} # All these are only for C-linkable languages; see `clink_langs` above. @@ -1207,13 +1211,13 @@ def get_args_from_envvars(lang: str, Returns a tuple of (compile_flags, link_flags) for the specified language from the inherited environment """ - if lang not in cflags_mapping: + 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]) + 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) diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py index 7249078ac..809b590bd 100644 --- a/mesonbuild/modules/unstable_external_project.py +++ b/mesonbuild/modules/unstable_external_project.py @@ -23,7 +23,7 @@ from ..mesonlib import (MesonException, Popen_safe, MachineChoice, from ..interpreterbase import InterpreterObject, InterpreterException, FeatureNew from ..interpreterbase import stringArgs, permittedKwargs from ..interpreter import Interpreter, DependencyHolder, InstallDir -from ..compilers.compilers import cflags_mapping, cexe_mapping +from ..compilers.compilers import CFLAGS_MAPPING, CEXE_MAPPING from ..dependencies.base import InternalDependency, PkgConfigDependency from ..environment import Environment from ..mesonlib import OptionKey @@ -110,11 +110,11 @@ class ExternalProject(InterpreterObject): link_args = [] self.run_env = os.environ.copy() for lang, compiler in self.env.coredata.compilers[MachineChoice.HOST].items(): - if any(lang not in i for i in (cexe_mapping, cflags_mapping)): + if any(lang not in i for i in (CEXE_MAPPING, CFLAGS_MAPPING)): continue cargs = self.env.coredata.get_external_args(MachineChoice.HOST, lang) - self.run_env[cexe_mapping[lang]] = self._quote_and_join(compiler.get_exelist()) - self.run_env[cflags_mapping[lang]] = self._quote_and_join(cargs) + self.run_env[CEXE_MAPPING[lang]] = self._quote_and_join(compiler.get_exelist()) + self.run_env[CFLAGS_MAPPING[lang]] = self._quote_and_join(cargs) if not link_exelist: link_exelist = compiler.get_linker_exelist() link_args = self.env.coredata.get_external_link_args(MachineChoice.HOST, lang) diff --git a/run_unittests.py b/run_unittests.py index 5118b0096..2f102b471 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -9347,7 +9347,7 @@ def unset_envs(): # For unit tests we must fully control all command lines # so that there are no unexpected changes coming from the # environment, for example when doing a package build. - varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.compilers.compilers.cflags_mapping.values()) + varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.compilers.compilers.CFLAGS_MAPPING.values()) for v in varnames: if v in os.environ: del os.environ[v]