diff --git a/environment.py b/environment.py index e4bb2fff5..32099703a 100755 --- a/environment.py +++ b/environment.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import subprocess +import subprocess, os.path class EnvironmentException(Exception): def __init(self, text): @@ -32,7 +32,12 @@ def detect_c_compiler(execmd): class CCompiler(): def __init__(self, exelist): - self.exelist = exelist + if type(exelist) == type(''): + self.exelist = [exelist] + elif type(exelist) == type([]): + self.exelist = exelist + else: + raise TypeError('Unknown argument to CCompiler') def get_exelist(self): return self.exelist @@ -48,6 +53,24 @@ class CCompiler(): if suffix == 'c' or suffix == 'h': return True return False + + def name_string(self): + return ' '.join(self.exelist) + + def sanity_check(self, work_dir): + source_name = os.path.join(work_dir, 'sanitycheck.c') + binary_name = os.path.join(work_dir, 'sanitycheck') + ofile = open(source_name, 'w') + ofile.write('int 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 RuntimeError('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 compiler %s are not runnable.' % self.name_string()) class GnuCCompiler(CCompiler): std_warn_flags = ['-Wall', '-Winvalid-pch'] diff --git a/runbuilder.py b/runbuilder.py index beeb53706..2e21527df 100755 --- a/runbuilder.py +++ b/runbuilder.py @@ -17,6 +17,7 @@ from optparse import OptionParser import sys, stat import os.path +import environment parser = OptionParser() @@ -30,6 +31,8 @@ class Builder(): def __init__(self, dir1, dir2, options): (self.source_dir, self.build_dir) = self.validate_dirs(dir1, dir2) + self.compiler = environment.GnuCCompiler('gcc') + self.compiler.sanity_check(self.build_dir) def has_builder_file(self, dirname): fname = os.path.join(dirname, Builder.builder_filename)