[pypy-svn] r59110 - in pypy/branch/cbuild-refactor/pypy: rlib translator/platform

fijal at codespeak.net fijal at codespeak.net
Wed Oct 15 17:02:42 CEST 2008


Author: fijal
Date: Wed Oct 15 17:02:42 2008
New Revision: 59110

Modified:
   pypy/branch/cbuild-refactor/pypy/rlib/libffi.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/darwin.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py
   pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py
Log:
Enough abstraction to have libffi platform-independent (at least a bit)


Modified: pypy/branch/cbuild-refactor/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/rlib/libffi.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/rlib/libffi.py	Wed Oct 15 17:02:42 2008
@@ -19,25 +19,18 @@
 # XXX this need solving rather than hacking. We need to raise something else
 #     than OSError, something capable of delivering a message
 
-_MS_WINDOWS = os.name == "nt"
-_MAC_OS = sys.platform == "darwin"
+from pypy.translator.platform import platform
+
+# maaaybe isinstance here would be better. Think
+_MS_WINDOWS = platform.name == "win32"
+_MAC_OS = platform.name == "darwin"
 
 if _MS_WINDOWS:
     from pypy.rlib import rwin32
 
 if not _MS_WINDOWS:
     includes = ['dlfcn.h', 'ffi.h']
-    include_dirs = []
-    if _MAC_OS:
-        pot_incl = py.path.local('/usr/include/ffi') 
-    else:
-        pot_incl = py.path.local('/usr/include/libffi') 
-    if pot_incl.check():
-        include_dirs.append(str(pot_incl))
-    lib_dirs = []
-    pot_lib = py.path.local('/usr/lib/libffi')
-    if pot_lib.check():
-        lib_dirs.append(str(pot_lib))
+    include_dirs = platform.include_dirs_for_libffi()
 
     if _MAC_OS:
         pre_include_bits = ['#define MACOSX']
@@ -47,8 +40,8 @@
         pre_include_bits = pre_include_bits,
         includes = includes,
         libraries = ['ffi', 'dl'],
-        include_dirs = include_dirs,
-        library_dirs = lib_dirs,
+        include_dirs = platform.include_dirs_for_libffi(),
+        library_dirs = platform.library_dirs_for_libffi(),
     )
 else:
     libffidir = py.path.local(pypydir).join('translator', 'c', 'src', 'libffi_msvc')

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/__init__.py	Wed Oct 15 17:02:42 2008
@@ -24,6 +24,8 @@
         return "<ExecutionResult retcode=%d>" % (self.returncode,)
 
 class Platform(object):
+    name = "abstract platform"
+    
     def __init__(self, cc):
         self.cc = cc
     
@@ -49,6 +51,14 @@
         return (self.__class__ is other.__class__ and
                 self.__dict__ == other.__dict__)
 
+    # below are some detailed informations for platforms
+
+    def include_dirs_for_libffi(self):
+        raise NotImplementedError("Needs to be overwritten")
+
+    def library_dirs_for_libffi(self):
+        raise NotImplementedError("Needs to be overwritten")        
+
     def check___thread(self):
         return True
 

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/darwin.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/darwin.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/darwin.py	Wed Oct 15 17:02:42 2008
@@ -3,6 +3,8 @@
 from pypy.translator.platform import linux # xxx
 
 class Darwin(linux.Linux): # xxx
+    name = "darwin"
+    
     link_flags = []
     cflags = ['-O3', '-fomit-frame-pointer']
     # -mdynamic-no-pic for standalone
@@ -12,3 +14,9 @@
 
     def _args_for_shared(self, args):
         return ['-bundle', '-undefined', 'dynamic_lookup'] + args
+
+    def include_dirs_for_libffi(self):
+        return ['/usr/include/ffi']
+
+    def library_dirs_for_libffi(self):
+        return []

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/linux.py	Wed Oct 15 17:02:42 2008
@@ -108,6 +108,8 @@
             f.close()
 
 class Linux(Platform):
+    name = "linux"
+    
     link_flags = ['-pthread']
     cflags = ['-O3', '-pthread', '-fomit-frame-pointer']
     so_ext = 'so'
@@ -269,3 +271,9 @@
             if len(stderrlines) > 5:
                 log.ERROR('...')
             raise CompilationError(stdout, stderr)
+
+    def include_dirs_for_libffi(self):
+        return ['/usr/include/libffi']
+
+    def library_dirs_for_libffi(self):
+        return ['/usr/lib/libffi']

Modified: pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py
==============================================================================
--- pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py	(original)
+++ pypy/branch/cbuild-refactor/pypy/translator/platform/maemo.py	Wed Oct 15 17:02:42 2008
@@ -8,6 +8,8 @@
         py.test.skip("No scratchbox detected")
 
 class Maemo(Linux):
+    name = "maemo"
+    
     available_includedirs = ['/usr/include', '/tmp']
     copied_cache = {}
 
@@ -65,3 +67,10 @@
                                                      env)
         return ExecutionResult(returncode, stdout, stderr)
 
+    def include_dirs_for_libffi(self):
+        # insanely obscure dir
+        return ['/usr/include/arm-linux-gnueabi/']
+
+    def library_dirs_for_libffi(self):
+        # on the other hand, library lands in usual place...
+        return []



More information about the Pypy-commit mailing list