summaryrefslogtreecommitdiff
path: root/scripts/buildhistory-diff
blob: b82240d76392b671550cfaf8720b9f8a7a8cac4c (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python

# Report significant differences in the buildhistory repository since a specific revision
#
# Copyright (C) 2013 Intel Corporation
# Author: Paul Eggleton <paul.eggleton@linux.intel.com>

import sys
import os
import optparse
from distutils.version import LooseVersion

# Ensure PythonGit is installed (buildhistory_analysis needs it)
try:
    import git
except ImportError:
    print("Please install GitPython (python-git) 0.3.1 or later in order to use this script")
    sys.exit(1)

def main():
    parser = optparse.OptionParser(
        description = "Reports significant differences in the buildhistory repository.",
        usage = """
    %prog [options] [from-revision [to-revision]]
(if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""")

    parser.add_option("-p", "--buildhistory-dir",
            help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
            action="store", dest="buildhistory_dir", default='buildhistory/')

    options, args = parser.parse_args(sys.argv)

    if len(args) > 3:
        sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
        parser.print_help()
        sys.exit(1)

    if LooseVersion(git.__version__) < '0.3.1':
        sys.stderr.write("Version of GitPython is too old, please install GitPython (python-git) 0.3.1 or later in order to use this script\n")
        sys.exit(1)

    if not os.path.exists(options.buildhistory_dir):
        sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
        parser.print_help()
        sys.exit(1)

    # Set path to OE lib dir so we can import the buildhistory_analysis module
    basepath = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])) + '/..')
    newpath = basepath + '/meta/lib'
    # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
    if os.path.exists(basepath + '/bitbake/lib/bb'):
        bitbakepath = basepath + '/bitbake'
    else:
        # look for bitbake/bin dir in PATH
        bitbakepath = None
        for pth in os.environ['PATH'].split(':'):
            if os.path.exists(os.path.join(pth, '../lib/bb')):
                bitbakepath = os.path.abspath(os.path.join(pth, '..'))
                break
        if not bitbakepath:
            sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
            sys.exit(1)

    sys.path[0:0] = [newpath, bitbakepath + '/lib']
    import oe.buildhistory_analysis

    fromrev = 'build-minus-1'
    torev = 'HEAD'
    if len(args) > 1:
        if len(args) == 2 and '..' in args[1]:
            revs = args[1].split('..')
            fromrev = revs[0]
            if revs[1]:
                torev = revs[1]
        else:
            fromrev = args[1]
    if len(args) > 2:
        torev = args[2]

    import gitdb
    try:
        changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev)
    except gitdb.exc.BadObject as e:
        if len(args) == 1:
            sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
            parser.print_help()
        else:
            sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
        sys.exit(1)

    for chg in changes:
        print('%s' % chg)

    sys.exit(0)


if __name__ == "__main__":
    main()