Bug 1299078 - Use lastRevFunc instead of lastGoodFunc. seamonkey-production
authorEdmund Wong <ewong@pw-wspx.org>
Thu, 06 Oct 2016 11:15:47 +0800
branchseamonkey-production
changeset 5002 1b07611cd6c4b7d7c7d4ac395fc22e3dd895209b
parent 5001 7f08d03ac77488499fd2ac2638c0549d9417cf6d
child 5003 8d679233c00e1f1ef3fb163ffd1e7eefb54923b0
push id4223
push userewong@pw-wspx.org
push dateThu, 06 Oct 2016 03:18:51 +0000
bugs1299078
Bug 1299078 - Use lastRevFunc instead of lastGoodFunc.
misc.py
misc_scheduler.py
--- a/misc.py
+++ b/misc.py
@@ -54,17 +54,17 @@ from buildbotcustom.process.factory impo
 from buildbotcustom.process.factory import RemoteUnittestFactory
 from buildbotcustom.scheduler import MultiScheduler, BuilderChooserScheduler, \
     PersistentScheduler, makePropertiesScheduler, SpecificNightly
 from buildbotcustom.l10n import TriggerableL10n
 from buildbotcustom.status.mail import MercurialEmailLookup, ChangeNotifier
 from buildbotcustom.status.generators import buildTryChangeMessage
 from buildbotcustom.env import MozillaEnvironments
 from buildbotcustom.misc_scheduler import tryChooser, buildIDSchedFunc, \
-    buildUIDSchedFunc, lastGoodFunc
+    buildUIDSchedFunc, lastGoodFunc, lastRevFunc
 from buildbotcustom.status.log_handlers import SubprocessLogHandler
 from build.paths import getRealpath
 
 # This file contains misc. helper function that don't make sense to put in
 # other files. For example, functions that are called in a master.cfg
 
 def get_l10n_repositories(file, l10nRepoPath, relbranch):
     """Reads in a list of locale names and revisions for their associated
@@ -1971,21 +1971,22 @@ def generateCCBranchObjects(config, name
             builderNames=test_builders,
             treeStableTimer=None,
             **extra_args
         ))
 
     # Now, setup the nightly en-US schedulers and maybe,
     # their downstream l10n ones
     if nightlyBuilders or xulrunnerNightlyBuilders:
-        goodFunc = lastGoodFunc(
+        goodFunc = lastRevFunc(
                 branch=config['repo_path'],
                 builderNames=builders,
-                triggerBuildIfNoChanges=False,
-                l10nBranch=config.get('l10n_repo_path')
+                triggerBuildIfNoChanges=True,
+                l10nBranch=config.get('l10n_repo_path'),
+                forceBuildLastChange=False,
                 )
 
         nightly_scheduler = makePropertiesScheduler(
                 SpecificNightly,
                 [buildIDSchedFunc, buildUIDSchedFunc])(
                     ssFunc=goodFunc,
                     name="%s nightly" % name,
                     branch=config['repo_path'],
--- a/misc_scheduler.py
+++ b/misc_scheduler.py
@@ -244,16 +244,37 @@ def getLastBuiltRevision(db, t, branch, 
             )
 
     t.execute(q, (branch,) + tuple(builderNames))
     result = t.fetchone()
     if result:
         return result[0]
     return None
 
+def getLastBuiltRevisions(db, t, branch, builderNames, limit=5):
+    """ Returns the latest revision that was built on builderNames """
+    # Find the latest revision web uilt on any of the builderNames
+
+    q = db.quoteq("""SELECT sourcestamps.revision FROM
+                buildrequests, buildsets, sourcestamps
+            WHERE
+                buildrequests.buildsetid = buildsets.id AND
+                buildsets.sourcestampid = sourcestamps.id AND
+                sourcestamps.branch = ? AND
+                buildrequests.buildername IN %s
+            ORDER BY
+                buildsets.submitted_at DESC
+            LIMIT ?""" % db.parmlist(len(builderNames)))
+
+    t.execute(q, (branch,) + tuple(builderNames) + (limit,))
+    retval = []
+    for row in t.fetchall():
+        retval.append(row[0])
+    return retval
+
 def lastGoodFunc(branch, builderNames, triggerBuildIfNoChanges=True, l10nBranch=None):
     """Returns a function that returns the latest revision on branch that was
     green for all builders in builderNames.
 
     If unable to find an all green build, fall back to the latest known
     revision on this branch, or the tip of the default branch if we don't know
     anything about this branch.
 
@@ -309,8 +330,36 @@ def lastGoodFunc(branch, builderNames, t
             # Make sure that rev is newer than the last revision we built.
             later_rev = getLatestRev(db, t, branch, rev, last_built_rev)
             if later_rev != rev:
                 log.msg("lastGoodRev: Building %s since it's newer than %s" %
                         (later_rev, rev))
                 rev = later_rev
         return SourceStamp(branch=scheduler.branch, revision=rev)
     return ssFunc
+
+def lastRevFunc(branch, builderNames, triggerBuildIfNoChanges=True, l10nBranch=None, forceBuildLastChange=True):
+    """Returns a function that returns the latest revision on branch. """
+    def ssFunc(scheduler, t):
+        db = scheduler.parent.db
+
+        c = lastChange(db, t, branch)
+        if not c: 
+            log.msg("No last change")
+
+        if not c:
+            return None
+
+        rev = c.revision
+
+        if not forceBuildLastChange:
+            last_built_revs = getLastBuiltRevisions(db, t, branch,
+                                                    builderNames)
+            log.msg("lastBuiltRevisions: %s" % last_built_revs)
+
+            if last_built_revs:
+                # make sre that rev is newer than the last revision we built
+                later_rev = getLatestRev(db, t, branch, rev, last_built_revs[0])
+                if later_rev in last_built_revs and not triggerBuildIfNoChanges:
+                    log.msg("lastGoodRev: Skipping %s since we've already built it" % rev)
+                    return None
+        return SourceStamp(branch=scheduler.branch, revision=rev)
+    return ssFunc