Commits

Maciej Fijalkowski committed 99eb704 Merge

merge

Comments (0)

Files changed (4)

pypy/rpython/module/ll_os_stat.py

         _compilation_info_ = compilation_info
         STAT_STRUCT = platform.Struct('struct %s' % _name_struct_stat, LL_STAT_FIELDS)
     try:
-        config = platform.configure(CConfig)
+        config = platform.configure(CConfig, ignore_errors=
+                                    try_to_add is not None)
     except platform.CompilationError:
         if try_to_add:
             return    # failed to add this field, give up

pypy/rpython/tool/rffi_platform.py

         eci = self.config._compilation_info_
         try_compile_cache([self.path], eci)
 
-def configure(CConfig):
+def configure(CConfig, ignore_errors=False):
     """Examine the local system by running the C compiler.
     The CConfig class contains CConfigEntry attribues that describe
     what should be inspected; configure() returns a dict mapping
         writer.close()
 
         eci = CConfig._compilation_info_
-        infolist = list(run_example_code(writer.path, eci))
+        infolist = list(run_example_code(writer.path, eci,
+                                         ignore_errors=ignore_errors))
         assert len(infolist) == len(entries)
 
         resultinfo = {}
 }
 """
 
-def run_example_code(filepath, eci):
+def run_example_code(filepath, eci, ignore_errors=False):
     eci = eci.convert_sources_to_files(being_main=True)
     files = [filepath]
-    output = build_executable_cache(files, eci)
+    output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
     section = None
     for line in output.splitlines():
         line = line.strip()

pypy/tool/gcc_cache.py

     hash = md5(key).hexdigest()
     return cache_dir.join(hash)
 
-def build_executable_cache(c_files, eci):
+def build_executable_cache(c_files, eci, ignore_errors=False):
     "Builds and run a program; caches the result"
     # Import 'platform' every time, the compiler may have been changed
     from pypy.translator.platform import platform
     try:
         return path.read()
     except py.error.Error:
-        result = platform.execute(platform.compile(c_files, eci))
+        _previous = platform.log_errors
+        try:
+            if ignore_errors:
+                platform.log_errors = False
+            result = platform.execute(platform.compile(c_files, eci))
+        finally:
+            if ignore_errors:
+                del platform.log_errors
+            # ^^^remove from the instance --- needed so that it can
+            # compare equal to another instance without it
+            if platform.log_errors != _previous:
+                platform.log_errors = _previous
         path.write(result.out)
         return result.out
 

pypy/tool/test/test_gcc_cache.py

     finally:
         sys.stderr = oldstderr
     assert 'ERROR' not in capture.getvalue().upper()
+
+def test_execute_code_ignore_errors():
+    f = localudir.join('z.c')
+    f.write("""this file is not valid C code\n""")
+    eci = ExternalCompilationInfo()
+    oldstderr = sys.stderr
+    try:
+        sys.stderr = capture = cStringIO.StringIO()
+        py.test.raises(CompilationError, build_executable_cache,
+                       [f], eci, True)
+    finally:
+        sys.stderr = oldstderr
+    assert 'ERROR' not in capture.getvalue().upper()
+