aboutsummaryrefslogtreecommitdiff
path: root/compilers.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-09-05 15:03:20 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2015-09-05 15:03:20 +0300
commitad5795ed2e2afcd32d89fae68a8682fb647dd194 (patch)
tree89895a897d1531b0010122e85542592cef180a3f /compilers.py
parent2c5688445bfc8a98972d380c17227ec9da0588ae (diff)
downloadmeson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.zip
meson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.tar.gz
meson-ad5795ed2e2afcd32d89fae68a8682fb647dd194.tar.bz2
Converted sizeof check to work also when cross compiling.
Diffstat (limited to 'compilers.py')
-rw-r--r--compilers.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/compilers.py b/compilers.py
index 1e778d3..56b2c8a 100644
--- a/compilers.py
+++ b/compilers.py
@@ -261,8 +261,7 @@ int someSymbolHereJustForFun;
'''
return self.compiles(templ % hname)
- def compiles(self, code):
- mlog.debug('Running compile test:\n\n', code)
+ def compiles(self, code, extra_args = []):
suflen = len(self.default_suffix)
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
@@ -270,8 +269,12 @@ int someSymbolHereJustForFun;
ofile.write(code)
ofile.close()
commands = self.get_exelist()
+ commands += extra_args
commands += self.get_compile_only_args()
commands.append(srcname)
+ mlog.debug('Running compile test.')
+ mlog.debug('Command line: ', ' '.join(commands))
+ mlog.debug('Code:\n', code)
p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stde, stdo) = p.communicate()
stde = stde.decode()
@@ -325,7 +328,24 @@ int someSymbolHereJustForFun;
os.remove(exename)
return RunResult(True, pe.returncode, so, se)
+ def cross_sizeof(self, element, prefix, env):
+ templ = '''%s
+int temparray[%d-sizeof(%s)];
+'''
+ extra_args = []
+ try:
+ extra_args = env.cross_info.config['properties'][self.language + '_args']
+ except KeyError:
+ pass
+ for i in range(1, 1024):
+ code = templ % (prefix, i, element)
+ if self.compiles(code, extra_args):
+ return i
+ raise EnvironmentException('Cross checking sizeof overflowed.')
+
def sizeof(self, element, prefix, env):
+ if self.is_cross:
+ return self.cross_sizeof(element, prefix, env)
templ = '''#include<stdio.h>
%s
@@ -334,23 +354,7 @@ int main(int argc, char **argv) {
return 0;
};
'''
- varname = 'sizeof ' + element
- varname = varname.replace(' ', '_')
- if self.is_cross:
- val = env.cross_info.config['properties'][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)
+ res = self.run(templ % (prefix, element))
if not res.compiled:
raise EnvironmentException('Could not compile sizeof test.')
if res.returncode != 0:
@@ -414,7 +418,7 @@ int main(int argc, char **argv) {
if val is not None:
if isinstance(val, bool):
return val
- raise EnvironmentException('Cross variable {0} is not an boolean.'.format(varname))
+ raise EnvironmentException('Cross variable {0} is not a boolean.'.format(varname))
return self.compiles(templ % (prefix, funcname))
def has_member(self, typename, membername, prefix):