2018-07-05 01:15:19 -03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
script to run configre for all hwdef.dat, to check for syntax errors
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import fnmatch
|
2021-10-26 00:25:15 -03:00
|
|
|
import shutil
|
2018-07-05 01:15:19 -03:00
|
|
|
|
2019-03-14 20:39:27 -03:00
|
|
|
import argparse
|
2018-07-05 01:15:19 -03:00
|
|
|
|
2023-05-10 05:46:37 -03:00
|
|
|
# modify our search path:
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))
|
|
|
|
import chibios_hwdef
|
|
|
|
|
2019-03-14 20:39:27 -03:00
|
|
|
parser = argparse.ArgumentParser(description='configure all ChibiOS boards')
|
|
|
|
parser.add_argument('--build', action='store_true', default=False, help='build as well as configure')
|
2020-01-18 04:34:49 -04:00
|
|
|
parser.add_argument('--build-target', default='copter', help='build target')
|
2022-06-24 00:03:30 -03:00
|
|
|
parser.add_argument('--stop', action='store_true', default=False, help='stop on configure or build failure')
|
2019-09-10 17:44:00 -03:00
|
|
|
parser.add_argument('--no-bl', action='store_true', default=False, help="don't check bootloader builds")
|
2022-12-04 17:00:28 -04:00
|
|
|
parser.add_argument('--only-bl', action='store_true', default=False, help="only check bootloader builds")
|
2020-04-23 23:27:14 -03:00
|
|
|
parser.add_argument('--Werror', action='store_true', default=False, help="build with -Werror")
|
2019-03-14 20:39:27 -03:00
|
|
|
parser.add_argument('--pattern', default='*')
|
2020-04-24 03:33:16 -03:00
|
|
|
parser.add_argument('--start', default=None, type=int, help='continue from specified build number')
|
2020-01-01 16:43:16 -04:00
|
|
|
parser.add_argument('--python', default='python')
|
2021-10-26 00:25:15 -03:00
|
|
|
parser.add_argument('--copy-hwdef-incs-to-directory', default=None, help='directory hwdefs should be copied to')
|
2019-03-14 20:39:27 -03:00
|
|
|
args = parser.parse_args()
|
2018-07-05 01:15:19 -03:00
|
|
|
|
|
|
|
os.environ['PYTHONUNBUFFERED'] = '1'
|
|
|
|
|
2019-03-14 23:13:48 -03:00
|
|
|
failures = []
|
2020-04-24 03:33:16 -03:00
|
|
|
done = []
|
|
|
|
board_list = []
|
2019-03-14 23:13:48 -03:00
|
|
|
|
2018-07-05 01:15:19 -03:00
|
|
|
def get_board_list():
|
|
|
|
'''add boards based on existance of hwdef-bl.dat in subdirectories for ChibiOS'''
|
|
|
|
board_list = []
|
2020-04-24 03:52:20 -03:00
|
|
|
# these are base builds, and don't build directly
|
2021-05-19 23:17:47 -03:00
|
|
|
omit = []
|
2018-07-05 01:15:19 -03:00
|
|
|
dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ChibiOS/hwdef'))
|
|
|
|
for d in dirlist:
|
|
|
|
hwdef = os.path.join(dirname, d, 'hwdef.dat')
|
2020-04-24 03:52:20 -03:00
|
|
|
if os.path.exists(hwdef) and not d in omit:
|
2018-07-05 01:15:19 -03:00
|
|
|
board_list.append(d)
|
|
|
|
return board_list
|
|
|
|
|
2019-03-14 23:13:48 -03:00
|
|
|
def run_program(cmd_list, build):
|
2018-07-05 01:15:19 -03:00
|
|
|
print("Running (%s)" % " ".join(cmd_list))
|
|
|
|
retcode = subprocess.call(cmd_list)
|
|
|
|
if retcode != 0:
|
2020-04-24 03:33:16 -03:00
|
|
|
print("FAILED BUILD: %s %s" % (build, ' '.join(cmd_list)))
|
2019-03-14 23:13:48 -03:00
|
|
|
global failures
|
|
|
|
failures.append(build)
|
|
|
|
if args.stop:
|
|
|
|
sys.exit(1)
|
2018-07-05 01:15:19 -03:00
|
|
|
|
2020-04-24 03:33:16 -03:00
|
|
|
for board in sorted(get_board_list()):
|
2019-03-14 20:39:27 -03:00
|
|
|
if not fnmatch.fnmatch(board, args.pattern):
|
2018-07-05 01:15:19 -03:00
|
|
|
continue
|
2020-04-24 03:33:16 -03:00
|
|
|
board_list.append(board)
|
|
|
|
|
|
|
|
if args.start is not None:
|
|
|
|
if args.start < 1 or args.start >= len(board_list):
|
|
|
|
print("Invalid start %u for %u boards" % (args.start, len(board_list)))
|
|
|
|
sys.exit(1)
|
|
|
|
board_list = board_list[args.start-1:]
|
|
|
|
|
2021-03-15 02:23:49 -03:00
|
|
|
def is_ap_periph(board):
|
|
|
|
hwdef = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef.dat' % board)
|
2023-05-10 05:46:37 -03:00
|
|
|
ch = chibios_hwdef.ChibiOSHWDef()
|
|
|
|
ch.process_file(hwdef)
|
|
|
|
return ch.is_periph_fw()
|
2021-03-15 02:23:49 -03:00
|
|
|
|
2021-10-26 00:25:15 -03:00
|
|
|
if args.copy_hwdef_incs_to_directory is not None:
|
|
|
|
os.makedirs(args.copy_hwdef_incs_to_directory)
|
2021-03-15 02:23:49 -03:00
|
|
|
|
2023-05-13 07:23:44 -03:00
|
|
|
def handle_hwdef_copy(directory, board, bootloader=False):
|
2023-05-09 05:32:15 -03:00
|
|
|
source = os.path.join("build", board, "hwdef.h")
|
2023-05-13 07:23:44 -03:00
|
|
|
if bootloader:
|
|
|
|
filename = "hwdef-%s-bl.h" % board
|
|
|
|
elif board == "iomcu":
|
2023-05-09 05:32:15 -03:00
|
|
|
filename = "hwdef-%s-iomcu.h" % board
|
|
|
|
elif is_ap_periph(board):
|
|
|
|
filename = "hwdef-%s-periph.h" % board
|
|
|
|
else:
|
|
|
|
filename = "hwdef-%s.h" % board
|
|
|
|
target = os.path.join(directory, filename)
|
|
|
|
shutil.copy(source, target)
|
|
|
|
|
2020-04-24 03:33:16 -03:00
|
|
|
for board in board_list:
|
|
|
|
done.append(board)
|
|
|
|
print("Configuring for %s [%u/%u failed=%u]" % (board, len(done), len(board_list), len(failures)))
|
2020-04-23 23:27:14 -03:00
|
|
|
config_opts = ["--board", board]
|
|
|
|
if args.Werror:
|
|
|
|
config_opts += ["--Werror"]
|
2022-12-04 17:00:28 -04:00
|
|
|
if not args.only_bl:
|
|
|
|
run_program([args.python, "waf", "configure"] + config_opts, "configure: " + board)
|
2023-05-09 05:32:15 -03:00
|
|
|
if args.copy_hwdef_incs_to_directory is not None:
|
|
|
|
handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board)
|
2019-03-14 20:39:27 -03:00
|
|
|
if args.build:
|
2019-03-15 00:12:14 -03:00
|
|
|
if board == "iomcu":
|
|
|
|
target = "iofirmware"
|
2021-03-15 02:23:49 -03:00
|
|
|
elif is_ap_periph(board):
|
2020-01-18 04:34:49 -04:00
|
|
|
target = "AP_Periph"
|
2019-03-15 00:12:14 -03:00
|
|
|
else:
|
2020-01-18 04:34:49 -04:00
|
|
|
target = args.build_target
|
2020-04-23 23:27:14 -03:00
|
|
|
if target.find('/') != -1:
|
|
|
|
run_program([args.python, "waf", "--target", target], "build: " + board)
|
|
|
|
else:
|
|
|
|
run_program([args.python, "waf", target], "build: " + board)
|
2019-09-10 17:44:00 -03:00
|
|
|
if args.no_bl:
|
|
|
|
continue
|
2019-03-14 19:30:59 -03:00
|
|
|
# check for bootloader def
|
|
|
|
hwdef_bl = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef-bl.dat' % board)
|
|
|
|
if os.path.exists(hwdef_bl):
|
|
|
|
print("Configuring bootloader for %s" % board)
|
2020-01-01 16:43:16 -04:00
|
|
|
run_program([args.python, "waf", "configure", "--board", board, "--bootloader"], "configure: " + board + "-bl")
|
2023-05-13 07:23:44 -03:00
|
|
|
if args.copy_hwdef_incs_to_directory is not None:
|
|
|
|
handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board, bootloader=True)
|
2019-03-14 20:39:27 -03:00
|
|
|
if args.build:
|
2020-01-01 16:43:16 -04:00
|
|
|
run_program([args.python, "waf", "bootloader"], "build: " + board + "-bl")
|
2019-03-14 23:13:48 -03:00
|
|
|
|
|
|
|
if len(failures) > 0:
|
|
|
|
print("Failed builds:")
|
|
|
|
for f in failures:
|
|
|
|
print(' ' + f)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sys.exit(0)
|