From cb6f9ea6a1456510629c0b8b2f04532ee0587d19 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 24 Feb 2022 16:34:08 +1100 Subject: [PATCH] Tools: allow specification of AUTOBUILD_TARGETS in hwdef files --- Tools/scripts/board_list.py | 34 ++++++++++++++++++++++++++++++--- Tools/scripts/build_binaries.py | 26 +++++++++++-------------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Tools/scripts/board_list.py b/Tools/scripts/board_list.py index d823dffacd..7306a0cdee 100755 --- a/Tools/scripts/board_list.py +++ b/Tools/scripts/board_list.py @@ -14,6 +14,14 @@ class Board(object): def __init__(self, name): self.name = name self.is_ap_periph = False + self.autobuild_targets = [ + 'AntennaTracker', + 'Blimp', + 'Copter', + 'Heli', + 'Plane', + 'Rover', + ] class BoardList(object): @@ -77,6 +85,13 @@ class BoardList(object): if re.match(r"^\s*env AP_PERIPH_HEAVY 1", line): board.is_ap_periph = 1 + # a hwdef can specify which vehicles this target is valid for: + match = re.match(r"AUTOBUILD_TARGETS\s*(.*)", line) + if match is not None: + board.autobuild_targets = [ + x.rstrip().lstrip().lower() for x in match.group(1).split(",") + ] + def read_hwdef(self, filepath): fh = open(filepath) ret = [] @@ -89,7 +104,7 @@ class BoardList(object): ret += [line] return ret - def find_autobuild_boards(self): + def find_autobuild_boards(self, build_target=None): ret = [] for board in self.boards: if board.is_ap_periph: @@ -136,7 +151,20 @@ class BoardList(object): ret = filter(lambda x : x not in blacklist, ret) - return list(ret) + # if the caller has supplied a vehicle to limit to then we do that here: + if build_target is not None: + # Slow down: n^2 algorithm ahead + newret = [] + for x in ret: + for b in self.boards: + if b.name.lower() != x.lower(): + continue + if build_target.lower() not in [y.lower() for y in b.autobuild_targets]: + continue + newret.append(x) + ret = newret + + return sorted(list(ret)) def find_ap_periph_boards(self): blacklist = [ @@ -159,7 +187,7 @@ class BoardList(object): if x.name in blacklist: continue ret.append(x.name) - return list(ret) + return sorted(list(ret)) AUTOBUILD_BOARDS = BoardList().find_autobuild_boards() diff --git a/Tools/scripts/build_binaries.py b/Tools/scripts/build_binaries.py index d13e4fcd07..4af52ba655 100755 --- a/Tools/scripts/build_binaries.py +++ b/Tools/scripts/build_binaries.py @@ -27,7 +27,8 @@ import generate_manifest import gen_stable import build_binaries_history -from board_list import AUTOBUILD_BOARDS, AP_PERIPH_BOARDS +import board_list +from board_list import AP_PERIPH_BOARDS if sys.version_info[0] < 3: running_python3 = False @@ -67,6 +68,7 @@ class build_binaries(object): def __init__(self, tags): self.tags = tags self.dirty = False + self.board_list = board_list.BoardList() def progress(self, string): '''pretty-print progress''' @@ -535,18 +537,15 @@ is bob we will attempt to checkout bob-AVR''' self.progress("Exception caught: %s" % self.get_exception_stacktrace(e)) - def common_boards(self): - '''returns list of boards common to all vehicles''' - return AUTOBUILD_BOARDS - def AP_Periph_boards(self): return AP_PERIPH_BOARDS def build_arducopter(self, tag): '''build Copter binaries''' + boards = [] - boards.extend(["skyviper-v2450", "aerofc-v1", "bebop", "CubeSolo", "CubeGreen-solo", "skyviper-journey"]) - boards.extend(self.common_boards()[:]) + boards.extend(["aerofc-v1", "bebop"]) + boards.extend(self.board_list.find_autobuild_boards('Copter')) self.build_vehicle(tag, "ArduCopter", boards, @@ -556,7 +555,7 @@ is bob we will attempt to checkout bob-AVR''' def build_arduplane(self, tag): '''build Plane binaries''' - boards = self.common_boards()[:] + boards = self.board_list.find_autobuild_boards('Plane')[:] boards.append("disco") self.build_vehicle(tag, "ArduPlane", @@ -566,19 +565,17 @@ is bob we will attempt to checkout bob-AVR''' def build_antennatracker(self, tag): '''build Tracker binaries''' - boards = self.common_boards()[:] self.build_vehicle(tag, "AntennaTracker", - boards, + self.board_list.find_autobuild_boards('Tracker')[:], "AntennaTracker", "antennatracker") def build_rover(self, tag): '''build Rover binaries''' - boards = self.common_boards() self.build_vehicle(tag, "Rover", - boards, + self.board_list.find_autobuild_boards('Rover')[:], "Rover", "ardurover") @@ -586,7 +583,7 @@ is bob we will attempt to checkout bob-AVR''' '''build Sub binaries''' self.build_vehicle(tag, "ArduSub", - self.common_boards(), + self.board_list.find_autobuild_boards('Sub')[:], "Sub", "ardusub") @@ -601,10 +598,9 @@ is bob we will attempt to checkout bob-AVR''' def build_blimp(self, tag): '''build Blimp binaries''' - boards = self.common_boards() self.build_vehicle(tag, "Blimp", - boards, + self.board_list.find_autobuild_boards('Blimp')[:], "Blimp", "blimp")