aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-08-24 23:10:44 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2013-08-24 23:10:44 +0300
commit211781482634dd53e068b4b78f0b3dd624f2a27f (patch)
treebb4d826cc1884c9ea49f00ca07618f2d34f89035
parent07f87b113e25a26b1c9f05028a3a7621162860ac (diff)
downloadmeson-211781482634dd53e068b4b78f0b3dd624f2a27f.zip
meson-211781482634dd53e068b4b78f0b3dd624f2a27f.tar.gz
meson-211781482634dd53e068b4b78f0b3dd624f2a27f.tar.bz2
Get sizeof info from cross file if it exists and write an error if it can not be determined.
-rw-r--r--cross/ubuntu-armhf.txt8
-rw-r--r--environment.py39
-rw-r--r--interpreter.py9
-rwxr-xr-xrun_cross_test.py1
4 files changed, 46 insertions, 11 deletions
diff --git a/cross/ubuntu-armhf.txt b/cross/ubuntu-armhf.txt
new file mode 100644
index 0000000..3363d7c
--- /dev/null
+++ b/cross/ubuntu-armhf.txt
@@ -0,0 +1,8 @@
+name = 'linux'
+c = '/usr/bin/arm-linux-gnueabihf-gcc'
+cpp = '/usr/bin/arm-linux-gnueabihf-g++'
+root = '/usr/arm-linux-gnueabihf'
+pkg-config = '/usr/bin/arm-linux-gnueabihf-pkg-config'
+
+sizeof_int = 4
+sizeof_wchar_t = 4
diff --git a/environment.py b/environment.py
index 1625b44..9be73f6 100644
--- a/environment.py
+++ b/environment.py
@@ -16,10 +16,15 @@ import subprocess, os.path, platform
import coredata
from glob import glob
import tempfile
+from coredata import MesonException
build_filename = 'meson.build'
-class EnvironmentException(Exception):
+class EnvironmentException(MesonException):
+ def __init(self, *args, **kwargs):
+ Exception.__init__(self, *args, **kwargs)
+
+class CrossNoRunException(Exception):
def __init(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)
@@ -166,7 +171,7 @@ class CCompiler():
def run(self, code):
if self.is_cross and self.exe_wrapper is None:
- raise EnvironmentException('Can not run test applications in this cross environment.')
+ raise CrossNoRunException('Can not run test applications in this cross environment.')
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
ofile = open(srcname, 'w')
@@ -190,7 +195,7 @@ class CCompiler():
os.remove(exename)
return RunResult(True, pe.returncode, so.decode(), se.decode())
- def sizeof(self, element, prefix):
+ def sizeof(self, element, prefix, env):
templ = '''#include<stdio.h>
%s
@@ -199,7 +204,23 @@ int main(int argc, char **argv) {
return 0;
};
'''
- res = self.run(templ % (prefix, element))
+ varname = 'sizeof ' + element
+ varname = varname.replace(' ', '_')
+ if self.is_cross:
+ val = env.cross_info.get(varname)
+ if val is not None:
+ if isinstance(val, int):
+ return val
+ raise EnvironmentException('Cross variable {0} is not an integer.'.format(varname))
+ cross_failed = False
+ try:
+ res = self.run(templ % (prefix, element))
+ except CrossNoRunException:
+ cross_failed = True
+ if cross_failed:
+ message = '''Can not determine size of {0} because cross compiled binaries are not runnable.
+Please define the corresponding variable {1} in your cross compilation definition file.'''.format(element, varname)
+ raise EnvironmentException(message)
if not res.compiled:
raise EnvironmentException('Could not compile sizeof test.')
if res.returncode != 0:
@@ -1033,9 +1054,13 @@ class CrossBuildInfo():
if not 'name' in self:
raise EnvironmentException('Cross file must specify "name".')
+ def ok_type(self, i):
+ return isinstance(i, str) or isinstance(i, int)
+
def parse_datafile(self, filename):
# This is a bit hackish at the moment.
- for linenum, line in enumerate(open(filename)):
+ for i, line in enumerate(open(filename)):
+ linenum = i+1
line = line.strip()
if line == '':
continue
@@ -1049,11 +1074,11 @@ class CrossBuildInfo():
res = eval(value, {})
except Exception:
raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum))
- if isinstance(res, str):
+ if self.ok_type(res):
self.items[varname] = res
elif isinstance(res, list):
for i in res:
- if not isinstance(i, str):
+ if not self.ok_type(i):
raise EnvironmentException('Malformed line in cross file %s:%d.' % (filename, linenum))
self.items[varname] = res
else:
diff --git a/interpreter.py b/interpreter.py
index 13b916a..7cbdfb9 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -654,9 +654,10 @@ class Test(InterpreterObject):
return self.name
class CompilerHolder(InterpreterObject):
- def __init__(self, compiler):
+ def __init__(self, compiler, env):
InterpreterObject.__init__(self)
self.compiler = compiler
+ self.environment = env
self.methods.update({'compiles': self.compiles_method,
'get_id': self.get_id_method,
'sizeof': self.sizeof_method,
@@ -749,7 +750,7 @@ class CompilerHolder(InterpreterObject):
prefix = kwargs.get('prefix', '')
if not isinstance(prefix, str):
raise InterpreterException('Prefix argument of sizeof must be a string.')
- esize = self.compiler.sizeof(element, prefix)
+ esize = self.compiler.sizeof(element, prefix, self.environment)
mlog.log('Checking for size of "%s": %d' % (element, esize))
return esize
@@ -794,14 +795,14 @@ class MesonMain(InterpreterObject):
InterpreterObject.__init__(self)
self.build = build
self.methods.update({'get_compiler': self.get_compiler_method})
-
+
def get_compiler_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('get_compiler_method must have one and only one argument.')
cname = args[0]
for c in self.build.compilers:
if c.get_language() == cname:
- return CompilerHolder(c)
+ return CompilerHolder(c, self.build.environment)
raise InterpreterException('Tried to access compiler for unspecified language "%s".' % cname)
diff --git a/run_cross_test.py b/run_cross_test.py
index d1eb689..093f30d 100755
--- a/run_cross_test.py
+++ b/run_cross_test.py
@@ -78,6 +78,7 @@ def run_tests():
except OSError:
pass
print('\nRunning cross compilation tests.\n')
+ commontests = commontests[:28] + commontests[28:]
[run_test(t) for t in commontests]
if __name__ == '__main__':