Remove the last functions which enclose themselves.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 01 Apr 2009 10:59:03 -0400
changeset 244 3dc32b90e1528d57a67d6517cc1b2d4a44f89358
parent 243 fe8f657b547f40e6f94de39defe68087f4128979
child 245 88471ac94e0e95b4d1f111d8a662f407a1d21b66
push id140
push userbsmedberg@mozilla.com
push dateWed, 01 Apr 2009 20:02:29 +0000
Remove the last functions which enclose themselves.
pymake/command.py
pymake/data.py
pymake/parserdata.py
pymake/util.py
--- a/pymake/command.py
+++ b/pymake/command.py
@@ -67,17 +67,17 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO TH
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE."""
 
 _log = logging.getLogger('pymake.execution')
 
-class RemakeContext(object):
+class _MakeContext(object):
     def __init__(self, makeflags, makelevel, workdir, context, env, targets, options, overrides, cb):
         self.makeflags = makeflags
         self.makelevel = makelevel
         print "makelevel: %r" % makelevel
 
         self.workdir = workdir
         self.context = context
         self.env = env
@@ -228,16 +228,16 @@ def main(args, env, cwd, cb):
                 options.makefiles.append('Makefile')
             else:
                 print "No makefile found"
                 cb(2)
                 return
 
         overrides, targets = parserdata.parsecommandlineargs(arguments)
 
-        RemakeContext(makeflags, makelevel, workdir, context, env, targets, options, overrides, cb)
+        _MakeContext(makeflags, makelevel, workdir, context, env, targets, options, overrides, cb)
     except (util.MakeError), e:
         print e
         if options.printdir:
             print "make.py[%i]: Leaving directory '%s'" % (makelevel, workdir)
         sys.stdout.flush()
         cb(2)
         return
--- a/pymake/data.py
+++ b/pymake/data.py
@@ -1263,16 +1263,40 @@ class PatternRule(object):
                 else:
                     stem = p.match(file)
                     if stem is not None:
                         yield PatternRuleInstance(self, dir, stem, False)
 
     def prerequisitesforstem(self, dir, stem):
         return [p.resolve(dir, stem) for p in self.prerequisites]
 
+class _RemakeContext(object):
+    def __init__(self, makefile, remakelist, mtimelist, cb):
+        self.makefile = makefile
+        self.remakelist = remakelist
+        self.mtimelist = mtimelist # list of (target, mtime)
+        self.cb = cb
+
+        self.remakecb(error=False, didanything=False)
+
+    def remakecb(self, error, didanything):
+        assert error in (True, False)
+
+        if error:
+            print "Error remaking makefiles (ignored)"
+
+        if len(self.remakelist):
+            self.remakelist.pop(0).make(self.makefile, [], avoidremakeloop=True, cb=self.remakecb)
+        else:
+            for t, oldmtime in self.mtimelist:
+                if t.mtime != oldmtime:
+                    self.cb(remade=True)
+                    return
+            self.cb(remade=False)
+
 class Makefile(object):
     """
     The top-level data structure for makefile execution. It holds Targets, implicit rules, and other
     state data.
     """
 
     def __init__(self, workdir=None, env=None, restarts=0, make=None, makeflags=None, makelevel=0, context=None, targets=(), keepgoing=False):
         self.defaulttarget = None
@@ -1443,63 +1467,26 @@ class Makefile(object):
         vp = list(self._vpath)
         for p, dirs in self._patternvpaths:
             if p.match(target):
                 vp.extend(dirs)
 
         return withoutdups(vp)
 
     def remakemakefiles(self, cb):
-        reparse = False
-
-        serial = self.context.jcount == 1
-
-        def remakedone():
-            for t, oldmtime in mlist:
-                if t.mtime != oldmtime:
-                    cb(remade=True)
-                    return
-            cb(remade=False)
-
         mlist = []
         for f in self.included:
             t = self.gettarget(f)
             t.explicit = True
             t.resolvevpath(self)
             oldmtime = t.mtime
 
             mlist.append((t, oldmtime))
 
-        if serial:
-            remakelist = [self.gettarget(f) for f in self.included]
-            def remakecb(error, didanything):
-                assert error in (True, False)
-                if error:
-                    print "Error remaking makefiles (ignored)"
-
-                if len(remakelist):
-                    t = remakelist.pop(0)
-                    t.make(self, [], avoidremakeloop=True, cb=remakecb)
-                else:
-                    remakedone()
-
-            remakelist.pop(0).make(self, [], avoidremakeloop=True, cb=remakecb)
-        else:
-            o = util.makeobject(('remakesremaining',), remakesremaining=len(self.included))
-            def remakecb(error, didanything):
-                assert error in (True, False)
-                if error:
-                    print "Error remaking makefiles (ignored)"
-
-                o.remakesremaining -= 1
-                if o.remakesremaining == 0:
-                    remakedone()
-
-            for t, mtime in mlist:
-                t.make(self, [], avoidremakeloop=True, cb=remakecb)
+        _RemakeContext(self, [self.gettarget(f) for f in self.included], mlist, cb)
 
     flagescape = re.compile(r'([\s\\])')
 
     def getsubenvironment(self, variables):
         env = dict(self.env)
         for vname, v in self.exportedvars.iteritems():
             if v:
                 flavor, source, val = variables.get(vname)
--- a/pymake/parserdata.py
+++ b/pymake/parserdata.py
@@ -465,26 +465,29 @@ class EmptyDirective(Statement):
     def execute(self, makefile, context):
         v = self.exp.resolvestr(makefile, makefile.variables)
         if v.strip() != '':
             raise data.DataError("Line expands to non-empty value", self.exp.loc)
 
     def dump(self, fd, indent):
         print >>fd, "%sEmptyDirective: %s" % (indent, self.exp)
 
+class _EvalContext(object):
+    __slots__ = ('currule',)
+
 class StatementList(list):
     __slots__ = ()
 
     def append(self, statement):
         assert isinstance(statement, Statement)
         list.append(self, statement)
 
     def execute(self, makefile, context=None):
         if context is None:
-            context = util.makeobject('currule')
+            context = _EvalContext()
 
         for s in self:
             s.execute(makefile, context)
 
     def dump(self, fd, indent):
         for s in self:
             s.dump(fd, indent)
 
--- a/pymake/util.py
+++ b/pymake/util.py
@@ -1,19 +1,10 @@
 import os
 
-def makeobject(proplist, **kwargs):
-    class P(object):
-        __slots__ = proplist
-
-    p = P()
-    for k, v in kwargs.iteritems():
-        setattr(p, k, v)
-    return p
-
 class MakeError(Exception):
     def __init__(self, message, loc=None):
         self.message = message
         self.loc = loc
 
     def __str__(self):
         locstr = ''
         if self.loc is not None: