Use dict for self.build.compilers instead of list

Everywhere we use this object, we end up iterating over it and comparing
compiler.get_language() with something. Using a dict is the obvious
choice and simplifies a lot of code.
pull/1171/head
Nirbheek Chauhan 8 years ago
parent ec47db6c0c
commit 7b3d00fee4
  1. 15
      mesonbuild/backend/ninjabackend.py
  2. 23
      mesonbuild/build.py
  3. 12
      mesonbuild/interpreter.py
  4. 10
      mesonbuild/modules/gnome.py
  5. 2
      mesonbuild/modules/rpm.py
  6. 6
      mesonbuild/modules/windows.py

@ -1210,7 +1210,7 @@ int dummy;
raise MesonException('Swift supports only executable and static library targets.')
def generate_static_link_rules(self, is_cross, outfile):
if self.build.has_language('java'):
if 'java' in self.build.compilers:
if not is_cross:
self.generate_java_link(outfile)
if is_cross:
@ -1251,8 +1251,7 @@ int dummy;
else:
ctypes.append((self.build.cross_compilers, True))
for (complist, is_cross) in ctypes:
for compiler in complist:
langname = compiler.get_language()
for langname, compiler in complist.items():
if langname == 'java' or langname == 'vala' or\
langname == 'rust' or langname == 'cs':
continue
@ -1511,8 +1510,7 @@ rule FORTRAN_DEP_HACK
def generate_compile_rules(self, outfile):
qstr = quote_char + "%s" + quote_char
for compiler in self.build.compilers:
langname = compiler.get_language()
for langname, compiler in self.build.compilers.items():
if compiler.get_id() == 'clang':
self.generate_llvm_ir_compile_rule(compiler, False, outfile)
self.generate_compile_rule_for(langname, compiler, qstr, False, outfile)
@ -1524,8 +1522,7 @@ rule FORTRAN_DEP_HACK
cclist = self.build.cross_compilers
else:
cclist = self.build.compilers
for compiler in cclist:
langname = compiler.get_language()
for langname, compiler in cclist.items():
if compiler.get_id() == 'clang':
self.generate_llvm_ir_compile_rule(compiler, True, outfile)
self.generate_compile_rule_for(langname, compiler, qstr, True, outfile)
@ -1588,8 +1585,8 @@ rule FORTRAN_DEP_HACK
def scan_fortran_module_outputs(self, target):
compiler = None
for c in self.build.compilers:
if c.get_language() == 'fortran':
for lang, c in self.build.compilers.items():
if lang == 'fortran':
compiler = c
break
if compiler is None:

@ -88,8 +88,8 @@ class Build:
self.environment = environment
self.projects = {}
self.targets = {}
self.compilers = []
self.cross_compilers = []
self.compilers = {}
self.cross_compilers = {}
self.global_args = {}
self.projects_args = {}
self.global_link_args = {}
@ -109,26 +109,19 @@ class Build:
self.dep_manifest = {}
self.cross_stdlibs = {}
def has_language(self, language):
for i in self.compilers:
if i.get_language() == language:
return True
return False
def add_compiler(self, compiler):
if self.static_linker is None and compiler.needs_static_linker():
self.static_linker = self.environment.detect_static_linker(compiler)
if self.has_language(compiler.get_language()):
return
self.compilers.append(compiler)
lang = compiler.get_language()
if lang not in self.compilers:
self.compilers[lang] = compiler
def add_cross_compiler(self, compiler):
if len(self.cross_compilers) == 0:
self.static_cross_linker = self.environment.detect_static_linker(compiler)
for i in self.cross_compilers:
if i.get_language() == compiler.get_language():
return
self.cross_compilers.append(compiler)
lang = compiler.get_language()
if lang not in self.cross_compilers:
self.cross_compilers[lang] = compiler
def get_project(self):
return self.projects['']

@ -1074,9 +1074,8 @@ class MesonMain(InterpreterObject):
clist = self.build.compilers
else:
clist = self.build.cross_compilers
for c in clist:
if c.get_language() == cname:
return CompilerHolder(c, self.build.environment)
if cname in clist:
return CompilerHolder(clist[cname], self.build.environment)
raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname)
def is_unity_method(self, args, kwargs):
@ -1254,8 +1253,7 @@ class Interpreter(InterpreterBase):
def check_cross_stdlibs(self):
if self.build.environment.is_cross_build():
cross_info = self.build.environment.cross_info
for c in self.build.cross_compilers:
l = c.language
for l, c in self.build.cross_compilers.items():
try:
di = mesonlib.stringlistify(cross_info.get_stdlib(l))
if len(di) != 2:
@ -2287,9 +2285,9 @@ requirements use the version keyword argument instead.''')
def get_used_languages(self, target):
result = {}
for i in target.sources:
for c in self.build.compilers:
for lang, c in self.build.compilers.items():
if c.can_compile(i):
result[c.language] = True
result[lang] = True
break
return result

@ -433,11 +433,11 @@ can not be used with the current version of glib-compiled-resources, due to
cflags += state.global_args['c']
if state.project_args.get('c'):
cflags += state.project_args['c']
for compiler in state.compilers:
if compiler.get_language() == 'c':
sanitize = compiler.get_options().get('b_sanitize')
if sanitize:
cflags += compilers.sanitizer_compile_args(sanitize)
if 'c' in state.compilers:
compiler = state.compilers['c']
sanitize = compiler.get_options().get('b_sanitize')
if sanitize:
cflags += compilers.sanitizer_compile_args(sanitize)
if cflags:
scan_command += ['--cflags-begin']
scan_command += cflags

@ -27,7 +27,7 @@ class RPMModule:
def generate_spec_template(self, state, args, kwargs):
compiler_deps = set()
for compiler in state.compilers:
for compiler in state.compilers.values():
if isinstance(compiler, compilers.GnuCCompiler):
compiler_deps.add('gcc')
elif isinstance(compiler, compilers.GnuCPPCompiler):

@ -19,9 +19,9 @@ import os
class WindowsModule:
def detect_compiler(self, compilers):
for c in compilers:
if c.language == 'c' or c.language == 'cpp':
return c
for l in ('c', 'cpp'):
if l in compilers:
return compilers[l]
raise MesonException('Resource compilation requires a C or C++ compiler.')
def compile_resources(self, state, args, kwargs):

Loading…
Cancel
Save