aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xenvironment.py71
-rwxr-xr-xinterpreter.py2
-rw-r--r--test cases/objc/1 simple/meson.build4
-rw-r--r--test cases/objc/1 simple/prog.m5
4 files changed, 76 insertions, 6 deletions
diff --git a/environment.py b/environment.py
index 6a04fcf..d800056 100755
--- a/environment.py
+++ b/environment.py
@@ -75,7 +75,7 @@ class CCompiler():
if suffix == 'c' or suffix == 'h':
return True
return False
-
+
def get_pic_flags(self):
return ['-fPIC']
@@ -91,11 +91,11 @@ class CCompiler():
pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
pc.wait()
if pc.returncode != 0:
- raise RuntimeError('Compiler %s can not compile programs.' % self.name_string())
+ raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
pe = subprocess.Popen(binary_name)
pe.wait()
if pe.returncode != 0:
- raise RuntimeError('Executables created by C compiler %s are not runnable.' % self.name_string())
+ raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string())
class CXXCompiler(CCompiler):
def __init__(self, exelist):
@@ -118,11 +118,36 @@ class CXXCompiler(CCompiler):
pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
pc.wait()
if pc.returncode != 0:
- raise RuntimeError('Compiler %s can not compile programs.' % self.name_string())
+ raise EnvironmentException('Compiler %s can not compile programs.' % self.name_string())
pe = subprocess.Popen(binary_name)
pe.wait()
if pe.returncode != 0:
- raise RuntimeError('Executables created by C++ compiler %s are not runnable.' % self.name_string())
+ raise EnvironmentException('Executables created by C++ compiler %s are not runnable.' % self.name_string())
+
+class ObjCCompiler(CCompiler):
+ def __init__(self, exelist):
+ CCompiler.__init__(self, exelist)
+
+ def can_compile(self, filename):
+ suffix = filename.split('.')[-1]
+ if suffix == 'm' or suffix == 'h':
+ return True
+ return False
+
+ def sanity_check(self, work_dir):
+ source_name = os.path.join(work_dir, 'sanitycheckobjc.m')
+ binary_name = os.path.join(work_dir, 'sanitycheckobjc')
+ ofile = open(source_name, 'w')
+ ofile.write('#import<stdio.h>\nint main(int argc, char **argv) { return 0; }\n')
+ ofile.close()
+ pc = subprocess.Popen(self.exelist + [source_name, '-o', binary_name])
+ pc.wait()
+ if pc.returncode != 0:
+ raise EnvironmentException('ObjC compiler %s can not compile programs.' % self.name_string())
+ pe = subprocess.Popen(binary_name)
+ pe.wait()
+ if pe.returncode != 0:
+ raise EnvironmentException('Executables created by ObjC compiler %s are not runnable.' % self.name_string())
class GnuCCompiler(CCompiler):
std_warn_flags = ['-Wall', '-Winvalid-pch']
@@ -140,6 +165,19 @@ class GnuCCompiler(CCompiler):
def get_pch_suffix(self):
return 'gch'
+class GnuObjCCompiler(ObjCCompiler):
+ std_warn_flags = ['-Wall', '-Winvalid-pch']
+ std_opt_flags = ['-O2']
+
+ def get_std_warn_flags(self):
+ return GnuObjCCompiler.std_warn_flags
+
+ def get_std_opt_flags(self):
+ return GnuObjCCompiler.std_opt_flags
+
+ def get_pch_suffix(self):
+ return 'gch'
+
class ClangCCompiler(CCompiler):
std_warn_flags = ['-Wall', '-Winvalid-pch']
std_opt_flags = ['-O2']
@@ -264,6 +302,7 @@ class Environment():
self.default_c = ['cc']
self.default_cxx = ['c++']
+ self.default_objc = ['cc']
self.default_static_linker = ['ar']
if is_windows():
@@ -349,6 +388,19 @@ class Environment():
return ClangCXXCompiler(exelist)
raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
+ def detect_objc_compiler(self):
+ exelist = self.get_objc_compiler_exelist()
+ try:
+ p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE)
+ except OSError:
+ raise EnvironmentException('Could not execute ObjC compiler "%s"' % ' '.join(exelist))
+ out = p.communicate()[0]
+ out = out.decode()
+ if (out.startswith('cc ') or out.startswith('gcc')) and \
+ 'Free Software Foundation' in out:
+ return GnuObjCCompiler(exelist)
+ raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"')
+
def detect_static_linker(self):
exelist = self.get_static_linker_exelist()
try:
@@ -381,7 +433,14 @@ class Environment():
if evar in os.environ:
return os.environ[evar].split()
return ccachelist + self.default_cxx
-
+
+ def get_objc_compiler_exelist(self):
+ ccachelist = self.detect_ccache()
+ evar = 'OBJCC'
+ if evar in os.environ:
+ return os.environ[evar].split()
+ return ccachelist + self.default_objc
+
def get_static_linker_exelist(self):
evar = 'AR'
if evar in os.environ:
diff --git a/interpreter.py b/interpreter.py
index 7308573..639f533 100755
--- a/interpreter.py
+++ b/interpreter.py
@@ -645,6 +645,8 @@ class Interpreter():
comp = self.environment.detect_c_compiler()
elif lang.lower() == 'cxx':
comp = self.environment.detect_cxx_compiler()
+ elif lang.lower() == 'objc':
+ comp = self.environment.detect_objc_compiler()
else:
raise InvalidCode('Tried to use unknown language "%s".' % lang)
comp.sanity_check(self.environment.get_scratch_dir())
diff --git a/test cases/objc/1 simple/meson.build b/test cases/objc/1 simple/meson.build
new file mode 100644
index 0000000..5bad8b0
--- /dev/null
+++ b/test cases/objc/1 simple/meson.build
@@ -0,0 +1,4 @@
+project('objective c', 'objc')
+
+exe = executable('prog', 'prog.m')
+add_test('objctest', exe)
diff --git a/test cases/objc/1 simple/prog.m b/test cases/objc/1 simple/prog.m
new file mode 100644
index 0000000..f2e2315
--- /dev/null
+++ b/test cases/objc/1 simple/prog.m
@@ -0,0 +1,5 @@
+#import<stdio.h>
+
+int main(int argc, char **argv) {
+ return 0;
+} \ No newline at end of file