Bug 481703 - Use python to create pre release suffix. r=bsmedberg
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 19 Mar 2009 11:56:40 -0700
changeset 26378 ae69c2f236cdcab7377a9c5d17451911e48d3072
parent 26377 92cfa4b07b8be13ff7d436fcd4ffcf0322f7e365
child 26379 41074d6c1919fd66030d97c35b3164de8691aef9
push id6036
push userrstrong@mozilla.com
push dateThu, 19 Mar 2009 18:57:27 +0000
treeherdermozilla-central@41074d6c1919 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs481703
milestone1.9.2a1pre
Bug 481703 - Use python to create pre release suffix. r=bsmedberg
browser/base/Makefile.in
browser/installer/windows/Makefile.in
config/Makefile.in
config/printprereleasesuffix.py
config/tests/unit-printprereleasesuffix.py
--- a/browser/base/Makefile.in
+++ b/browser/base/Makefile.in
@@ -50,20 +50,18 @@ abs_srcdir = $(call core_abspath,$(srcdi
 CHROME_DEPS += $(abs_srcdir)/content/overrides/app-license.html
 
 ifdef ENABLE_TESTS
 DIRS += content/test
 endif
 
 include $(topsrcdir)/config/rules.mk
 
-PRE_RELEASE_SUFFIX = $(shell cat $(srcdir)/../config/version.txt | \
-  sed -e '/pre/s/.*//g' -e '/[ab][0-9]/!s/.*//g' \
-      -e 's/\(.*[0-9]\)a\([0-9]\+\)/ \1 Alpha \2/g' \
-      -e 's/\(.*[0-9]\)b\([0-9]\+\)/ \1 Beta \2/g')
+PRE_RELEASE_SUFFIX := $(shell $(PYTHON) $(topsrcdir)/config/printprereleasesuffix.py \
+                        $(shell cat $(srcdir)/../config/version.txt))
 
 DEFINES += \
 	-DMOZ_APP_VERSION=$(MOZ_APP_VERSION) \
 	-DAPP_LICENSE_BLOCK=$(abs_srcdir)/content/overrides/app-license.html \
 	-DPRE_RELEASE_SUFFIX="$(PRE_RELEASE_SUFFIX)" \
 	$(NULL)
 
 ifndef MOZ_BRANDING_DIRECTORY
--- a/browser/installer/windows/Makefile.in
+++ b/browser/installer/windows/Makefile.in
@@ -44,22 +44,19 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 include $(topsrcdir)/toolkit/mozapps/installer/package-name.mk
 
 CONFIG_DIR = instgen
 SFX_MODULE = $(topsrcdir)/other-licenses/7zstub/firefox/7zSD.sfx
-APP_VERSION = $(shell cat $(srcdir)/../../config/version.txt)
+APP_VERSION := $(shell cat $(srcdir)/../../config/version.txt)
 DEFINES += -DAPP_VERSION=$(APP_VERSION)
-PRE_RELEASE_SUFFIX = $(shell echo $(APP_VERSION) | \
-  sed -e '/pre/s/.*//g' -e '/[ab][0-9]/!s/.*//g' \
-      -e 's/\(.*[0-9]\)a\([0-9]\+\)/ \1 Alpha \2/g' \
-      -e 's/\(.*[0-9]\)b\([0-9]\+\)/ \1 Beta \2/g')
+PRE_RELEASE_SUFFIX := $(shell $(PYTHON) $(topsrcdir)/config/printprereleasesuffix.py $(APP_VERSION))
 DEFINES += -DPRE_RELEASE_SUFFIX="$(PRE_RELEASE_SUFFIX)"
 
 PP_LOCALIZED_FILES = \
 	packages-static \
 	$(NULL)
 
 # All script and locale files used by the Unicode version of NSIS need to be
 # converted from UTF-8 to UTF-16LE
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -149,17 +149,18 @@ endif
 
 FORCE:
 
 ifdef MKDEPEND_DIR
 clean clobber realclean clobber_all::
 	cd $(MKDEPEND_DIR); $(MAKE) $@
 endif
 
-PYUNITS := unit-Expression.py unit-Preprocessor.py unit-nsinstall.py
+PYUNITS := unit-Expression.py unit-Preprocessor.py unit-nsinstall.py \
+           unit-printprereleasesuffix.py
 
 check:: check-python-modules check-jar-mn
 
 check-python-modules::
 	@$(EXIT_ON_ERROR) \
 	for test in $(PYUNITS); do \
 	  $(PYTHON) $(srcdir)/tests/$$test ; \
 	done
new file mode 100644
--- /dev/null
+++ b/config/printprereleasesuffix.py
@@ -0,0 +1,63 @@
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is Mozilla.
+#
+# The Initial Developer of the Original Code is
+# the Mozilla Foundation.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#  Robert Strong <robert.bugzilla@gmail.com>
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 2 or later (the "GPL"), or
+# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+# Prints the pre-release version suffix based on the version string
+#
+# Examples:
+# 2.1a3    > " 2.1 Alpha 3"
+# 2.1a3pre > ""
+# 3.2b4    > " 3.2 Beta 4"
+# 3.2b4pre > ""
+
+import sys
+import re
+
+def get_prerelease_suffix(version):
+  """ Returns the prerelease suffix from the version string argument """
+
+  def mfunc(m):
+    return " %s %s %s" % (m.group('prefix'),
+                         {'a': 'Alpha', 'b': 'Beta'}[m.group('c')],
+                         m.group('suffix'))
+  result, c = re.subn(r'^(?P<prefix>(\d+\.)*\d+)(?P<c>[ab])(?P<suffix>\d+)$',
+                      mfunc, version)
+  if c != 1:
+    return ''
+  return result
+
+if len(sys.argv) == 2:
+  print get_prerelease_suffix(sys.argv[1])
new file mode 100644
--- /dev/null
+++ b/config/tests/unit-printprereleasesuffix.py
@@ -0,0 +1,80 @@
+import unittest
+
+import sys
+import os.path
+sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+
+from printprereleasesuffix import get_prerelease_suffix
+
+class TestGetPreReleaseSuffix(unittest.TestCase):
+  """
+  Unit tests for the get_prerelease_suffix function
+  """
+
+  def test_alpha_1(self):
+    """test 1a1 version string"""
+    self.c = get_prerelease_suffix('1a1')
+    self.assertEqual(self.c, ' 1 Alpha 1')
+
+  def test_alpha_10(self):
+    """test 1.2a10 version string"""
+    self.c = get_prerelease_suffix('1.2a10')
+    self.assertEqual(self.c, ' 1.2 Alpha 10')
+
+  def test_beta_3(self):
+    """test 1.2.3b3 version string"""
+    self.c = get_prerelease_suffix('1.2.3b3')
+    self.assertEqual(self.c, ' 1.2.3 Beta 3')
+
+  def test_beta_30(self):
+    """test 1.2.3.4b30 version string"""
+    self.c = get_prerelease_suffix('1.2.3.4b30')
+    self.assertEqual(self.c, ' 1.2.3.4 Beta 30')
+
+  def test_release_1(self):
+    """test 1.2.3.4 version string"""
+    self.c = get_prerelease_suffix('1.2.3.4')
+    self.assertEqual(self.c, '')
+
+  def test_alpha_1_pre(self):
+    """test 1.2a1pre version string"""
+    self.c = get_prerelease_suffix('1.2a1pre')
+    self.assertEqual(self.c, '')
+
+  def test_beta_10_pre(self):
+    """test 3.4b10pre version string"""
+    self.c = get_prerelease_suffix('3.4b10pre')
+    self.assertEqual(self.c, '')
+
+  def test_pre_0(self):
+    """test 1.2pre0 version string"""
+    self.c = get_prerelease_suffix('1.2pre0')
+    self.assertEqual(self.c, '')
+
+  def test_pre_1_b(self):
+    """test 1.2pre1b version string"""
+    self.c = get_prerelease_suffix('1.2pre1b')
+    self.assertEqual(self.c, '')
+
+  def test_a_a(self):
+    """test 1.2aa version string"""
+    self.c = get_prerelease_suffix('1.2aa')
+    self.assertEqual(self.c, '')
+
+  def test_b_b(self):
+    """test 1.2bb version string"""
+    self.c = get_prerelease_suffix('1.2bb')
+    self.assertEqual(self.c, '')
+
+  def test_a_b(self):
+    """test 1.2ab version string"""
+    self.c = get_prerelease_suffix('1.2ab')
+    self.assertEqual(self.c, '')
+
+  def test_plus(self):
+    """test 1.2+ version string """
+    self.c = get_prerelease_suffix('1.2+')
+    self.assertEqual(self.c, '')
+
+if __name__ == '__main__':
+  unittest.main()