Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/scripts/configure_all.py
Views: 1798
#!/usr/bin/env python12"""3script to run configre for all hwdef.dat, to check for syntax errors4"""56import os7import subprocess8import sys9import fnmatch10import shutil1112import argparse1314# modify our search path:15sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))16import chibios_hwdef1718parser = argparse.ArgumentParser(description='configure all ChibiOS boards')19parser.add_argument('--build', action='store_true', default=False, help='build as well as configure')20parser.add_argument('--build-target', default='copter', help='build target')21parser.add_argument('--stop', action='store_true', default=False, help='stop on configure or build failure')22parser.add_argument('--no-bl', action='store_true', default=False, help="don't check bootloader builds")23parser.add_argument('--only-bl', action='store_true', default=False, help="only check bootloader builds")24parser.add_argument('--Werror', action='store_true', default=False, help="build with -Werror")25parser.add_argument('--pattern', default='*')26parser.add_argument('--start', default=None, type=int, help='continue from specified build number')27parser.add_argument('--python', default='python')28parser.add_argument('--copy-hwdef-incs-to-directory', default=None, help='directory hwdefs should be copied to')29args = parser.parse_args()3031os.environ['PYTHONUNBUFFERED'] = '1'3233failures = []34done = []35board_list = []3637def get_board_list():38'''add boards based on existance of hwdef-bl.dat in subdirectories for ChibiOS'''39board_list = []40# these are base builds, and don't build directly41omit = []42dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ChibiOS/hwdef'))43for d in dirlist:44hwdef = os.path.join(dirname, d, 'hwdef.dat')45if os.path.exists(hwdef) and d not in omit:46board_list.append(d)47return board_list4849def run_program(cmd_list, build):50print("Running (%s)" % " ".join(cmd_list))51retcode = subprocess.call(cmd_list)52if retcode != 0:53print("FAILED BUILD: %s %s" % (build, ' '.join(cmd_list)))54global failures55failures.append(build)56if args.stop:57sys.exit(1)5859for board in sorted(get_board_list()):60if not fnmatch.fnmatch(board, args.pattern):61continue62board_list.append(board)6364if args.start is not None:65if args.start < 1 or args.start >= len(board_list):66print("Invalid start %u for %u boards" % (args.start, len(board_list)))67sys.exit(1)68board_list = board_list[args.start-1:]6970def is_ap_periph(board):71hwdef = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef.dat' % board)72ch = chibios_hwdef.ChibiOSHWDef()73ch.process_file(hwdef)74return ch.is_periph_fw()7576if args.copy_hwdef_incs_to_directory is not None:77os.makedirs(args.copy_hwdef_incs_to_directory)7879def handle_hwdef_copy(directory, board, bootloader=False):80source = os.path.join("build", board, "hwdef.h")81if bootloader:82filename = "hwdef-%s-bl.h" % board83elif board == "iomcu":84filename = "hwdef-%s-iomcu.h" % board85elif is_ap_periph(board):86filename = "hwdef-%s-periph.h" % board87else:88filename = "hwdef-%s.h" % board89target = os.path.join(directory, filename)90shutil.copy(source, target)9192for board in board_list:93done.append(board)94print("Configuring for %s [%u/%u failed=%u]" % (board, len(done), len(board_list), len(failures)))95config_opts = ["--board", board]96if args.Werror:97config_opts += ["--Werror"]98if not args.only_bl:99run_program([args.python, "waf", "configure"] + config_opts, "configure: " + board)100if args.copy_hwdef_incs_to_directory is not None:101handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board)102if args.build:103if board == "iomcu":104target = "iofirmware"105elif is_ap_periph(board):106target = "AP_Periph"107else:108target = args.build_target109if target.find('/') != -1:110run_program([args.python, "waf", "--target", target], "build: " + board)111else:112run_program([args.python, "waf", target], "build: " + board)113if args.no_bl:114continue115# check for bootloader def116hwdef_bl = os.path.join('libraries/AP_HAL_ChibiOS/hwdef/%s/hwdef-bl.dat' % board)117if os.path.exists(hwdef_bl):118print("Configuring bootloader for %s" % board)119run_program([args.python, "waf", "configure", "--board", board, "--bootloader"], "configure: " + board + "-bl")120if args.copy_hwdef_incs_to_directory is not None:121handle_hwdef_copy(args.copy_hwdef_incs_to_directory, board, bootloader=True)122if args.build:123run_program([args.python, "waf", "bootloader"], "build: " + board + "-bl")124125if len(failures) > 0:126print("Failed builds:")127for f in failures:128print(' ' + f)129sys.exit(1)130131sys.exit(0)132133134