2021-03-22 07:58:22 -03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
""" Script to generate a JSON config with all build targets (for CI) """
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
import re
|
2021-10-26 11:15:39 -03:00
|
|
|
from kconfiglib import Kconfig
|
|
|
|
|
|
|
|
kconf = Kconfig()
|
|
|
|
|
|
|
|
# Supress warning output
|
|
|
|
kconf.warn_assign_undef = False
|
|
|
|
kconf.warn_assign_override = False
|
|
|
|
kconf.warn_assign_redun = False
|
2021-03-22 07:58:22 -03:00
|
|
|
|
|
|
|
source_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Generate build targets')
|
|
|
|
|
|
|
|
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
|
|
|
|
help='Verbose Output')
|
|
|
|
parser.add_argument('-p', '--pretty', dest='pretty', action='store_true',
|
|
|
|
help='Pretty output instead of a single line')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
verbose = args.verbose
|
|
|
|
|
|
|
|
build_configs = []
|
2022-12-12 12:46:33 -04:00
|
|
|
excluded_boards = ['modalai_voxl2', 'px4_ros2'] # TODO: fix and enable
|
2021-03-22 07:58:22 -03:00
|
|
|
excluded_manufacturers = ['atlflight']
|
|
|
|
excluded_platforms = ['qurt']
|
2021-03-22 09:36:55 -03:00
|
|
|
excluded_labels = [
|
|
|
|
'stackcheck',
|
|
|
|
'nolockstep', 'replay', 'test',
|
2022-09-23 17:40:56 -03:00
|
|
|
'uavcanv1', # TODO: fix and enable
|
2021-03-22 09:36:55 -03:00
|
|
|
]
|
2021-03-22 07:58:22 -03:00
|
|
|
|
2021-10-26 11:15:39 -03:00
|
|
|
def process_target(px4board_file, target_name):
|
2021-03-22 07:58:22 -03:00
|
|
|
ret = None
|
|
|
|
platform = None
|
|
|
|
toolchain = None
|
|
|
|
|
2021-12-09 06:35:59 -04:00
|
|
|
if px4board_file.endswith("default.px4board") or \
|
|
|
|
px4board_file.endswith("recovery.px4board") or \
|
|
|
|
px4board_file.endswith("bootloader.px4board"):
|
2021-10-26 11:15:39 -03:00
|
|
|
kconf.load_config(px4board_file, replace=True)
|
|
|
|
else: # Merge config with default.px4board
|
|
|
|
default_kconfig = re.sub(r'[a-zA-Z\d_]+\.px4board', 'default.px4board', px4board_file)
|
|
|
|
kconf.load_config(default_kconfig, replace=True)
|
|
|
|
kconf.load_config(px4board_file, replace=False)
|
|
|
|
|
|
|
|
if "BOARD_TOOLCHAIN" in kconf.syms:
|
|
|
|
toolchain = kconf.syms["BOARD_TOOLCHAIN"].str_value
|
|
|
|
|
|
|
|
if "BOARD_PLATFORM" in kconf.syms:
|
|
|
|
platform = kconf.syms["BOARD_PLATFORM"].str_value
|
|
|
|
|
|
|
|
assert platform, f"PLATFORM not found in {px4board_file}"
|
|
|
|
|
|
|
|
if platform not in excluded_platforms:
|
|
|
|
# get the container based on the platform and toolchain
|
|
|
|
if platform == 'posix':
|
2023-07-18 14:18:01 -03:00
|
|
|
container = 'px4io/px4-dev-base-focal:2021-09-08'
|
2021-10-26 11:15:39 -03:00
|
|
|
if toolchain:
|
|
|
|
if toolchain.startswith('aarch64'):
|
2023-07-18 14:24:33 -03:00
|
|
|
container = 'px4io/px4-dev-aarch64:2022-08-12'
|
2021-10-26 11:15:39 -03:00
|
|
|
elif toolchain == 'arm-linux-gnueabihf':
|
2023-07-18 14:24:33 -03:00
|
|
|
container = 'px4io/px4-dev-armhf:2023-06-26'
|
2021-10-26 11:15:39 -03:00
|
|
|
else:
|
2023-07-18 14:18:01 -03:00
|
|
|
if verbose: print(f'unmatched toolchain: {toolchain}')
|
2021-10-26 11:15:39 -03:00
|
|
|
elif platform == 'nuttx':
|
2023-07-18 14:24:33 -03:00
|
|
|
container = 'px4io/px4-dev-nuttx-focal:2022-08-12'
|
2023-07-18 14:18:01 -03:00
|
|
|
else:
|
|
|
|
if verbose: print(f'unmatched platform: {platform}')
|
2021-10-26 11:15:39 -03:00
|
|
|
|
|
|
|
ret = {'target': target_name, 'container': container}
|
|
|
|
|
2021-03-22 07:58:22 -03:00
|
|
|
return ret
|
|
|
|
|
|
|
|
for manufacturer in os.scandir(os.path.join(source_dir, 'boards')):
|
|
|
|
if not manufacturer.is_dir():
|
|
|
|
continue
|
|
|
|
if manufacturer.name in excluded_manufacturers:
|
|
|
|
if verbose: print(f'excluding manufacturer {manufacturer.name}')
|
|
|
|
continue
|
|
|
|
|
|
|
|
for board in os.scandir(manufacturer.path):
|
|
|
|
if not board.is_dir():
|
|
|
|
continue
|
2022-09-24 12:27:31 -03:00
|
|
|
|
2021-03-22 07:58:22 -03:00
|
|
|
for files in os.scandir(board.path):
|
2021-10-26 11:15:39 -03:00
|
|
|
if files.is_file() and files.name.endswith('.px4board'):
|
2022-09-24 12:27:31 -03:00
|
|
|
|
|
|
|
board_name = manufacturer.name + '_' + board.name
|
2021-10-26 11:15:39 -03:00
|
|
|
label = files.name[:-9]
|
2021-03-22 07:58:22 -03:00
|
|
|
target_name = manufacturer.name + '_' + board.name + '_' + label
|
2022-09-24 12:27:31 -03:00
|
|
|
|
|
|
|
if board_name in excluded_boards:
|
|
|
|
if verbose: print(f'excluding board {board_name} ({target_name})')
|
|
|
|
continue
|
|
|
|
|
2021-03-22 07:58:22 -03:00
|
|
|
if label in excluded_labels:
|
|
|
|
if verbose: print(f'excluding label {label} ({target_name})')
|
|
|
|
continue
|
|
|
|
target = process_target(files.path, target_name)
|
|
|
|
if target is not None:
|
|
|
|
build_configs.append(target)
|
|
|
|
|
|
|
|
|
|
|
|
github_action_config = { 'include': build_configs }
|
|
|
|
extra_args = {}
|
|
|
|
if args.pretty:
|
|
|
|
extra_args['indent'] = 2
|
|
|
|
print(json.dumps(github_action_config, **extra_args))
|