Bug 661267 - Add --tinderbox-print to client.py to output hg revision links for buildbot. r=Standard8
authorPhilippe M. Chiasson <gozer@mozillamessaging.com>
Mon, 20 Jun 2011 15:40:02 -0400
changeset 8201 91d67ba9a6b5fcf536826b283fef17a8fc46eafe
parent 8200 33d556250e18c453d3c88a75b762a267175070e3
child 8202 0f79491664e9d3dabf1ff563e98174fe1aa262c0
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs661267
Bug 661267 - Add --tinderbox-print to client.py to output hg revision links for buildbot. r=Standard8
client.py
--- a/client.py
+++ b/client.py
@@ -23,16 +23,22 @@ DEFAULTS = {
 
   # URL of the default hg repository to clone for Venkman.
   'VENKMAN_REPO': 'http://hg.mozilla.org/venkman/',
 
   # URL of the default hg repository to clone for Mozilla.
   'MOZILLA_REPO': 'http://hg.mozilla.org/mozilla-central/',
 }
 
+REPO_SHORT_NAMES = {
+'mozilla-central':  'moz',
+'dom-inspector':    'dom',
+'ldap-sdks':        'ldap',
+}
+
 def get_DEFAULT_tag(index):
   if index in DEFAULTS:
     return DEFAULTS[index]
   else:
     return DEFAULTS['REV']
 
 # The set of defaults below relate to the current switching mechanism between
 # trunk or branches and back again if it is required.
@@ -86,16 +92,36 @@ except ImportError:
     def check_call(*popenargs, **kwargs):
         retcode = subprocess.call(*popenargs, **kwargs)
         if retcode:
             cmd = kwargs.get("args")
             if cmd is None:
                 cmd = popenargs[0]
                 raise Exception("Command '%s' returned non-zero exit status %i" % (cmd, retcode))
 
+try:
+    from subprocess import check_output
+except ImportError:
+    import subprocess
+    def check_output(*popenargs, **kwargs):
+        if 'stdout' in kwargs:
+            raise ValueError('stdout argument not allowed, it will be overridden.')
+        process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+        output, unused_err = process.communicate()
+        retcode = process.poll()
+        if retcode:
+            cmd = kwargs.get("args")
+            if cmd is None:
+                cmd = popenargs[0]
+            raise CalledProcessError(retcode, cmd, output=output)
+        return output
+
+def check_call_output(cmd, *args, **kwargs):
+    return check_output(cmd, *args, **kwargs)
+
 def check_call_noisy(cmd, retryMax=0, *args, **kwargs):
   """Wrapper around execute_check_call() to allow retries before failing.
 
   |cmd|, is the command to try and execute.
   |retryMax|, is the maximum number of retries to attempt, 0 by default.
   """
 
   def execute_check_call(cmd, *args, **kwargs):
@@ -304,16 +330,27 @@ def do_hg_pull(dir, repository, hg, rev)
         cmd.append('-v')
     # Explicitly never retry 'hg update': otherwise any merge failures are ignored.
     # This command is local: a failure can't be caused by a network error.
     check_call_noisy(cmd, retryMax=0)
 
     check_call([hg, 'parent', '-R', fulldir,
                 '--template=Updated to revision {node}.\n'])
 
+    if options.tinderbox_print and dir != '.':
+        got_rev = check_call_output([hg, 'parent', '-R', fulldir,
+                    '--template={node|short}'])
+
+        url = check_call_output([hg, 'paths', 'default', '-R', fulldir ]).rstrip().rstrip('/')
+        repo_name = url.split('/')[-1]
+        repo_short_name = REPO_SHORT_NAMES.get(repo_name, repo_name)
+
+        print "TinderboxPrint:<a href=%s/rev/%s title='Built from %s revision %s'>%s:%s</a>"  % ( url, got_rev, repo_name, got_rev, repo_short_name, got_rev)
+
+
 def check_retries_option(option, opt_str, value, parser):
   if value < 0:
     raise OptionValueError("%s option value needs to be positive (not '%d')" % (opt_str, value))
   setattr(parser.values, option.dest, value)
 
 def do_apply_patch(hg, patch, repo):
     check_call_noisy([hg, 
         'import', 
@@ -422,16 +459,20 @@ o.add_option("--retries", dest="retries"
 o.add_option("-r", "--rev", dest = "default_rev",
              default = None,
              help = "Revision of all repositories to update to, unless otherwise specified.")
 
 o.add_option("--apply-patches", dest="apply_patches",
              action="store_true", default=False,
              help="Look for and apply local patches (repo*.patch)")
 
+o.add_option("--tinderbox-print", dest="tinderbox_print",
+             action="store_true", default=False,
+             help="Print repo revisions for Tinderbox")
+
 def fixup_comm_repo_options(options):
     """Check options.comm_repo value.
 
     options.comm_repo is normally None.
     This is fine -- our "hg pull" command will omit the repo URL.
     The exception is the initial checkout, which does an "hg clone".
     That command requires a repository URL.
     """