[pypy-svn] r57625 - in pypy/dist/pypy: tool translator/tool translator/tool/test
fijal at codespeak.net
fijal at codespeak.net
Tue Aug 26 12:23:49 CEST 2008
Author: fijal
Date: Tue Aug 26 12:23:46 2008
New Revision: 57625
Modified:
pypy/dist/pypy/tool/gcc_cache.py
pypy/dist/pypy/translator/tool/cbuild.py
pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
Some support for cross-compilation. Eci can now say how to run and how to
compile targets for different platform.
Modified: pypy/dist/pypy/tool/gcc_cache.py
==============================================================================
--- pypy/dist/pypy/tool/gcc_cache.py (original)
+++ pypy/dist/pypy/tool/gcc_cache.py Tue Aug 26 12:23:46 2008
@@ -20,7 +20,8 @@
try:
return path.read()
except py.error.Error:
- result = py.process.cmdexec(build_executable(c_files, eci))
+ result = py.process.cmdexec(eci.get_emulator_for_platform() +
+ build_executable(c_files, eci))
path.write(result)
return result
Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py (original)
+++ pypy/dist/pypy/translator/tool/cbuild.py Tue Aug 26 12:23:46 2008
@@ -23,7 +23,8 @@
_ATTRIBUTES = ['pre_include_bits', 'includes', 'include_dirs',
'post_include_bits', 'libraries', 'library_dirs',
'separate_module_sources', 'separate_module_files',
- 'export_symbols', 'compile_extra', 'link_extra', 'frameworks']
+ 'export_symbols', 'compile_extra', 'link_extra',
+ 'frameworks']
_DUPLICATES_OK = ['compile_extra', 'link_extra']
def __init__(self,
@@ -38,7 +39,8 @@
export_symbols = [],
compile_extra = [],
link_extra = [],
- frameworks = []):
+ frameworks = [],
+ platform = 'host'):
"""
pre_include_bits: list of pieces of text that should be put at the top
of the generated .c files, before any #include. They shouldn't
@@ -79,11 +81,15 @@
linker. Use this instead of the 'libraries' parameter if you want to
link to a framework bundle. Not suitable for unix-like .dylib
installations.
+
+ platform: an unique identifier of compile platform, useful for
+ caching.
"""
for name in self._ATTRIBUTES:
value = locals()[name]
assert isinstance(value, (list, tuple))
setattr(self, name, tuple(value))
+ self.platform = platform
def from_compiler_flags(cls, flags):
"""Returns a new ExternalCompilationInfo instance by parsing
@@ -196,6 +202,11 @@
s.add(elem)
attr.append(elem)
attrs[name] = attr
+ for other in others:
+ if other.platform != self.platform:
+ raise Exception("Mixing ECI for different platforms %s and %s"%
+ (other.platform, self.platform))
+ attrs['platform'] = self.platform
return ExternalCompilationInfo(**attrs)
def write_c_header(self, fileobj):
@@ -251,6 +262,24 @@
d['separate_module_sources'] = ()
return ExternalCompilationInfo(**d)
+ def get_emulator_for_platform(self):
+ if self.platform == 'host':
+ return ''
+ elif self.platform == 'maemo':
+ # XXX how to do it in better way???
+ return '/scratchbox/login '
+ else:
+ raise NotImplementedError("Platform = %s" % (self.platform,))
+
+ def get_compiler_for_platform(self):
+ if self.platform == 'host':
+ return None
+ elif self.platform == 'maemo':
+ # XXX this should be settable somehow, not sure exactly how
+ return '/scratchbox/compilers/cs2005q3.2-glibc-arm/bin/sbox-arm-linux-gcc'
+ else:
+ raise NotImplementedError("Platform = %s" % (self.platform,))
+
if sys.platform == 'win32':
so_ext = '.dll'
else:
@@ -498,7 +527,10 @@
self.compile_extra = list(eci.compile_extra)
self.link_extra = list(eci.link_extra)
self.frameworks = list(eci.frameworks)
- self.compiler_exe = compiler_exe
+ if compiler_exe is not None:
+ self.compiler_exe = compiler_exe
+ else:
+ self.compiler_exe = eci.get_compiler_for_platform()
self.profbased = profbased
if not sys.platform in ('win32', 'darwin'): # xxx
if 'm' not in self.libraries:
Modified: pypy/dist/pypy/translator/tool/test/test_cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_cbuild.py (original)
+++ pypy/dist/pypy/translator/tool/test/test_cbuild.py Tue Aug 26 12:23:46 2008
@@ -156,3 +156,34 @@
py.test.raises(ImportError,
ExternalCompilationInfo.from_config_tool,
'dxowqbncpqympqhe-config')
+
+ def test_platforms(self):
+ eci = ExternalCompilationInfo(platform='xxx')
+ eci2 = ExternalCompilationInfo()
+ py.test.raises(Exception, eci2.merge, eci)
+ assert eci.merge(eci).platform == 'xxx'
+
+ def test_standalone_maemo(self):
+ # XXX skip if there is no scratchbox
+ if not py.path.local('/scratchbox/login').check():
+ py.test.skip("No scratchbox detected")
+ tmpdir = self.tmpdir
+ c_file = tmpdir.join('stand1.c')
+ c_file.write('''
+ #include <math.h>
+ #include <stdio.h>
+
+ int main()
+ {
+ printf("%f\\n", pow(2.0, 2.0));
+ return 0;
+ }''')
+ if sys.platform == 'win32':
+ py.test.skip("No cross-compilation on windows yet")
+ else:
+ eci = ExternalCompilationInfo(platform='maemo',
+ libraries=['m'])
+ output = build_executable([c_file], eci)
+ py.test.raises(py.process.cmdexec.Error, py.process.cmdexec, output)
+ result = py.process.cmdexec(eci.get_emulator_for_platform() + output)
+ assert result.startswith('4.0')
More information about the Pypy-commit
mailing list