summaryrefslogtreecommitdiff
path: root/wscript
blob: a9f2b31e83f9fc10793007406baa5a7692433290 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# SPDX-License-Identifier: BSD-2-Clause
"""
Deployment regression tests

This can be a template for using waf to run the RSB.
"""

#
# Copyright 2022 Chris Johns (chris@contemporary.software)
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

from __future__ import print_function

import os.path

rtems_version_default = 6

builds = {
    5: [
        {
            'buildset': '5/project-tools',
            'good': True,
            'dry-run': False
        },
        {
            'buildset': '5/project-tools-bsp',
            'good': True,
            'dry-run': False
        },
    ],
    6: [
        {
            'buildset': '6/test-aarch64-bsps-bad-opts',
            'good': False,
            'dry-run': True
        },
        {
            'buildset': '6/test-aarch64-bsps',
            'good': True,
            'dry-run': True
        },
        {
            'buildset': '6/test-aarch64-bsps-opts',
            'good': True,
            'dry-run': True
        },
        {
            'buildset': '6/test-aarch64-config',
            'good': True,
            'dry-run': True
        },
        {
            'buildset': '6/test-aarch64-powerpc-config',
            'good': True,
            'dry-run': True
        },
        {
            'buildset': '6/project-tools',
            'good': True,
            'dry-run': False
        },
        {
            'buildset': '6/project-tools-bsp',
            'good': True,
            'dry-run': False
        },
        {
            'buildset': '6/project-tools-bsp-config',
            'good': True,
            'dry-run': False
        },
        {
            'buildset': '6/project-aarch64-tools-bsp-libbsd',
            'good': True,
            'dry-run': False
        },
        {
            'buildset': '6/project-aarch64-tools-bsp-libbsd-config',
            'good': True,
            'dry-run': False
        },
    ],
}

from waflib import Context, Build, Errors, Task, TaskGen, Utils


class set_builder_task(Task.Task):
    always_run = True
    semaphore = Task.TaskSemaphore(1)

    def __str__(self):
        return self.name

    def uid(self):
        return Utils.h_list(self.name)

    def run(self):
        r = 0
        try:
            self.generator.bld.cmd_and_log(self.rsb_cmd,
                                           cwd=self.base,
                                           quiet=Context.BOTH)
        except Errors.WafError as e:
            r = 1
        if not self.good:
            if r == 0:
                r = 1
            else:
                r = 0
        return r


@TaskGen.taskgen_method
@TaskGen.feature('*')
def set_builder_generator(self):
    tsk = self.create_task('set_builder_task')
    tsk.name = getattr(self, 'name', None)
    tsk.base = getattr(self, 'base', None)
    tsk.config = getattr(self, 'config', None)
    tsk.good = getattr(self, 'good', None)
    tsk.rsb_cmd = getattr(self, 'rsb_cmd', None)


class shower(Build.BuildContext):
    cmd = 'show'
    fun = 'show'


def set_builder_build(bld, build, show=False):
    name = os.path.basename(build['buildset'])
    cmd = [
        bld.env.RSB_SET_BUILDER, '--prefix=/private/prefix', '--no-install',
        '--bset-tar-file'
    ]
    if build['dry-run'] or bld.env.DRY_RUN:
        cmd += ['--dry-run']
    cmd += ['--trace', '--log=' + name + '.txt', build['buildset']]
    if show:
        print(build['buildset'] + ':', ' '.join(cmd))
    else:
        config = 'config/' + build['buildset'] + '.bset'
        buildset = bld.path.find_resource(config)
        if buildset is None:
            bld.fatal('buildset not found: ' + build['buildset'])
        bld(name=build['buildset'],
            soufrce=config,
            base=bld.path,
            good=build['good'],
            rsb_cmd=' '.join(cmd),
            always=True)


def options(opt):
    opt.add_option('--rsb',
                   default=None,
                   dest='rsb_path',
                   help='Path to the RTEMS Source Builder (RSB)')
    opt.add_option('--rtems-version',
                   default=rtems_version_default,
                   dest='rtems_version',
                   help='Version of RTEMS')
    opt.add_option('--dry-run',
                   action='store_true',
                   default=False,
                   dest='dry_run',
                   help='Dry run of the build commands')


def configure(conf):
    if conf.options.rsb_path is None:
        conf.fatal('RSB path not provided as configure option')
    if not os.path.exists(conf.options.rsb_path):
        conf.fatal('RSB path not found: ' + conf.options.rsb_path)
    rsb_path = os.path.abspath(conf.options.rsb_path)
    rsb_set_builder = os.path.join(rsb_path, 'source-builder',
                                   'sb-set-builder')
    if not os.path.exists(rsb_set_builder):
        conf.fatal('RSB path not the valid: ' + rsb_path)
    conf.msg('RSB', rsb_path, 'GREEN')
    try:
        rtems_version = int(conf.options.rtems_version)
    except:
        conf.fatal('invalid RTEMS version: ' + conf.options.rtems_version)
    if rtems_version not in builds:
        conf.fatal('unsupported RTEMS version: ' + conf.options.rtems_version)
    conf.msg('RTEMS Version', rtems_version, 'GREEN')
    if conf.options.dry_run:
        dry_run = 'yes'
    else:
        dry_run = 'no'
    conf.msg('Dry run', dry_run, 'GREEN')
    conf.env.RSB_PATH = rsb_path
    conf.env.RSB_SET_BUILDER = rsb_set_builder
    conf.env.RTEMS_VERSION = rtems_version
    conf.env.DRY_RUN = conf.options.dry_run


def build(bld):
    dry_runs = [
        build for build in builds[bld.env.RTEMS_VERSION] if build['dry-run']
    ]
    tars = [
        build for build in builds[bld.env.RTEMS_VERSION]
        if not build['dry-run']
    ]
    bld.add_group('dry-run')
    for build in dry_runs:
        set_builder_build(bld, build)
    bld.add_group('tar')
    for build in tars:
        set_builder_build(bld, build)


def show(bld):
    for build in builds[bld.env.RTEMS_VERSION]:
        set_builder_build(bld, build, show=True)