[pypy-svn] r54838 - in pypy/dist/pypy/translator/tool: . test

arigo at codespeak.net arigo at codespeak.net
Sat May 17 16:42:07 CEST 2008


Author: arigo
Date: Sat May 17 16:42:05 2008
New Revision: 54838

Modified:
   pypy/dist/pypy/translator/tool/cbuild.py
   pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
Separate from_compiler_flags() and from_linker_flags().


Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Sat May 17 16:42:05 2008
@@ -74,23 +74,44 @@
         format."""
         pre_include_lines = []
         include_dirs = []
-        libraries = []
-        library_dirs = []
+        compile_extra = []
         for arg in flags.split():
             if arg.startswith('-I'):
                 include_dirs.append(arg[2:])
-            elif arg.startswith('-L'):
-                library_dirs.append(arg[2:])
-            elif arg.startswith('-l'):
-                libraries.append(arg[2:])
             elif arg.startswith('-D'):
                 pre_include_lines.append('#define %s 1' % (arg[2:],))
+            elif arg.startswith('-L') or arg.startswith('-l'):
+                raise ValueError('linker flag found in compiler options: %r'
+                                 % (arg,))
+            else:
+                compile_extra.append(arg)
         return cls(pre_include_lines=pre_include_lines,
                    include_dirs=include_dirs,
-                   libraries=libraries,
-                   library_dirs=library_dirs)
+                   compile_extra=compile_extra)
     from_compiler_flags = classmethod(from_compiler_flags)
 
+    def from_linker_flags(cls, flags):
+        """Returns a new ExternalCompilationInfo instance by parsing
+        the string 'flags', which is in the typical Unix linker flags
+        format."""
+        libraries = []
+        library_dirs = []
+        link_extra = []
+        for arg in flags.split():
+            if arg.startswith('-L'):
+                library_dirs.append(arg[2:])
+            elif arg.startswith('-l'):
+                libraries.append(arg[2:])
+            elif arg.startswith('-I') or arg.startswith('-D'):
+                raise ValueError('compiler flag found in linker options: %r'
+                                 % (arg,))
+            else:
+                link_extra.append(arg)
+        return cls(libraries=libraries,
+                   library_dirs=library_dirs,
+                   link_extra=link_extra)
+    from_linker_flags = classmethod(from_linker_flags)
+
     def from_config_tool(cls, execonfigtool):
         """Returns a new ExternalCompilationInfo instance by executing
         the 'execonfigtool' with --cflags and --libs arguments."""
@@ -100,8 +121,10 @@
             # we raise ImportError to be nice to the pypy.config.pypyoption
             # logic of skipping modules depending on non-installed libs
         cflags = py.process.cmdexec([str(path), '--cflags'])
+        eci1 = cls.from_compiler_flags(cflags)
         libs = py.process.cmdexec([str(path), '--libs'])
-        return cls.from_compiler_flags(cflags + ' ' + libs)
+        eci2 = cls.from_linker_flags(libs)
+        return eci1.merge(eci2)
     from_config_tool = classmethod(from_config_tool)
 
     def _value(self):

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	Sat May 17 16:42:05 2008
@@ -126,19 +126,24 @@
         assert not neweci.separate_module_files
 
     def test_from_compiler_flags(self):
-        flags = ('-I/some/include/path -L/some/lib/path '
-                 '-I/other/include/path -L/other/lib/path '
-                 '-lmylib1 -lmylib2 '
-                 '-DMACRO1 -D_MACRO2')
+        flags = ('-I/some/include/path -I/other/include/path '
+                 '-DMACRO1 -D_MACRO2 -?1 -!2')
         eci = ExternalCompilationInfo.from_compiler_flags(flags)
         assert eci.pre_include_lines == ('#define MACRO1 1',
                                          '#define _MACRO2 1')
         assert eci.includes == ()
         assert eci.include_dirs == ('/some/include/path',
                                     '/other/include/path')
+        assert eci.compile_extra == ('-?1', '-!2')
+
+    def test_from_linker_flags(self):
+        flags = ('-L/some/lib/path -L/other/lib/path '
+                 '-lmylib1 -lmylib2 -?1 -!2')
+        eci = ExternalCompilationInfo.from_linker_flags(flags)
         assert eci.libraries == ('mylib1', 'mylib2')
         assert eci.library_dirs == ('/some/lib/path',
                                     '/other/lib/path')
+        assert eci.link_extra == ('-?1', '-!2')
 
     def test_from_config_tool(self):
         sdlconfig = py.path.local.sysfind('sdl-config')



More information about the Pypy-commit mailing list