Commits

Anonymous committed 93f6742

Add Mercurial-specific build version info.
Pilfered from billc.

Comments (0)

Files changed (2)

indra/lib/python/indra/util/llversion.py

 """@file llversion.py
 @brief Utility for parsing llcommon/llversion${server}.h
        for the version string and channel string
-       Utility that parses svn info for branch and revision
+       Utility that parses hg or svn info for branch and revision
 
 $LicenseInfo:firstyear=2006&license=mit$
 
     status, output = commands.getstatusoutput('svn info %s' % get_src_root())
     m = regular_expression.search(output)
     if not m:
-        print "Failed to parse svn info output, resultfollows:"
-        print output
+        print >> sys.stderr, "Failed to parse svn info output, result follows:"
+        print >> sys.stderr, output
         raise Exception, "No matching svn status in "+src_root
     return m.group(1)
 
     last_rev_re = re.compile('Last Changed Rev: (\d+)')
     return get_svn_status_matching(last_rev_re)
 
+def get_hg_repo():
+    status, output = commands.getstatusoutput('hg showconfig paths.default')
+    if status:
+        print >> sys.stderr, output
+        sys.exit(1)
+    if not output:
+        print >> sys.stderr, 'ERROR: cannot find repo we cloned from'
+        sys.exit(1)
+    return output
 
+def get_hg_changeset():
+    status, output = commands.getstatusoutput('hg id -i')
+    if status:
+        print >> sys.stderr, output
+        sys.exit(1)
+    return output
+
+def using_svn():
+    return os.path.isdir(os.path.join(get_src_root(), '.svn'))
+
+def using_hg():
+    return os.path.isdir(os.path.join(get_src_root(), '.hg'))

scripts/update_version_files.py

         if update_server:
             server_version = new_version
     else:
-        # Assume we're updating just the build number
-        cl = '%s info "%s"' % (svn, src_root)
-        status, output = _getstatusoutput(cl)
-        if verbose:
-            print
-            print "svn info output:"
-            print "----------------"
-            print output
 
-        branch_match = svn_branch_re.search(output)
-        revision_match = svn_revision_re.search(output)
-        if not branch_match or not revision_match:
-            print "Failed to execute svn info, output follows:"
-            print output
+        if llversion.using_svn():
+            revision = llversion.get_svn_revision()
+            branch = llversion.get_svn_branch()
+        elif llversion.using_hg():
+            revision = llversion.get_hg_changeset()
+            branch = llversion.get_hg_repo()
+        else:
+            print >>sys.stderr, "ERROR: could not determine revision and branch"
             return -1
-        branch = branch_match.group(1)
-        revision = revision_match.group(1)
+        
         if skip_on_branch_re and skip_on_branch_re.match(branch):
             print "Release Candidate Build, leaving version files untouched."
             return 0