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.
pull/8159/head
Dylan Baker 4 years ago
parent 7248a64750
commit 4580433b82
  1. 32
      mesonbuild/compilers/compilers.py
  2. 8
      mesonbuild/modules/unstable_external_project.py
  3. 2
      run_unittests.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)

@ -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)

@ -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]

Loading…
Cancel
Save