diff options
Diffstat (limited to 'environment.py')
-rwxr-xr-x | environment.py | 29 |
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): |