aboutsummaryrefslogtreecommitdiff
path: root/environment.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-06-01 00:35:11 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2013-06-01 00:35:11 +0300
commitae62e8ca11b08b9b554b83b48e743f672708ace5 (patch)
treed1aa4853fec86d0a4150c49418c8c81a87920a61 /environment.py
parent3872cd024e8dcf4f4e3eabf9d9060c0433113027 (diff)
downloadmeson-ae62e8ca11b08b9b554b83b48e743f672708ace5.zip
meson-ae62e8ca11b08b9b554b83b48e743f672708ace5.tar.gz
meson-ae62e8ca11b08b9b554b83b48e743f672708ace5.tar.bz2
Can detect sizes of expressions.
Diffstat (limited to 'environment.py')
-rwxr-xr-xenvironment.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/environment.py b/environment.py
index e6c25aa..00cc4e4 100755
--- a/environment.py
+++ b/environment.py
@@ -133,6 +133,35 @@ class CCompiler():
pass
return p.returncode == 0
+ def sizeof(self, element):
+ templ = '''#include<stdio.h>
+int main(int argc, char **argv) {
+ printf("%%ld\\n", (long)(sizeof(%s)));
+ return 0;
+};
+'''
+ (fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
+ exename = srcname + '.exe' # Is guaranteed to be executable on every platform.
+ os.close(fd)
+ ofile = open(srcname, 'w')
+ code = templ % element
+ ofile.write(code)
+ ofile.close()
+ commands = self.get_exelist()
+ commands.append(srcname)
+ commands += self.get_output_flags(exename)
+ p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0])#s, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ p.communicate()
+ os.remove(srcname)
+ if p.returncode != 0:
+ raise EnvironmentException('Could not compile sizeof test.')
+ pe = subprocess.Popen(exename, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ so = pe.communicate()[0]
+ os.remove(exename)
+ if pe.returncode != 0:
+ raise EnvironmentException('Could not run sizeof test binary.')
+ return int(so.decode())
+
cxx_suffixes = ['cc', 'cpp', 'cxx', 'hh', 'hpp', 'hxx']
class CXXCompiler(CCompiler):