[pypy-svn] r58296 - in pypy/dist/pypy: config rlib tool translator/c translator/c/test translator/tool translator/tool/test
fijal at codespeak.net
fijal at codespeak.net
Sun Sep 21 14:02:58 CEST 2008
Author: fijal
Date: Sun Sep 21 14:02:57 2008
New Revision: 58296
Added:
pypy/dist/pypy/rlib/pyplatform.py
- copied unchanged from r58295, pypy/branch/cross-compilation/pypy/rlib/pyplatform.py
Modified:
pypy/dist/pypy/config/translationoption.py
pypy/dist/pypy/tool/gcc_cache.py
pypy/dist/pypy/translator/c/genc.py
pypy/dist/pypy/translator/c/test/test_standalone.py
pypy/dist/pypy/translator/tool/cbuild.py
pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
Merge cross-compilation branch (without benchmark work)
This contains:
* A bit separated cbuild logic for rffi_platform and friends
* --platform=xxx translation option
* support for maemo target platform
Modified: pypy/dist/pypy/config/translationoption.py
==============================================================================
--- pypy/dist/pypy/config/translationoption.py (original)
+++ pypy/dist/pypy/config/translationoption.py Sun Sep 21 14:02:57 2008
@@ -346,10 +346,19 @@
]
def set_platform(config, platform):
- if platform == 'maemo':
- from pypy.translator.tool.cbuild import ExternalCompilationInfo
- # XXX evil hackery
- func_defs = list(ExternalCompilationInfo.__init__.func_defaults)
- func_defs[-1] = 'maemo'
- ExternalCompilationInfo.__init__.im_func.func_defaults = tuple(func_defs)
-
+ from pypy.rlib.pyplatform import Platform, Maemo, OverloadCompilerPlatform
+ from pypy.rlib import pyplatform
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+ if isinstance(platform, str):
+ if platform == 'maemo':
+ platform = Maemo()
+ elif platform == 'host':
+ return
+ else:
+ raise NotImplementedError('Platform = %s' % (platform,))
+ assert isinstance(platform, Platform)
+ pyplatform.platform = platform
+ if config.translation.cc:
+ pyplatform.platform = OverloadCompilerPlatform(platform,
+ config.translation.cc)
+
Modified: pypy/dist/pypy/tool/gcc_cache.py
==============================================================================
--- pypy/dist/pypy/tool/gcc_cache.py (original)
+++ pypy/dist/pypy/tool/gcc_cache.py Sun Sep 21 14:02:57 2008
@@ -20,8 +20,7 @@
try:
return path.read()
except py.error.Error:
- result = py.process.cmdexec(eci.get_emulator_for_platform() +
- build_executable(c_files, eci))
+ result = eci.platform.execute(build_executable(c_files, eci))
path.write(result)
return result
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Sun Sep 21 14:02:57 2008
@@ -312,7 +312,7 @@
bk = self.translator.annotator.bookkeeper
return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
- def getccompiler(self):
+ def getccompiler(self):
cc = self.config.translation.cc
# Copy extrafiles to target directory, if needed
extrafiles = []
@@ -399,7 +399,9 @@
if self.config.translation.cc:
cc = self.config.translation.cc
else:
- cc = 'gcc'
+ cc = self.eci.platform.get_compiler()
+ if cc is None:
+ cc = 'gcc'
make_no_prof = ''
if self.has_profopt():
profopt = self.config.translation.profopt
Modified: pypy/dist/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_standalone.py (original)
+++ pypy/dist/pypy/translator/c/test/test_standalone.py Sun Sep 21 14:02:57 2008
@@ -1,5 +1,5 @@
import py
-import sys, os
+import sys, os, re
from pypy.rlib.rarithmetic import r_longlong
from pypy.translator.translator import TranslationContext
@@ -226,3 +226,30 @@
assert " ll_strtod.h" in makefile
assert " ll_strtod.o" in makefile
+def test_cross_compilation():
+ from pypy.rlib.pyplatform import Platform
+ from pypy.config.translationoption import set_platform
+
+ class X(Platform):
+ def get_compiler(self):
+ return 'x'
+
+ def entry_point(argv):
+ return 0
+
+ t = TranslationContext()
+ t.buildannotator().build_types(entry_point, [s_list_of_strings])
+ t.buildrtyper().specialize()
+
+ set_platform(t.config, X())
+ try:
+ eci = ExternalCompilationInfo(platform=X())
+
+ cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+ cbuilder.generate_source()
+
+ makefile = udir.join(cbuilder.modulename, 'Makefile').read()
+
+ m = re.search('^CC\s*=\s*x$', makefile)
+ finally:
+ set_platform(t.config, Platform())
Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py (original)
+++ pypy/dist/pypy/translator/tool/cbuild.py Sun Sep 21 14:02:57 2008
@@ -40,7 +40,7 @@
compile_extra = [],
link_extra = [],
frameworks = [],
- platform = 'host'):
+ platform = None):
"""
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
@@ -82,13 +82,15 @@
link to a framework bundle. Not suitable for unix-like .dylib
installations.
- platform: an unique identifier of compile platform, useful for
- caching.
+ platform: an object that can identify the platform
"""
for name in self._ATTRIBUTES:
value = locals()[name]
assert isinstance(value, (list, tuple))
setattr(self, name, tuple(value))
+ if platform is None:
+ from pypy.rlib import pyplatform
+ platform = pyplatform.platform
self.platform = platform
def from_compiler_flags(cls, flags):
@@ -174,6 +176,7 @@
for attr in self._ATTRIBUTES:
val = getattr(self, attr)
info.append("%s=%s" % (attr, repr(val)))
+ info.append("platform=%s" % self.platform.__class__.__name__)
return "<ExternalCompilationInfo (%s)>" % ", ".join(info)
def merge(self, *others):
@@ -263,24 +266,6 @@
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:
@@ -531,7 +516,7 @@
if compiler_exe is not None:
self.compiler_exe = compiler_exe
else:
- self.compiler_exe = eci.get_compiler_for_platform()
+ self.compiler_exe = eci.platform.get_compiler()
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 Sun Sep 21 14:02:57 2008
@@ -158,14 +158,50 @@
'dxowqbncpqympqhe-config')
def test_platforms(self):
- eci = ExternalCompilationInfo(platform='xxx')
+ from pypy.rlib.pyplatform import Maemo
+ eci = ExternalCompilationInfo(platform=Maemo())
eci2 = ExternalCompilationInfo()
assert eci != eci2
assert hash(eci) != hash(eci2)
+ assert repr(eci) != repr(eci2)
py.test.raises(Exception, eci2.merge, eci)
- assert eci.merge(eci).platform == 'xxx'
+ assert eci.merge(eci).platform == Maemo()
+
+ def test_platform(self):
+ from pypy.rlib.pyplatform import Platform
+ class Expected(Exception):
+ pass
+
+ class X(Platform):
+ def get_compiler(self):
+ raise Expected
+
+ def execute(self):
+ return 3
+
+ eci = ExternalCompilationInfo(platform=X())
+ try:
+ build_executable([self.modfile], eci)
+ except Expected:
+ pass
+ else:
+ py.test.fail("Did not raise")
+ assert eci.platform.execute() == 3
+
+ def test_platform_equality(self):
+ from pypy.rlib.pyplatform import Platform
+ class X(Platform):
+ pass
+ class Y(Platform):
+ def __init__(self, x):
+ self.x = x
+
+ assert X() == X()
+ assert Y(3) == Y(3)
+ assert Y(2) != Y(3)
def test_standalone_maemo(self):
+ from pypy.rlib.pyplatform import Maemo
# XXX skip if there is no scratchbox
if not py.path.local('/scratchbox/login').check():
py.test.skip("No scratchbox detected")
@@ -183,9 +219,10 @@
if sys.platform == 'win32':
py.test.skip("No cross-compilation on windows yet")
else:
- eci = ExternalCompilationInfo(platform='maemo',
+ 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)
+ result = eci.platform.execute(output)
assert result.startswith('4.0')
+
More information about the Pypy-commit
mailing list