Bug 739601 - Rewrite (the used parts of) config/milestone.pl in python; r=gps
authorMs2ger <ms2ger@gmail.com>
Fri, 09 Jan 2015 10:24:45 +0100
changeset 222890 9b33fc49396cd8d1f1b0805bccab59a7657f4802
parent 222889 3eb9a4e2bab0cbca1eeebba75ee0e5feaed157c5
child 222891 f78b883da6fdc097cf98f7c4f2ef0b3512fb388b
push id53747
push userMs2ger@gmail.com
push dateFri, 09 Jan 2015 09:25:11 +0000
treeherdermozilla-inbound@9b33fc49396c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs739601
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739601 - Rewrite (the used parts of) config/milestone.pl in python; r=gps
config/milestone.pl
config/milestone.txt
configure.in
js/src/configure.in
python/mozbuild/mozbuild/milestone.py
toolkit/xre/Makefile.in
deleted file mode 100755
--- a/config/milestone.pl
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/perl -w
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-use Getopt::Long;
-
-use strict;
-use vars qw(
-            $OBJDIR
-            $SRCDIR
-            $TOPSRCDIR
-            $SCRIPTDIR
-            @TEMPLATE_FILE
-            $MILESTONE_FILE
-            $MILESTONE
-            $MILESTONE_NUM
-            @MILESTONE_PARTS
-            $MINI_VERSION
-            $MICRO_VERSION
-            $opt_debug
-            $opt_template
-            $opt_uaversion
-            $opt_symbolversion
-            $opt_help
-            );
-
-$SCRIPTDIR = $0;
-$SCRIPTDIR =~ s/[^\/]*$//;
-push(@INC,$SCRIPTDIR);
-
-require "Moz/Milestone.pm";
-
-&GetOptions('topsrcdir=s' => \$TOPSRCDIR, 'srcdir=s' => \$SRCDIR, 'objdir=s' => \$OBJDIR, 'debug', 'help', 'template', 'uaversion', 'symbolversion');
-
-if (defined($opt_help)) {
-    &usage();
-    exit;
-}
-
-if (defined($opt_template)) {
-    @TEMPLATE_FILE = @ARGV;
-    if ($opt_debug) {
-        print("TEMPLATE_FILE = --@TEMPLATE_FILE--\n");
-    }
-}
-
-if (!defined($SRCDIR)) { $SRCDIR = '.'; }
-if (!defined($OBJDIR)) { $OBJDIR = '.'; }
-
-$MILESTONE_FILE  = "$TOPSRCDIR/config/milestone.txt";
-@MILESTONE_PARTS = (0, 0, 0, 0);
-
-#
-# Grab milestone (top line of $MILESTONE_FILE that starts with a digit)
-#
-my $milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
-
-if (@TEMPLATE_FILE) {
-  my $TFILE;
-
-  foreach $TFILE (@TEMPLATE_FILE) {
-    my $BUILT_FILE = "$OBJDIR/$TFILE";
-    $TFILE = "$SRCDIR/$TFILE.tmpl";
-
-    if (-e $TFILE) {
-
-      Moz::Milestone::build_file($TFILE,$BUILT_FILE);
-
-    } else {
-      warn("$0:  No such file $TFILE!\n");
-    }
-  }
-} elsif(defined($opt_uaversion)) {
-  # Only expose the major milestone in the UA string, hide the patch level
-  # (bugs 572659 and 870868).
-  my $uaversion = Moz::Milestone::getMilestoneMajor($milestone) . ".0";
-  print "$uaversion\n";
-} elsif(defined($opt_symbolversion)) {
-  # Only expose major milestone and alpha version. Used for symbol versioning
-  # on Linux.
-  my $symbolversion = Moz::Milestone::getMilestoneMajor($milestone) .
-                      Moz::Milestone::getMilestoneABWithNum($milestone);
-  print "$symbolversion\n";
-} else {
-  print "$milestone\n";
-}
-
-sub usage() {
-  print <<END
-`milestone.pl [--topsrcdir TOPSRCDIR] [--objdir OBJDIR] [--srcdir SRCDIR] --template [file list] --uaversion --symbolversion`  # will build file list from .tmpl files
-END
-    ;
-}
--- a/config/milestone.txt
+++ b/config/milestone.txt
@@ -1,13 +1,13 @@
 # Holds the current milestone.
 # Should be in the format of
 #
 #    x.x.x
 #    x.x.x.x
 #    x.x.x+
 #
-# Referenced by milestone.pl.
+# Referenced by milestone.py.
 # Hopefully I'll be able to automate replacement of *all*
 # hardcoded milestones in the tree from these two files.
 #--------------------------------------------------------
 
 37.0a1
--- a/configure.in
+++ b/configure.in
@@ -1877,20 +1877,22 @@ case "$host" in
     ;;
 
 *)
     HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
     HOST_OPTIMIZE_FLAGS="${HOST_OPTIMIZE_FLAGS=-O2}"
     ;;
 esac
 
+dnl ==============================================================
 dnl Get mozilla version from central milestone file
