aboutsummaryrefslogtreecommitdiff
path: root/environment.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-04-21 17:46:58 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2013-04-21 17:46:58 +0300
commit140f30470b79d2adeef2ea7986ecca0f5f24da76 (patch)
tree5deabbe8fcea76e806b506256236300e98b40404 /environment.py
parent417abe105c3d7bfa2c4753306cf03a9ab89d1f54 (diff)
downloadmeson-140f30470b79d2adeef2ea7986ecca0f5f24da76.zip
meson-140f30470b79d2adeef2ea7986ecca0f5f24da76.tar.gz
meson-140f30470b79d2adeef2ea7986ecca0f5f24da76.tar.bz2
Can run trial compilations on a given compiler.
Diffstat (limited to 'environment.py')
-rwxr-xr-xenvironment.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/environment.py b/environment.py
index 6f89b47..255784e 100755
--- a/environment.py
+++ b/environment.py
@@ -17,6 +17,7 @@
import subprocess, os.path, platform
import coredata
from glob import glob
+import tempfile
build_filename = 'meson.build'
@@ -33,6 +34,7 @@ class CCompiler():
else:
raise TypeError('Unknown argument to CCompiler')
self.language = 'c'
+ self.default_suffix = 'c'
def get_dependency_gen_flags(self, outtarget, outfile):
return ['-MMD', '-MT', outtarget, '-MF', outfile]
@@ -44,10 +46,10 @@ class CCompiler():
return self.language
def get_exelist(self):
- return self.exelist
+ return self.exelist[:]
def get_linker_exelist(self):
- return self.exelist
+ return self.exelist[:]
def get_compile_only_flags(self):
return ['-c']
@@ -102,6 +104,28 @@ class CCompiler():
pe.wait()
if pe.returncode != 0:
raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string())
+
+ def compiles(self, code):
+ suflen = len(self.default_suffix)
+ (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
+ open(srcname, 'w').write(code)
+ commands = self.get_exelist()
+ commands += self.get_compile_only_flags()
+ commands.append(srcname)
+ p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ p.communicate()
+ os.close(fd)
+ os.remove(srcname)
+ try:
+ trial = srcname[:-suflen] + 'o'
+ os.remove(trial)
+ except FileNotFoundError:
+ pass
+ try:
+ os.remove(srcname[:-suflen] + 'obj')
+ except FileNotFoundError:
+ pass
+ return p.returncode == 0
cxx_suffixes = ['cc', 'cpp', 'cxx', 'hh', 'hpp', 'hxx']
@@ -109,6 +133,7 @@ class CXXCompiler(CCompiler):
def __init__(self, exelist):
CCompiler.__init__(self, exelist)
self.language = 'cxx'
+ self.default_suffix = 'cpp'
def can_compile(self, filename):
suffix = filename.split('.')[-1]
@@ -135,7 +160,8 @@ class ObjCCompiler(CCompiler):
def __init__(self, exelist):
CCompiler.__init__(self, exelist)
self.language = 'objc'
-
+ self.default_suffix = 'm'
+
def can_compile(self, filename):
suffix = filename.split('.')[-1]
if suffix == 'm' or suffix == 'h':
@@ -146,6 +172,7 @@ class ObjCXXCompiler(CXXCompiler):
def __init__(self, exelist):
CXXCompiler.__init__(self, exelist)
self.language = 'objcxx'
+ self.default_suffix = 'mm'
def can_compile(self, filename):
suffix = filename.split('.')[-1]
@@ -228,6 +255,8 @@ class VisualStudioCCompiler(CCompiler):
class VisualStudioCXXCompiler(VisualStudioCCompiler):
def __init__(self, exelist):
VisualStudioCCompiler.__init__(self, exelist)
+ self.language = 'cxx'
+ self.default_suffix = 'cpp'
def can_compile(self, filename):
suffix = filename.split('.')[-1]