-
Notifications
You must be signed in to change notification settings - Fork 47
/
dev_build.py
104 lines (85 loc) · 2.78 KB
/
dev_build.py
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
# Copyright 2021, Breakaway Consulting Pty. Ltd.
# SPDX-License-Identifier: BSD-2-Clause
"""Build a specific example during development.
This is designed to make it easy to build and run examples during development.
"""
from argparse import ArgumentParser
from os import environ, system
from pathlib import Path
from shutil import rmtree
from subprocess import run
from sys import executable
CWD = Path.cwd()
BUILD_DIR = CWD / "tmp_build"
def find_releases():
releases = []
for f in (CWD / "release").iterdir():
if not f.is_dir():
continue
if not f.name.startswith("microkit-sdk-"):
# All directories in here should match this, but
# skip just iun case someone added junk
continue
releases.append(f)
def release_sort_key(rel):
ver_str = rel.name.split("-")[-1]
ver = tuple(int(x) for x in ver_str.split("."))
return ver
releases.sort(key=release_sort_key, reverse=True)
return releases
def main():
parser = ArgumentParser()
parser.add_argument(
"--rebuild",
action="store_true",
default=False,
help="Force a rebuild of the example",
)
parser.add_argument(
"--example-from-sdk",
action="store_true",
default=False,
help="Build the example from the SDK build rather than directly from source directory",
)
parser.add_argument(
"--board",
help="Target board",
required=True
)
parser.add_argument(
"--example",
help="Example to build",
required=True
)
parser.add_argument(
"--config",
default="debug",
help="Config option to be passed to the tool"
)
args = parser.parse_args()
# TODO: Support choosing a release by specifying on command line
releases = find_releases()
release = releases[0]
if args.rebuild and BUILD_DIR.exists():
rmtree(BUILD_DIR)
if not BUILD_DIR.exists():
BUILD_DIR.mkdir()
tool_rebuild = f"cd tool/microkit && cargo build --release"
r = system(tool_rebuild)
assert r == 0
make_env = environ.copy()
make_env["BUILD_DIR"] = str(BUILD_DIR.absolute())
make_env["MICROKIT_BOARD"] = args.board
make_env["MICROKIT_CONFIG"] = args.config
make_env["MICROKIT_SDK"] = str(release)
make_env["MICROKIT_TOOL"] = Path("tool/microkit/target/release/microkit").absolute()
# Choose the makefile based on the `--example-from-sdk` command line flag
makefile_directory = (
f"{release}/board/{args.board}/example/{args.example}"
if args.example_from_sdk
else f"{CWD.absolute()}/example/{args.board}/{args.example}"
)
cmd = ["make", "-C", makefile_directory]
run(cmd, env=make_env)
if __name__ == "__main__":
main()