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

arigo at codespeak.net arigo at codespeak.net
Mon May 19 15:27:17 CEST 2008


Author: arigo
Date: Mon May 19 15:27:15 2008
New Revision: 54931

Modified:
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/goal/timing.py
   pypy/dist/pypy/translator/tool/cbuild.py
   pypy/dist/pypy/translator/tool/taskengine.py
   pypy/dist/pypy/translator/tool/test/test_taskengine.py
Log:
Check early if Boehm is installed or not when starting a translation.


Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Mon May 19 15:27:15 2008
@@ -32,12 +32,14 @@
 }
 
 
-def taskdef(taskfunc, deps, title, new_state=None, expected_states=[], idemp=False):
+def taskdef(taskfunc, deps, title, new_state=None, expected_states=[],
+            idemp=False, earlycheck=None):
     taskfunc.task_deps = deps
     taskfunc.task_title = title
     taskfunc.task_newstate = None
     taskfunc.task_expected_states = expected_states
     taskfunc.task_idempotent = idemp
+    taskfunc.task_earlycheck = earlycheck
     return taskfunc
 
 # TODO:
@@ -460,6 +462,16 @@
         "inserting stack checks")
     STACKCHECKINSERTION = 'stackcheckinsertion_lltype'
 
+    def possibly_check_for_boehm(self):
+        if self.config.translation.gc == "boehm":
+            from pypy.translator.tool.cbuild import check_boehm_presence
+            from pypy.translator.tool.cbuild import CompilationError
+            try:
+                check_boehm_presence(noerr=False)
+            except CompilationError, e:
+                i = 'Boehm GC not installed.  Try e.g. "translate.py --gc=hybrid"'
+                raise CompilationError('%s\n--------------------\n%s' % (e, i))
+
     def task_database_c(self):
         translator = self.translator
         if translator.annotator is not None:
@@ -483,7 +495,8 @@
     #
     task_database_c = taskdef(task_database_c,
                             [STACKCHECKINSERTION, '?'+BACKENDOPT, RTYPE, '?annotate'], 
-                            "Creating database for generating c source")
+                            "Creating database for generating c source",
+                            earlycheck = possibly_check_for_boehm)
     
     def task_source_c(self):  # xxx messy
         translator = self.translator
@@ -828,6 +841,8 @@
 
     # checkpointing support
     def _event(self, kind, goal, func):
+        if kind == 'planned' and func.task_earlycheck:
+            func.task_earlycheck(self)
         if kind == 'pre':
             fork_before = self.config.translation.fork_before
             if fork_before:

Modified: pypy/dist/pypy/translator/goal/timing.py
==============================================================================
--- pypy/dist/pypy/translator/goal/timing.py	(original)
+++ pypy/dist/pypy/translator/goal/timing.py	Mon May 19 15:27:15 2008
@@ -31,7 +31,10 @@
         self.tk = now
 
     def ttime(self):
-        return self.tk - self.t0
+        try:
+            return self.tk - self.t0
+        except AttributeError:
+            return 0.0
 
     def pprint(self):
         """ Pretty print

Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Mon May 19 15:27:15 2008
@@ -587,7 +587,7 @@
     compiler.build(noerr=noerr)
     return str(compiler.outputfilename)
 
-def check_boehm_presence():
+def check_boehm_presence(noerr=True):
     from pypy.tool.udir import udir
     try:
         cfile = udir.join('check_boehm.c')
@@ -605,9 +605,12 @@
             eci = ExternalCompilationInfo(libraries=['gc_pypy'])
         else:
             eci = ExternalCompilationInfo(libraries=['gc'])
-        build_executable([cfname], eci, noerr=True)
+        build_executable([cfname], eci, noerr=noerr)
     except CompilationError:
-        return False
+        if noerr:
+            return False
+        else:
+            raise
     else:
         return True
 

Modified: pypy/dist/pypy/translator/tool/taskengine.py
==============================================================================
--- pypy/dist/pypy/translator/tool/taskengine.py	(original)
+++ pypy/dist/pypy/translator/tool/taskengine.py	Mon May 19 15:27:15 2008
@@ -105,7 +105,11 @@
     def _execute(self, goals, *args, **kwds):
         task_skip = kwds.get('task_skip', [])
         res = None
-        for goal in self._plan(goals, skip=task_skip):
+        goals = self._plan(goals, skip=task_skip)
+        for goal in goals:
+            taskcallable, _ = self.tasks[goal]
+            self._event('planned', goal, taskcallable)
+        for goal in goals:
             taskcallable, _ = self.tasks[goal]
             self._event('pre', goal, taskcallable)
             try:

Modified: pypy/dist/pypy/translator/tool/test/test_taskengine.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_taskengine.py	(original)
+++ pypy/dist/pypy/translator/tool/test/test_taskengine.py	Mon May 19 15:27:15 2008
@@ -86,6 +86,8 @@
     def trace(goals):
         t = []
         for goal in goals:
+            t.append(('planned', goal))
+        for goal in goals:
             t.extend([('pre', goal), goal, ('post', goal)])
         return t
 



More information about the Pypy-commit mailing list