summaryrefslogtreecommitdiffstats
path: root/source-builder/sb/getsources.py
blob: d348da485a792c67358628fffcd8c02c7694c57b (plain) (blame)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2019 Chris Johns (chrisj@rtems.org)
# All rights reserved.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#
# This code builds a package compiler tool suite given a tool set. A tool
# set lists the various tools. These are specific tool configurations.
#

from __future__ import print_function

import argparse
import copy
import datetime
import os
import sys

try:
    from . import build
    from . import error
    from . import log
    from . import simhost
    from . import version
except KeyboardInterrupt:
    print('abort: user terminated', file = sys.stderr)
    sys.exit(1)
except:
    raise

def run(args = sys.argv):
    ec = 0
    get_sources_error = True
    try:
        #
        # The RSB options support cannot be used because it loads the defaults
        # for the host which we cannot do here.
        #
        description  = 'RTEMS Get Sources downloads all the source a build set '
        description += 'references for all hosts.'

        argsp = argparse.ArgumentParser(prog = 'rtems-get-sources',
                                        description = description)
        argsp.add_argument('--rtems-version', help = 'Set the RTEMS version.',
                           type = str,
                           default = version.version())
        argsp.add_argument('--list-hosts', help = 'List the hosts.',
                           action = 'store_true')
        argsp.add_argument('--list-bsets', help = 'List the hosts.',
                           action = 'store_true')
        argsp.add_argument('--download-dir', help = 'Download directory.',
                           type = str)
        argsp.add_argument('--clean', help = 'Clean the download directory.',
                           action = 'store_true')
        argsp.add_argument('--tar', help = 'Create a tarball of all the source.',
                           action = 'store_true')
        argsp.add_argument('--log', help = 'Log file.',
                           type = str,
                           default = simhost.log_default('getsource'))
        argsp.add_argument('--trace', help = 'Enable trace logging for debugging.',
                           action = 'store_true')
        argsp.add_argument('bsets', nargs='*', help = 'Build sets.')

        argopts = argsp.parse_args(args[1:])

        simhost.load_log(argopts.log)
        log.notice('RTEMS Source Builder - Get Sources, %s' % (version.string()))
        log.tracing = argopts.trace

        opts = simhost.load_options(args, argopts, extras = ['--with-download'])
        configs = build.get_configs(opts)

        if argopts.list_hosts:
            simhost.list_hosts()
        elif argopts.list_bsets:
            simhost.list_bset_files(opts, configs)
        else:
            if argopts.clean:
                if argopts.download_dir is None:
                    raise error.general('cleaning of the default download directories is not supported')
                if path.exists(argopts.download_dir):
                    log.notice('Cleaning source directory: %s' % (argopts.download_dir))
                    path.removeall(argopts.download_dir)
            all_bsets = simhost.get_bset_files(configs)
            if len(argopts.bsets) == 0:
                bsets = all_bsets
            else:
                bsets = argopts.bsets
            for bset in bsets:
                b = None
                try:
                    for host in simhost.profiles:
                        get_sources_error = True
                        b = simhost.buildset(bset, configs, opts)
                        get_sources_error = False
                        b.build(host)
                        del b
                except error.general as gerr:
                    log.stderr(str(gerr))
                    log.stderr('Build FAILED')
                b = None
    except error.general as gerr:
        if get_sources_error:
            log.stderr(str(gerr))
        log.stderr('Build FAILED')
        ec = 1
    except error.internal as ierr:
        if get_sources_error:
            log.stderr(str(ierr))
        log.stderr('Internal Build FAILED')
        ec = 1
    except error.exit as eerr:
        pass
    except KeyboardInterrupt:
        log.notice('abort: user terminated')
        ec = 1
    except:
        raise
        log.notice('abort: unknown error')
        ec = 1
    sys.exit(ec)

if __name__ == "__main__":
    run()