-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
123 lines (92 loc) · 2.63 KB
/
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import argparse
import json
import os
import platform
import shutil
import subprocess
import sys
import tarfile
from typing import List
# Make sure all needed third-party libraries are installed.
try:
import requests
import xbstrap
import chalk
except ImportError:
print("The requests and xbstrap libraries are required", file=sys.stderr)
sys.exit(1)
import requests
import xbstrap
import chalk
BUILD_DIR = "build"
def run_command(args, **kwargs):
"""Runs a command and returns the command's output, along with its standard-out and
standard-error files.
"""
output = subprocess.run(args, **kwargs)
return output.returncode, output.stdout, output.stderr
def build_cargo_workspace(directory, command, args, cargo="cargo"):
code, _, _ = run_command([cargo, command, *args], cwd=directory)
if code != 0:
return None
_, stdout, _ = run_command(
[cargo, command, *args, "--message-format=json"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
cwd=directory,
)
def build_kernel(args):
command = "build"
command_args = ["--package", "kernel", "--target", f".cargo/{args.target}.json"]
if not args.debug:
command_args.append("release")
if args.test:
command = "test"
command_args.append("--no-run")
elif args.check:
command = "check"
elif args.document:
command = "doc"
if args.features:
command_args += ["--features", ",".join(args.features)]
return build_cargo_workspace("src", command, command_args)
def parse_args():
parser = argparse.ArgumentParser(
description="Builds the RusTOS kernel and userland"
)
check_test = parser.add_mutually_exclusive_group()
check_test.add_argument(
"--clean",
default=False,
action="store_true",
help="removes the build artifacts",
)
check_test.add_argument(
"--test", default=False, action="store_true", help="runs the test suite"
)
check_test.add_argument(
"--document",
default=False,
action="store_true",
help="generates the documentation for the kernel",
)
parser.add_argument(
"--debug",
default=False,
action="store_true",
help="builds the kernel and userland in debug mode",
)
parser.add_argument(
"--only-run",
default=False,
action="store_true",
help="runs RusTOS without re-building"
)
return parser.parse_args()
def main():
args = parse_args()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass