File: bazel_build.py

package info (click to toggle)
pico-sdk 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,552 kB
  • sloc: ansic: 146,841; asm: 13,423; python: 2,417; cpp: 2,171; yacc: 381; lex: 270; makefile: 32; sh: 13; javascript: 13
file content (235 lines) | stat: -rwxr-xr-x 7,566 bytes parent folder | download
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
#!/usr/bin/env python3
#
# Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# A script that verifies various Bazel build configurations succeed.

import logging
import os
import sys

from bazel_common import (
    SDK_ROOT,
    override_picotool_arg,
    parse_common_args,
    print_framed_string,
    print_to_stderr,
    run_bazel,
    setup_logging,
)


BUILD_CONFIGURATIONS = (
    {
        "name": "host",
        "args": (),
        "extra_targets": (
            "@picotool//:picotool",
            "//tools/pioasm:pioasm",
        ),
        "exclusions": frozenset(
            (
                "//test/cmsis_test:cmsis_test",
                "//test/hardware_irq_test:hardware_irq_test",
                "//test/hardware_pwm_test:hardware_pwm_test",
                "//test/hardware_sync_spin_lock_test:hardware_sync_spin_lock_test",
                "//test/kitchen_sink:kitchen_sink",
                "//test/kitchen_sink:kitchen_sink_cpp",
                "//test/kitchen_sink:kitchen_sink_lwip_poll",
                "//test/kitchen_sink:kitchen_sink_lwip_background",
                "//test/pico_divider_test:pico_divider_test",
                "//test/pico_divider_test:pico_divider_nesting_test",
                "//test/pico_float_test:pico_double_test",
                "//test/pico_float_test:pico_float_test",
                "//test/pico_float_test:pico_float_test_hazard3",
                "//test/pico_sha256_test:pico_sha256_test",
                "//test/pico_stdio_test:pico_stdio_test",
                "//test/pico_time_test:pico_time_test",

                # Pretty much only Picotool and pioasm build on Windows.
                "//..." if os.name == "nt" else "",
                "//test/pico_sem_test:pico_sem_test" if os.name == "nt" else "",
                "//test/pico_stdlib_test:pico_stdlib_test" if os.name == "nt" else "",

            )
        ),
        "run_targets": (""),
    },
    {
        "name": "rp2040",
        "args": ("--platforms=//bazel/platform:rp2040",),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                "//test/kitchen_sink:kitchen_sink_lwip_poll",
                "//test/kitchen_sink:kitchen_sink_lwip_background",
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # No RISC-V on RP2040.
                "//test/pico_float_test:pico_float_test_hazard3",
                # hardware_sha256 doesn't appear to work on RP2040.
                "//test/pico_sha256_test:pico_sha256_test",
            )
        ),
    },
    {
        "name": "rp2350",
        "args": ("--platforms=//bazel/platform:rp2350",),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                "//test/kitchen_sink:kitchen_sink_lwip_poll",
                "//test/kitchen_sink:kitchen_sink_lwip_background",
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # TODO: RISC-V support.
                "//test/pico_float_test:pico_float_test_hazard3",
            )
        ),
    },
    {
        "name": "rp2040 clang",
        "args": (
            "--platforms=//bazel/platform:rp2040",
            "--@pico-sdk//bazel/config:PICO_TOOLCHAIN=clang",
        ),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                "//test/kitchen_sink:kitchen_sink_lwip_poll",
                "//test/kitchen_sink:kitchen_sink_lwip_background",
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # No RISC-V on RP2040.
                "//test/pico_float_test:pico_float_test_hazard3",
                # hardware_sha256 doesn't appear to work on RP2040.
                "//test/pico_sha256_test:pico_sha256_test",
            )
        ),
    },
    {
        "name": "rp2350 clang",
        "args": (
            "--platforms=//bazel/platform:rp2350",
            "--@pico-sdk//bazel/config:PICO_TOOLCHAIN=clang",
        ),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                "//test/kitchen_sink:kitchen_sink_lwip_poll",
                "//test/kitchen_sink:kitchen_sink_lwip_background",
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # TODO: RISC-V support.
                "//test/pico_float_test:pico_float_test_hazard3",
            )
        ),
    },
    {
        "name": "Pico W",
        "args": (
            "--platforms=//bazel/platform:rp2040",
            "--@pico-sdk//bazel/config:PICO_BOARD=pico_w",
        ),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # No RISC-V on RP2040.
                "//test/pico_float_test:pico_float_test_hazard3",
                # hardware_sha256 doesn't appear to work on RP2040.
                "//test/pico_sha256_test:pico_sha256_test",
            )
        ),
    },
    {
        "name": "Pico 2 W",
        "args": (
            "--platforms=//bazel/platform:rp2350",
            "--@pico-sdk//bazel/config:PICO_BOARD=pico2_w",
        ),
        "extra_targets": (),
        "exclusions": frozenset(
            (
                # Host only.
                "//test/pico_float_test:hazard3_test_gen",
                # No RISC-V on RP2040.
                "//test/pico_float_test:pico_float_test_hazard3",
            )
        ),
    },
)


def _find_tests(picotool_dir):
    """Explicitly lists out every test binary in //tests."""
    all_tests = (
        run_bazel(
            (
                "query",
                "kind(cc_binary, //test/...)",
                "--output=label",
                override_picotool_arg(picotool_dir) if picotool_dir else "",
            ),
            text=True,
            check=True,
            capture_output=True,
        )
        .stdout.strip()
        .splitlines()
    )
    # Some tests are behind a transition.
    return [t.replace("_actual", "") for t in all_tests]


def build_all_configurations(picotool_dir):
    default_build_targets = [
        "//...",
        # Tests are explicitly built by name so we can catch compatibilty
        # regressions that cause them to vanish from the wildcard build.
        *_find_tests(picotool_dir),
    ]
    failed_builds = []
    for config in BUILD_CONFIGURATIONS:
        print_framed_string(f"Building {config['name']} configuration...")
        build_targets = [
            t for t in default_build_targets if t not in config["exclusions"]
        ]
        build_targets.extend(config["extra_targets"])

        args = list(config["args"])
        if picotool_dir:
            args.append(override_picotool_arg(picotool_dir))

        result = run_bazel(
            (
                "build",
                *args,
                *build_targets,
            ),
        )
        if result.returncode != 0:
            failed_builds.append(config["name"])
        print_to_stderr()

    if failed_builds:
        print_framed_string("ERROR: One or more builds failed.")
        for build in failed_builds:
            print_to_stderr(f"  * FAILED: {build} build")
        return 1

    print_framed_string("All builds successfully passed!")
    return 0


def main():
    setup_logging()
    args = parse_common_args()
    return build_all_configurations(args.picotool_dir)


if __name__ == "__main__":
    sys.exit(main())