macversion.py (1432B)
1 #!/usr/bin/python 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 import re 7 import sys 8 from optparse import OptionParser 9 10 o = OptionParser() 11 o.add_option("--buildid", dest="buildid") 12 o.add_option("--version", dest="version") 13 14 (options, args) = o.parse_args() 15 16 if not options.buildid: 17 print("--buildid is required", file=sys.stderr) 18 sys.exit(1) 19 20 if not options.version: 21 print("--version is required", file=sys.stderr) 22 sys.exit(1) 23 24 # We want to build a version number that matches the format allowed for 25 # CFBundleVersion (nnnnn[.nn[.nn]]). We'll incorporate both the version 26 # number as well as the date, so that it changes at least daily (for nightly 27 # builds), but also so that newly-built older versions (e.g. beta build) aren't 28 # considered "newer" than previously-built newer versions (e.g. a trunk nightly) 29 30 define, MOZ_BUILDID, buildid = open(options.buildid, encoding="utf-8").read().split() 31 32 # extract only the major version (i.e. "14" from "14.0b1") 33 majorVersion = re.match(r"^(\d+)[^\d].*", options.version).group(1) 34 # last two digits of the year 35 twodigityear = buildid[2:4] 36 month = buildid[4:6] 37 if month[0] == "0": 38 month = month[1] 39 day = buildid[6:8] 40 if day[0] == "0": 41 day = day[1] 42 43 print("%s.%s.%s" % (majorVersion + twodigityear, month, day))