CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/configure_all.py
Views: 1798
1
#!/usr/bin/env python
2
3
"""
4
script to run configre for all hwdef.dat, to check for syntax errors
5
"""
6
7
import os
8
import subprocess
9
import sys
10
import fnmatch
11
import shutil
12
13
import argparse
14
15
# modify our search path:
16
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
17
import chibios_hwdef
18
19
parser = argparse.ArgumentParser(description='configure all ChibiOS boards')
20
parser.add_argument('--build', action='store_true', default=False, help='build as well as configure')
21
parser.add_argument('--build-target', default='copter', help='build target')
22
parser.add_argument('--stop', action='store_true', default=False, help='stop on configure or build failure')
23
parser.add_argument('--no-bl', action='store_true', default=False, help="don't check bootloader builds")
24
parser.add_argument('--only-bl', action='store_true', default=False, help="only check bootloader builds")
25
parser.add_argument('--Werror', action='store_true', default=False, help="build with -Werror")
26
parser.add_argument('--pattern', default='*')
27
parser.add_argument('--start', default=None, type=int, help='continue from specified build number')
28
parser.add_argument('--python', default='python')
29
parser.add_argument('--copy-hwdef-incs-to-directory', default=None, help='directory hwdefs should be copied to')
30
args = parser.parse_args()
31
32
os.environ['PYTHONUNBUFFERED'] = '1'
33
34
failures = []
35
done = []
36
board_list = []
37
38
def get_board_list():
39
'''add boards based on existance of hwdef-bl.dat in subdirectories for ChibiOS'''
40
board_list = []
41
# these are base builds, and don't build directly
42
omit = []
43
dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ChibiOS/hwdef'))
44
for d in dirlist:
45
hwdef = os.path.join(dirname, d, 'hwdef.dat')
46
if os.path.exists(hwdef) and d not in omit:
47
board_list.append(d)
48
return board_list
49
50
def run_program(cmd_list, build):
51
print("Running (%s)" % " ".join(cmd_list))
52
retcode = subprocess.call(cmd_list)
53
if retcode != 0:
54
print("FAILED BUILD: %s %s" % (build, ' '.join(cmd_list)))
55
global failures
56
failures.append(build)
57
if args.stop:
58
sys.exit(1)
59
60
for board in sorted(get_board_list()):
61
if not fnmatch.fnmatch(board, args.pattern):
62
continue
63
board_list.append(board)
64
65
if args.start is not None:
66
if args.start < 1 or args.start >= len(board_list):
67
print("Invalid start %u for %u boards" % (args.start, len(board_list)))
68
sys.exit(1)
69
board_list = board_list[args.start-1:]
70
71
def is_ap_periph(board):
72
hwdef = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef.dat' % board)
73
ch = chibios_hwdef.ChibiOSHWDef()
74
ch.process_file(hwdef)
75
return ch.is_periph_fw()
76
77
if args.copy_hwdef_incs_to_directory is not None:
78
os.makedirs(args.copy_hwdef_incs_to_directory)
79
80
def handle_hwdef_copy(directory, board, bootloader=False):
81
source = os.path.join("build", board, "hwdef.h")
82
if bootloader:
83
filename = "hwdef-%s-bl.h" % board
84
elif board == "iomcu":
85
filename = "hwdef-%s-iomcu.h" % board
86
elif is_ap_periph(board):
87
filename = "hwdef-%s-periph.h" % board
88
else:
89
filename = "hwdef-%s.h" % board
90
target = os.path.join(directory, filename)
91
shutil.copy(source, target)
92
93
for board in board_list:
94
done.append(board)
95
print("Configuring for %s [%u/%u failed=%u]" % (board, len(done), len(board_list), len(failures)))
96
config_opts = ["--board", board]
97
if args.Werror:
98
config_opts += ["--Werror"]
99
if not args.only_bl:
100
run_program([args.python, "waf", "configure"] + config_opts, "configure: " + board)
101
if args.copy_hwdef_incs_to_directory is not None:
102
handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board)
103
if args.build:
104
if board == "iomcu":
105
target = "iofirmware"
106
elif is_ap_periph(board):
107
target = "AP_Periph"
108
else:
109
target = args.build_target
110
if target.find('/') != -1:
111
run_program([args.python, "waf", "--target", target], "build: " + board)
112
else:
113
run_program([args.python, "waf", target], "build: " + board)
114
if args.no_bl:
115
continue
116
# check for bootloader def
117
hwdef_bl = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef-bl.dat' % board)
118
if os.path.exists(hwdef_bl):
119
print("Configuring bootloader for %s" % board)
120
run_program([args.python, "waf", "configure", "--board", board, "--bootloader"], "configure: " + board + "-bl")
121
if args.copy_hwdef_incs_to_directory is not None:
122
handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board, bootloader=True)
123
if args.build:
124
run_program([args.python, "waf", "bootloader"], "build: " + board + "-bl")
125
126
if len(failures) > 0:
127
print("Failed builds:")
128
for f in failures:
129
print(' ' + f)
130
sys.exit(1)
131
132
sys.exit(0)
133
134