summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/milestone.py
blob: c2aa78fcd90f8c2e17604e549015b0e9e672582b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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 absolute_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:])