-MOZILLA_VERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir`
-MOZILLA_UAVERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir -uaversion`
-MOZILLA_SYMBOLVERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir -symbolversion`
+dnl ==============================================================
+MOZILLA_VERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir`
+MOZILLA_UAVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --uaversion`
+MOZILLA_SYMBOLVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --symbolversion`
 
 dnl Get version of various core apps from the version files.
 FIREFOX_VERSION=`cat $_topsrcdir/browser/config/version.txt`
 
 if test -z "$FIREFOX_VERSION"; then
     AC_MSG_ERROR([FIREFOX_VERSION is unexpectedly blank.])
 fi
 
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -231,19 +231,19 @@ if test -n "$gonkdir" ; then
     AC_DEFINE(GONK)
 else
     MOZ_ANDROID_NDK
 fi
 
 dnl ==============================================================
 dnl Get mozilla version from central milestone file
 dnl ==============================================================
-MOZILLA_VERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir`
-MOZILLA_UAVERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir -uaversion`
-MOZILLA_SYMBOLVERSION=`$PERL $srcdir/config/milestone.pl -topsrcdir $srcdir -symbolversion`
+MOZILLA_VERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir`
+MOZILLA_UAVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --uaversion`
+MOZILLA_SYMBOLVERSION=`$PYTHON $srcdir/python/mozbuild/mozbuild/milestone.py --topsrcdir $srcdir --symbolversion`
 
 AC_DEFINE_UNQUOTED(MOZILLA_VERSION,"$MOZILLA_VERSION")
 AC_DEFINE_UNQUOTED(MOZILLA_VERSION_U,$MOZILLA_VERSION)
 AC_DEFINE_UNQUOTED(MOZILLA_UAVERSION,"$MOZILLA_UAVERSION")
 AC_SUBST(MOZILLA_SYMBOLVERSION)
 
 # Separate version into components for use in shared object naming etc
 changequote(,)
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/milestone.py
@@ -0,0 +1,75 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import print_function, unicode_literals
+
+import argparse
+import os
+import re
+import sys
+
+
+def get_milestone_ab_with_num(milestone):
+    """
+    Returns the alpha and beta tag with its number (a1, a2, b3, ...).
+    """
+
+    match = re.search(r"([ab]\d+)", milestone)
+    if match:
+        return match.group(1)
+
+    return ""
+
+
+def get_official_milestone(path):
+    """
+    Returns the contents of the first line in `path` that starts with a digit.
+    """
+
+    with open(path) as fp:
+        for line in fp:
+            line = line.strip()
+            if line[:1].isdigit():
+                return line
+
+    raise Exception("Didn't find a line that starts with a digit.")
+
+
+def get_milestone_major(milestone):
+    """
+    Returns the major (first) part of the milestone.
+    """
+
+    return milestone.split('.')[0]
+
+
+def main(args):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--uaversion', default=False, action='store_true')
+    parser.add_argument('--symbolversion', default=False, action='store_true')
+    parser.add_argument('--topsrcdir', metavar='TOPSRCDIR', required=True)
+    options = parser.parse_args(args)
+
+    milestone_file = os.path.join(options.topsrcdir, 'config', 'milestone.txt')
+
+    milestone = get_official_milestone(milestone_file)
+
+    if options.uaversion:
+        # Only expose the major milestone in the UA string, hide the patch
+        # level (bugs 572659 and 870868).
+        uaversion = "%s.0" % (get_milestone_major(milestone),)
+        print(uaversion)
+
+    elif options.symbolversion:
+        # Only expose major milestone and alpha version. Used for symbol
+        # versioning on Linux.
+        symbolversion = "%s%s" % (get_milestone_major(milestone),
+                                  get_milestone_ab_with_num(milestone))
+        print(symbolversion)
+    else:
+        print(milestone)
+
+
+if __name__ == '__main__':
+    main(sys.argv[1:])
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -8,17 +8,17 @@
 USE_RCS_MK=1
 include $(topsrcdir)/config/makefiles/makeutils.mk
 
 milestone_txt = $(topsrcdir)/config/milestone.txt
 
 include $(topsrcdir)/config/rules.mk
 
 # Should version be optional or required ?
-TOOLKIT_EM_VERSION=$(shell $(PERL) $(topsrcdir)/config/milestone.pl --topsrcdir=$(topsrcdir))
+TOOLKIT_EM_VERSION=$(shell $(PYTHON) $(topsrcdir)/python/mozbuild/mozbuild/milestone.py --topsrcdir=$(topsrcdir))
 $(call warnIfEmpty,TOOLKIT_EM_VERSION)
 
 # Valid if null: {warn,error}IfEmpty
 DEFINES += -DTOOLKIT_EM_VERSION='"$(TOOLKIT_EM_VERSION)"'
 
 MOZ_SOURCE_STAMP ?= $(firstword $(shell hg -R $(topsrcdir) parent --template='{node|short}\n' 2>/dev/null))
 ifdef MOZ_SOURCE_STAMP