summaryrefslogtreecommitdiffstats
path: root/scripts/osmo-depcheck/osmo-depcheck.py
blob: 7f701d6006a7cb9437d9db0c5dc173e16b4f6965 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright 2018 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>

import argparse
import os
import shutil
import sys

# Same folder
import config
import dependencies
import buildstack


def parse_arguments():
    # Create argparser
    description = ("This script verifies that Osmocom programs really build"
                   " with the dependency versions they claim to support in"
                   " configure.ac. In order to do that, it clones the"
                   " dependency repositories if they don't exist in workdir"
                   " already, and checks out the minimum version tag. This"
                   " happens recursively for their dependencies as well.")
    parser = argparse.ArgumentParser(description=description)

    # Git sources folder
    workdir_default = os.path.expanduser("~") + "/osmo-depcheck-work"
    parser.add_argument("-w", "--workdir", default=workdir_default,
                        help="folder to which the sources will be cloned"
                             " (default: " + workdir_default + ")")

    # Build switch
    parser.add_argument("-b", "--build", action="store_true",
                        help="don't only parse the dependencies, but also try"
                             " to build the program")

    # Build switch
    parser.add_argument("-o", "--old", action="store_true",
                        help="report dependencies on old releases")

    # Job count
    parser.add_argument("-j", "--jobs", type=int,
                        help="parallel build jobs (for make)")

    # Git URL prefix
    parser.add_argument("-u", "--git-url-prefix", dest="prefix",
                        default=config.git_url_prefix,
                        help="where to clone the sources from (default: " +
                             config.git_url_prefix + ")")

    # Projects
    parser.add_argument("projects_revs", nargs="*", default=config.projects,
                        help="which Osmocom projects to look at"
                             " (e.g. 'osmo-hlr:0.2.1', 'osmo-bts', defaults to"
                             " all projects defined in config.py, default"
                             " revision is 'master')",
                        metavar="project[:revision]")

    # Workdir must exist
    ret = parser.parse_args()
    if not os.path.exists(ret.workdir):
        print("ERROR: workdir does not exist: " + ret.workdir)
        sys.exit(1)
    return ret


def workdir_prepare(workdir):
    """ Delete old binaries and create the subfolders in workdir
        :param workdir: path to where all data is stored """
    # Delete folders with binaries from previous runs
    for subfolder in ("build", "install"):
        full = workdir + "/" + subfolder
        if os.path.exists(full):
            shutil.rmtree(full)

    # Create all subfolders
    for subfolder in ("build", "install", "git"):
        os.makedirs(workdir + "/" + subfolder, exist_ok=True)


def main():
    args = parse_arguments()

    # Iterate over projects
    cache_git_fetch = []
    for project_rev in args.projects_revs:
        # Split the git revision from the project name
        project = project_rev
        rev = "master"
        if ":" in project_rev:
            project, rev = project_rev.split(":", 1)

        # Clone and parse the repositories
        workdir_prepare(args.workdir)
        depends = dependencies.generate(args.workdir, args.prefix,
                                        cache_git_fetch, project, rev)
        print("---")
        dependencies.print_dict(depends)
        stack = buildstack.generate(depends)
        print("---")
        buildstack.print_dict(stack)

        # Old versions
        if args.old:
            print("---")
            dependencies.print_old(args.workdir, depends)

        # Build
        if args.build:
            print("---")
            buildstack.build(args.workdir, args.jobs, stack)

        # Success
        print("---")
        print("Success for " + project + ":" + rev + "!")
        print("---")


if __name__ == '__main__':
    main()