Commits

mattip  committed 7fb7c92

implement for posix, fix test for posix and pep8 cleanup

  • Participants
  • Parent commits 8ceff85
  • Branches precompiled-headers

Comments (0)

Files changed (3)

File rpython/translator/platform/posix.py

             ('CC_LINK', eci.use_cpp_linker and 'g++' or '$(CC)'),
             ('LINKFILES', eci.link_files),
             ]
-        for args in definitions:
-            m.definition(*args)
 
         rules = [
             ('all', '$(DEFAULT_TARGET)', []),
             ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES) $(LDFLAGS)'),
-            ('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'),
             ('%.o', '%.cxx', '$(CXX) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'),
             ]
 
+        if len(headers_to_precompile)>0:
+            stdafx_h = path.join('stdafx.h')
+            txt  = '#ifndef PYPY_STDAFX_H\n'
+            txt += '#define PYPY_STDAFX_H\n'
+            txt += '\n'.join(['#include "' + m.pathrel(c) + '"' for c in headers_to_precompile])
+            txt += '\n#endif\n'
+            stdafx_h.write(txt)
+            rules.append(('$(OBJECTS)', 'stdafx.h.gch', []))
+            rules.append(('%.h.gch', '%.h',
+                    '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'))
+            rules.append(('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -include stdafx.h -o $@ -c $< $(INCLUDEDIRS)'))
+        else:
+            rules.append(('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'))
+
+        for args in definitions:
+            m.definition(*args)
         for rule in rules:
             m.rule(*rule)
 

File rpython/translator/platform/test/test_makefile.py

 from StringIO import StringIO
 import re, sys
 
+import time
+if sys.platform == 'win32':
+    get_time = time.clock
+else:
+    get_time = time.time
+
+
 def test_simple_makefile():
     m = Makefile()
     m.definition('CC', 'xxx')
     m.write(s)
     val = s.getvalue()
     assert not re.search('CC += +xxx', val, re.M)
-    assert re.search('CC += +yyy', val, re.M)    
+    assert re.search('CC += +yyy', val, re.M)
 
 class TestMakefile(object):
     platform = host
         assert res.out == expected
         if self.strict_on_stderr:
             assert res.err == ''
-        assert res.returncode == 0        
-    
+        assert res.returncode == 0
+
     def test_900_files(self):
         txt = '#include <stdio.h>\n'
         for i in range(900):
             txt += 'int func%03d();\n' % i
-        txt += 'int main() {\n    int j=0;'    
+        txt += 'int main() {\n    int j=0;'
         for i in range(900):
             txt += '    j += func%03d();\n' % i
         txt += '    printf("%d\\n", j);\n'
         self.check_res(res, '%d\n' %sum(range(900)))
 
     def test_precompiled_headers(self):
-        import time
         tmpdir = udir.join('precompiled_headers').ensure(dir=1)
         # Create an eci that should not use precompiled headers
         eci = ExternalCompilationInfo(include_dirs=[tmpdir])
         eci.separate_module_files = [main_c]
         ncfiles = 10
         nprecompiled_headers = 20
-        txt = ''
+        txt = '#include <stdio.h>\n'
         for i in range(ncfiles):
             txt += "int func%03d();\n" % i
         txt += "\nint main(int argc, char * argv[])\n"
             for j in range(3000):
                 txt += "int pcfunc%03d_%03d();\n" %(i, j)
             txt += '#endif'
-            pch_name.write(txt)    
-            cfiles_precompiled_headers.append(pch_name)        
+            pch_name.write(txt)
+            cfiles_precompiled_headers.append(pch_name)
         # Create some cfiles with headers we want precompiled
         cfiles = []
         for i in range(ncfiles):
                 txt += '#include "%s"\n' % pch_name
             txt += "int func%03d(){ return %d;};\n" % (i, i)
             c_name.write(txt)
-            cfiles.append(c_name)        
+            cfiles.append(c_name)
         if sys.platform == 'win32':
             clean = ('clean', '', 'for %f in ( $(OBJECTS) $(TARGET) ) do @if exist %f del /f %f')
