aboutsummaryrefslogtreecommitdiff
path: root/environment.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2012-12-26 17:26:58 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2012-12-26 17:26:58 +0200
commit22b162bd0dc4e07aca6d38f208d5f4a8fa11d4df (patch)
treebc529b8a302c051114f64c5c35baced83ee3d03a /environment.py
parentf16feed44ae396ee045f5214407bb150c9347793 (diff)
downloadmeson-22b162bd0dc4e07aca6d38f208d5f4a8fa11d4df.zip
meson-22b162bd0dc4e07aca6d38f208d5f4a8fa11d4df.tar.gz
meson-22b162bd0dc4e07aca6d38f208d5f4a8fa11d4df.tar.bz2
Check that the C compiler can produce valid executables.
Diffstat (limited to 'environment.py')
-rwxr-xr-xenvironment.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/environment.py b/environment.py
index e4bb2ff..3209970 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']