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