Check that the C compiler can produce valid executables.

pull/15/head
Jussi Pakkanen 12 years ago
parent f16feed44a
commit 22b162bd0d
  1. 25
      environment.py
  2. 3
      runbuilder.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):
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
@ -49,6 +54,24 @@ class CCompiler():
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']
std_opt_flags = ['-O2']

@ -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)

Loading…
Cancel
Save