-        else:    
+        else:
             clean = ('clean', '', 'rm -f $(OBJECTS) $(TARGET) ')
         #write a non-precompiled header makefile
         mk = self.platform.gen_makefile(cfiles, eci, path=tmpdir)
         mk.rule(*clean)
         mk.write()
-        t0 = time.clock()
+        t0 = get_time()
         self.platform.execute_makefile(mk)
-        t1 = time.clock()
+        t1 = get_time()
         t_normal = t1 - t0
         self.platform.execute_makefile(mk, extra_opts=['clean'])
         # Write a super-duper makefile with precompiled headers
                            headers_to_precompile=cfiles_precompiled_headers,)
         mk.rule(*clean)
         mk.write()
-        t0 = time.clock()
+        t0 = get_time()
         self.platform.execute_makefile(mk)
-        t1 = time.clock()
+        t1 = get_time()
         t_precompiled = t1 - t0
         res = self.platform.execute(mk.exe_name)
         self.check_res(res, '%d\n' %sum(range(ncfiles)))
         print "precompiled haeder 'make' time %.2f, non-precompiled header time %.2f" %(t_precompiled, t_normal)
-        assert t_precompiled < t_normal * 0.5
+        assert t_precompiled < t_normal * 0.8
 
-   
+

File rpython/translator/platform/windows.py

     raise Exception("Win64 is not supported.  You must either build for Win32"
                     " or contribute the missing support in PyPy.")
     return _get_compiler_type(cc, True)
-    
+
 def _get_msvc_env(vsver, x64flag):
     try:
         toolsdir = os.environ['VS%sCOMNTOOLS' % vsver]
     name = "msvc"
     so_ext = 'dll'
     exe_ext = 'exe'
-    
+
     relevant_environ = ('PATH', 'INCLUDE', 'LIB')
 
     cc = 'cl.exe'
     standalone_only = ()
     shared_only = ()
     environ = None
-    
+
     def __init__(self, cc=None, x64=False):
         self.x64 = x64
         msvc_compiler_environ = find_msvc_env(x64)
         else:
             masm32 = 'ml.exe'
             masm64 = 'ml64.exe'
-        
+
         if x64:
             self.masm = masm64
         else:
             definitions.append(('CREATE_PCH', '/Ycstdafx.h /Fpstdafx.pch /FIstdafx.h'))
             definitions.append(('USE_PCH', '/Yustdafx.h /Fpstdafx.pch /FIstdafx.h'))
             rules.append(('$(OBJECTS)', 'stdafx.pch', []))
-            rules.append(('stdafx.pch', 'stdafx.h', 
+            rules.append(('stdafx.pch', 'stdafx.h',
                '$(CC) stdafx.c /c /nologo $(CFLAGS) $(CFLAGSEXTRA) '
                '$(CREATE_PCH) $(INCLUDEDIRS)'))
-            rules.append(('.c.obj', '', 
+            rules.append(('.c.obj', '',
                     '$(CC) /nologo $(CFLAGS) $(CFLAGSEXTRA) $(USE_PCH) '
                     '/Fo$@ /c $< $(INCLUDEDIRS)'))
             #Do not use precompiled headers for some files
                         '/Fo%s /c %s $(INCLUDEDIRS)' %(target, f)))
 
         else:
-            rules.append(('.c.obj', '', 
+            rules.append(('.c.obj', '',
                           '$(CC) /nologo $(CFLAGS) $(CFLAGSEXTRA) '
                           '/Fo$@ /c $< $(INCLUDEDIRS)'))
 
 
         for rule in rules:
             m.rule(*rule)
-        
+
         objects = ' $(OBJECTS)'
         create_obj_response_file = []
         if len(' '.join(rel_ofiles)) > 4000:
             for i in range(len(rel_ofiles) - 1):
                 create_obj_response_file.append('echo %s >> obj_names.rsp' % \
                                                 rel_ofiles[i])
-            # use cmd /c for the last one so that the file is flushed 
+            # use cmd /c for the last one so that the file is flushed
             create_obj_response_file.append('cmd /c echo %s >> obj_names.rsp' % \
                                             rel_ofiles[-1])
             objects = ' @obj_names.rsp'