[pypy-svn] r58600 - in pypy/dist/pypy: config rlib translator/tool/test

hpk at codespeak.net hpk at codespeak.net
Sun Oct 5 09:14:11 CEST 2008


Author: hpk
Date: Sun Oct  5 09:14:09 2008
New Revision: 58600

Modified:
   pypy/dist/pypy/config/translationoption.py
   pypy/dist/pypy/rlib/pyplatform.py
   pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
simplifying handling of c compiler
and fixing a problem with caching. 



Modified: pypy/dist/pypy/config/translationoption.py
==============================================================================
--- pypy/dist/pypy/config/translationoption.py	(original)
+++ pypy/dist/pypy/config/translationoption.py	Sun Oct  5 09:14:09 2008
@@ -346,19 +346,15 @@
 ]
 
 def set_platform(config, platform):
-    from pypy.rlib.pyplatform import Platform, Maemo, OverloadCompilerPlatform
+    from pypy.rlib.pyplatform import Platform, Maemo
     from pypy.rlib import pyplatform
     from pypy.translator.tool.cbuild import ExternalCompilationInfo
     if isinstance(platform, str):
         if platform == 'maemo':
-            platform = Maemo()
+            platform = Maemo(cc=config.translation.cc or None)
         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/rlib/pyplatform.py
==============================================================================
--- pypy/dist/pypy/rlib/pyplatform.py	(original)
+++ pypy/dist/pypy/rlib/pyplatform.py	Sun Oct  5 09:14:09 2008
@@ -1,13 +1,19 @@
 
 """ This file contains various platform-specific profiles for
 pypy's cross compilation
+
 """
 
 import py
 
+# XXX i think the below belongs somewhere under pypy/translator 
+
 class Platform(object):
+    def __init__(self, cc=None):
+        self.cc = None
+
     def get_compiler(self):
-        return None
+        return self.cc 
 
     def execute(self, cmd):
         return py.process.cmdexec(cmd)
@@ -25,29 +31,20 @@
                 self.__dict__ == other.__dict__)
 
 class Maemo(Platform):
-    def get_compiler(self):
-        # XXX how to make this reliable???
-        for x in (
-            '/scratchbox/compilers/cs2007q3-glibc2.5-arm7/bin/arm-none-linux-gnueabi-gcc',
-            '/scratchbox/compilers/cs2005q3.2-glibc-arm/bin/sbox-arm-linux-gcc',
-        ):
-            if py.path.local(x).check():
-                return x
-        raise ValueError("could not find scratchbox cross-compiler")
-    
+    def __init__(self, cc=None):
+        if cc is None:
+            for x in (
+                '/scratchbox/compilers/cs2007q3-glibc2.5-arm7/bin/arm-none-linux-gnueabi-gcc',
+                '/scratchbox/compilers/cs2005q3.2-glibc-arm/bin/sbox-arm-linux-gcc',
+            ):
+                if py.path.local(x).check():
+                    cc = x
+            else:
+                raise ValueError("could not find scratchbox cross-compiler")
+        super(Platform, self).__init__(cc=cc)
+        
     def execute(self, cmd):
         return py.process.cmdexec('/scratchbox/login ' + cmd)
 
-class OverloadCompilerPlatform(Platform):
-    def __init__(self, previous_platform, cc):
-        self.previous_platform = previous_platform
-        self.cc = cc
-
-    def get_compiler(self):
-        return self.cc
-
-    def execute(self, cmd):
-        return self.previous_platform.execute(cmd)
-
 platform = Platform()
 

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 Oct  5 09:14:09 2008
@@ -4,6 +4,7 @@
 from pypy.translator.tool.cbuild import build_executable, \
      ExternalCompilationInfo, compile_c_module
 from subprocess import Popen, PIPE, STDOUT
+from pypy.rlib.pyplatform import Maemo
 
 def test_simple_executable(): 
     print udir
@@ -157,16 +158,6 @@
                        ExternalCompilationInfo.from_config_tool,
                        'dxowqbncpqympqhe-config')
 
-    def test_platforms(self):
-        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 == Maemo()
-
     def test_platform(self):
         from pypy.rlib.pyplatform import Platform
         class Expected(Exception):
@@ -200,11 +191,13 @@
         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
+    def checkscratchbox(self):
         if not py.path.local('/scratchbox/login').check():
             py.test.skip("No scratchbox detected")
+
+    def test_standalone_maemo(self):
+        self.checkscratchbox()
+        # XXX skip if there is no scratchbox
         tmpdir = self.tmpdir
         c_file = tmpdir.join('stand1.c')
         c_file.write('''
@@ -226,3 +219,14 @@
         result = eci.platform.execute(output)
         assert result.startswith('4.0')
 
+    def test_platforms(self):
+        self.checkscratchbox()
+        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 == Maemo()
+
+



More information about the Pypy-commit mailing list