aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-07-16 11:26:59 -0700
committerDylan Baker <dylan@pnwbakers.com>2019-08-14 13:13:23 -0700
commit1c455ee63028def44d1f5683ffd9c7be12eac7fa (patch)
treeec0f2a1e4729b20c8d153964c310d1534f11239f
parent499c44dc77c2d4a2c649830555cd9257d285bba6 (diff)
downloadmeson-1c455ee63028def44d1f5683ffd9c7be12eac7fa.zip
meson-1c455ee63028def44d1f5683ffd9c7be12eac7fa.tar.gz
meson-1c455ee63028def44d1f5683ffd9c7be12eac7fa.tar.bz2
environment: Use a single function to check for ObjC and ObjC++
These two functions are different only in the classes that they use, a couple of simple in-line ternaries takes care of that and reduces code duplication.
-rw-r--r--mesonbuild/environment.py55
1 files changed, 17 insertions, 38 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index cd55ace..b299677 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -927,39 +927,15 @@ class Environment:
def get_scratch_dir(self):
return self.scratch_dir
- def detect_objc_compiler(self, for_machine):
- popen_exceptions = {}
- compilers, ccache, exe_wrap = self._get_compilers('objc', for_machine)
- is_cross = not self.machines.matches_build_machine(for_machine)
- for compiler in compilers:
- if isinstance(compiler, str):
- compiler = [compiler]
- arg = ['--version']
- try:
- p, out, err = Popen_safe(compiler + arg)
- except OSError as e:
- popen_exceptions[' '.join(compiler + arg)] = e
- continue
- version = search_version(out)
- if 'Free Software Foundation' in out or ('e2k' in out and 'lcc' in out):
- defines = self.get_gnu_compiler_defines(compiler)
- if not defines:
- popen_exceptions[' '.join(compiler)] = 'no pre-processor defines'
- continue
- compiler_type = self.get_gnu_compiler_type(defines)
- version = self.get_gnu_version_from_defines(defines)
- return GnuObjCCompiler(ccache + compiler, version, compiler_type, for_machine, is_cross, exe_wrap, defines)
- if out.startswith('Apple LLVM') or out.startswith('Apple clang'):
- return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, for_machine, is_cross, exe_wrap)
- if 'windows' in out:
- return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_MINGW, for_machine, is_cross, exe_wrap)
- if out.startswith(('clang', 'OpenBSD clang')):
- return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, for_machine, is_cross, exe_wrap)
- self._handle_exceptions(popen_exceptions, compilers)
+ def detect_objc_compiler(self, for_machine: MachineInfo) -> 'Compiler':
+ return self._detect_objc_or_objcpp_compiler(for_machine, True)
- def detect_objcpp_compiler(self, for_machine):
+ def detect_objcpp_compiler(self, for_machine: MachineInfo) -> 'Compiler':
+ return self._detect_objc_or_objcpp_compiler(for_machine, False)
+
+ def _detect_objc_or_objcpp_compiler(self, for_machine: MachineInfo, objc: bool) -> 'Compiler':
popen_exceptions = {}
- compilers, ccache, exe_wrap = self._get_compilers('objcpp', for_machine)
+ compilers, ccache, exe_wrap = self._get_compilers('objc' if objc else 'objcpp', for_machine)
is_cross = not self.machines.matches_build_machine(for_machine)
for compiler in compilers:
if isinstance(compiler, str):
@@ -978,13 +954,16 @@ class Environment:
continue
compiler_type = self.get_gnu_compiler_type(defines)
version = self.get_gnu_version_from_defines(defines)
- return GnuObjCPPCompiler(ccache + compiler, version, compiler_type, for_machine, is_cross, exe_wrap, defines)
- if out.startswith('Apple LLVM') or out.startswith('Apple clang'):
- return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, for_machine, is_cross, exe_wrap)
- if 'windows' in out:
- return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_MINGW, for_machine, is_cross, exe_wrap)
- if out.startswith(('clang', 'OpenBSD clang')):
- return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, for_machine, is_cross, exe_wrap)
+ comp = GnuObjCCompiler if objc else GnuObjCPPCompiler
+ return comp(ccache + compiler, version, compiler_type, for_machine, is_cross, exe_wrap, defines)
+ else:
+ comp = ClangObjCCompiler if objc else ClangObjCPPCompiler
+ if out.startswith('Apple LLVM') or out.startswith('Apple clang'):
+ return comp(ccache + compiler, version, CompilerType.CLANG_OSX, for_machine, is_cross, exe_wrap)
+ if 'windows' in out:
+ return comp(ccache + compiler, version, CompilerType.CLANG_MINGW, for_machine, is_cross, exe_wrap)
+ if out.startswith(('clang', 'OpenBSD clang')):
+ return comp(ccache + compiler, version, CompilerType.CLANG_STANDARD, for_machine, is_cross, exe_wrap)
self._handle_exceptions(popen_exceptions, compilers)
def detect_java_compiler(self, for_machine):