- enable --one-per-family to build 1 board per family, also skip family if board specified in -b also present
- minimize ci run for push event
  - only build one board per family
  - skip hil test on both pi4 and hfp
- full build will be runn for PR event
- IAR always build 1 board per family regardless of event 
- update build.py to optimize make
- remove all setup python since we don't really need it
This commit is contained in:
Ha Thach 2024-05-13 20:27:49 +07:00 committed by GitHub
parent 6f47746e5f
commit 7cf1bdd284
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 163 additions and 161 deletions

View File

@ -32,6 +32,7 @@ runs:
- name: Download Toolchain
if: >-
inputs.toolchain != 'arm-gcc' &&
inputs.toolchain != 'arm-iar' &&
inputs.toolchain != 'esp-idf'
uses: ./.github/actions/setup_toolchain/download
with:
@ -44,6 +45,8 @@ runs:
BUILD_OPTION=""
if [[ "${{ inputs.toolchain }}" == *"clang"* ]]; then
BUILD_OPTION="--toolchain clang"
elif [[ "${{ inputs.toolchain }}" == "arm-iar" ]]; then
BUILD_OPTION="--toolchain iar"
fi
echo "build_option=$BUILD_OPTION"
echo "build_option=$BUILD_OPTION" >> $GITHUB_OUTPUT

View File

@ -37,11 +37,6 @@ jobs:
outputs:
json: ${{ steps.set-matrix-json.outputs.matrix }}
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Checkout TinyUSB
uses: actions/checkout@v4
@ -63,27 +58,22 @@ jobs:
matrix:
toolchain:
- 'aarch64-gcc'
- 'arm-clang'
# - 'arm-clang'
- 'arm-gcc'
- 'msp430-gcc'
- 'riscv-gcc'
if: >-
matrix.toolchain != 'arm-clang' ||
github.event_name == 'pull_request' ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
with:
build-system: 'cmake'
toolchain: ${{ matrix.toolchain }}
toolchain_url: ${{ fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].toolchain_url }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
one-per-family: ${{ github.event_name != 'pull_request' }}
# ---------------------------------------
# Build Make
# ---------------------------------------
make:
if: >-
github.event_name == 'pull_request' ||
(github.event_name == 'push' && github.ref == 'refs/heads/master')
#if: github.event_name == 'pull_request'
needs: set-matrix
uses: ./.github/workflows/build_util.yml
strategy:
@ -100,6 +90,7 @@ jobs:
toolchain: ${{ matrix.toolchain }}
toolchain_url: ${{ fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].toolchain_url }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
one-per-family: ${{ github.event_name != 'pull_request' }}
# ---------------------------------------
# Build Make on Windows/MacOS
@ -114,7 +105,8 @@ jobs:
os: ${{ matrix.os }}
build-system: 'make'
toolchain: 'arm-gcc'
build-args: '["-bstm32f411disco"]'
build-args: '["stm32h7"]'
one-per-family: true
# ---------------------------------------
# Build Espressif
@ -134,3 +126,33 @@ jobs:
toolchain: 'esp-idf'
toolchain_url: 'v5.1.1'
build-args: '["-b${{ matrix.board }}"]'
# ---------------------------------------
# Build IAR on HFP self-hosted
# ---------------------------------------
arm-iar:
if: github.repository_owner == 'hathach'
needs: set-matrix
runs-on: [self-hosted, Linux, X64, hifiphile]
env:
BUILD_ARGS: ${{ join(fromJSON(needs.set-matrix.outputs.json)['arm-iar'].family, ' ') }}
steps:
- name: Clean workspace
run: |
echo "Cleaning up previous run"
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
- name: Checkout TinyUSB
uses: actions/checkout@v4
- name: Get Dependencies
run: python3 tools/get_deps.py $BUILD_ARGS
- name: Build
run: python3 tools/build.py --one-per-family --toolchain iar $BUILD_ARGS
- name: Test on actual hardware (hardware in the loop)
if: github.event_name == 'pull_request'
run: |
python3 test/hil/hil_test.py hfp.json

View File

@ -1,50 +0,0 @@
name: Build IAR
on:
workflow_dispatch:
pull_request:
branches: [ master ]
paths:
- 'src/**'
- 'examples/**'
- 'lib/**'
- 'hw/**'
- 'tools/get_deps.py'
- 'test/hil/**'
- '.github/workflows/build_iar.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
cmake:
if: github.repository_owner == 'hathach'
runs-on: [self-hosted, Linux, X64, hifiphile]
strategy:
fail-fast: false
matrix:
family:
# Alphabetical order
# Note: bundle multiple families into a matrix since there is only one self-hosted instance can
# run IAR build. Too many matrix can hurt due to setup/teardown overhead.
- 'lpc43 stm32f0 stm32f1 stm32f7 stm32g0 stm32g4 stm32l4'
steps:
- name: Clean workspace
run: |
echo "Cleaning up previous run"
rm -rf "${{ github.workspace }}"
mkdir -p "${{ github.workspace }}"
- name: Checkout TinyUSB
uses: actions/checkout@v4
- name: Get Dependencies
run: python3 tools/get_deps.py ${{ matrix.family }}
- name: Build
run: python3 tools/build.py --toolchain iar ${{ matrix.family }}
- name: Test on actual hardware (hardware in the loop)
run: |
python3 test/hil/hil_test.py hfp.json

View File

@ -34,11 +34,6 @@ jobs:
# Alphabetical order
- 'rx'
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Checkout TinyUSB
uses: actions/checkout@v4

View File

@ -15,6 +15,10 @@ on:
build-args:
required: true
type: string
one-per-family:
required: false
default: false
type: boolean
os:
required: false
type: string
@ -31,11 +35,6 @@ jobs:
- name: Checkout TinyUSB
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Setup Toolchain
id: setup-toolchain
uses: ./.github/actions/setup_toolchain
@ -48,10 +47,20 @@ jobs:
with:
arg: ${{ matrix.arg }}
- name: Set build one-per-family option
id: set-one-per-family
run: |
if [[ "${{ inputs.one-per-family }}" == "true" ]]; then
BUILD_OPTION="--one-per-family"
fi
echo "build_option=$BUILD_OPTION"
echo "build_option=$BUILD_OPTION" >> $GITHUB_OUTPUT
shell: bash
- name: Build
if: inputs.toolchain != 'esp-idf'
run: |
python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ matrix.arg }}
python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ steps.set-one-per-family.outputs.build_option }} ${{ matrix.arg }}
- name: Build using ESP-IDF docker
if: inputs.toolchain == 'esp-idf'

View File

@ -4,6 +4,7 @@ import json
toolchain_list = {
"aarch64-gcc": "https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz",
"arm-clang": "https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-17.0.1/LLVMEmbeddedToolchainForArm-17.0.1-Linux-x86_64.tar.xz",
"arm-iar": "",
"arm-gcc": "",
"msp430-gcc": "http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/9_2_0_0/export/msp430-gcc-9.2.0.50_linux64.tar.bz2",
"riscv-gcc": "https://github.com/xpack-dev-tools/riscv-none-embed-gcc-xpack/releases/download/v10.1.0-1.1/xpack-riscv-none-embed-gcc-10.1.0-1.1-linux-x64.tar.gz",
@ -28,12 +29,12 @@ family_list = {
"rp2040": ["arm-gcc"],
"samd11 samd21 saml2x": ["arm-gcc", "arm-clang"],
"samd5x_e5x samg": ["arm-gcc", "arm-clang"],
"stm32f0 stm32f1 stm32f2 stm32f3": ["arm-gcc", "arm-clang"],
"stm32f4": ["arm-gcc", "arm-clang"],
"stm32f7": ["arm-gcc", "arm-clang"],
"stm32g0 stm32g4 stm32h5": ["arm-gcc", "arm-clang"],
"stm32h7": ["arm-gcc", "arm-clang"],
"stm32l4 stm32u5 stm32wb": ["arm-gcc", "arm-clang"],
"stm32f0 stm32f1 stm32f2 stm32f3": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f4": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32f7": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32g0 stm32g4 stm32h5": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32h7": ["arm-gcc", "arm-clang", "arm-iar"],
"stm32l4 stm32u5 stm32wb": ["arm-gcc", "arm-clang", "arm-iar"],
"xmc4000": ["arm-gcc"],
}
@ -43,7 +44,16 @@ def set_matrix_json():
for toolchain in toolchain_list.keys():
filtered_families = [family for family, supported_toolchain in family_list.items() if
toolchain in supported_toolchain]
# always add board in hfp.json for arm-iar
if toolchain == 'arm-iar':
with open('test/hil/hfp.json') as f:
hfp_data = json.load(f)
hfp_boards = [f"-b{board['name']}" for board in hfp_data['boards']]
filtered_families = filtered_families + hfp_boards
matrix[toolchain] = {"family": filtered_families, "toolchain_url": toolchain_list[toolchain]}
print(json.dumps(matrix))

View File

@ -30,11 +30,6 @@ jobs:
- name: Checkout TinyUSB
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Parse HIL json
id: parse_hil_json
run: |
@ -78,11 +73,6 @@ jobs:
- name: Checkout TinyUSB
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Parse HIL json
id: parse_hil_json
run: |
@ -131,7 +121,7 @@ jobs:
- build-esp
runs-on: [self-hosted, rp2040, nrf52840, esp32s3, hardware-in-the-loop]
env:
BOARDS_LIST: "${{ needs.build.outputs.BOARDS_LIST }} ${{ needs.build-esp.outputs.BOARDS_LIST }}"
BOARDS_LIST: "${{ needs.build.outputs.BOARDS_LIST }} ${{ needs.build-esp.outputs.BOARDS_LIST }}"
steps:
- name: Clean workspace
run: |

View File

@ -14,11 +14,6 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:

View File

@ -115,7 +115,7 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

View File

@ -124,7 +124,7 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
GPIO_PinState pin_state = (GPIO_PinState)(state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}

View File

@ -108,7 +108,8 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}
uint32_t board_button_read(void) {

View File

@ -108,7 +108,8 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}
uint32_t board_button_read(void) {
@ -142,7 +143,7 @@ uint32_t board_millis(void) {
#endif
void HardFault_Handler(void) {
asm("bkpt");
asm("bkpt 0");
}
// Required by __libc_init_array in startup code if we are compiling using

View File

@ -203,7 +203,8 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}
uint32_t board_button_read(void) {

View File

@ -136,7 +136,8 @@ void board_init(void) {
//--------------------------------------------------------------------+
void board_led_write(bool state) {
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1 - LED_STATE_ON));
GPIO_PinState pin_state = (GPIO_PinState) (state ? LED_STATE_ON : (1 - LED_STATE_ON));
HAL_GPIO_WritePin(LED_PORT, LED_PIN, pin_state);
}
uint32_t board_button_read(void) {
@ -174,7 +175,7 @@ uint32_t board_millis(void) {
#endif
void HardFault_Handler(void) {
asm("bkpt");
asm("bkpt 1");
}
// Required by __libc_init_array in startup code if we are compiling using

View File

@ -1,4 +1,5 @@
import argparse
import random
import os
import sys
import time
@ -96,32 +97,61 @@ def build_board_cmake(board, toolchain):
return ret
def build_family(family, toolchain, build_system):
def build_board_make_all_examples(board, toolchain, all_examples):
start_time = time.monotonic()
ret = [0, 0, 0]
with Pool(processes=os.cpu_count()) as pool:
pool_args = list((map(lambda e, b=board, o=f"TOOLCHAIN={toolchain}": [e, b, o], all_examples)))
r = pool.starmap(build_utils.build_example, pool_args)
# sum all element of same index (column sum)
rsum = list(map(sum, list(zip(*r))))
ret[0] += rsum[0]
ret[1] += rsum[1]
ret[2] += rsum[2]
duration = time.monotonic() - start_time
if ret[1] == 0:
status = SUCCEEDED
else:
status = FAILED
flash_size = "-"
sram_size = "-"
example = 'all'
title = build_utils.build_format.format(example, board, status, "{:.2f}s".format(duration), flash_size, sram_size)
print(title)
return ret
def build_family(family, toolchain, build_system, one_per_family, boards):
all_boards = []
for entry in os.scandir(f"hw/bsp/{family}/boards"):
if entry.is_dir() and entry.name != 'pico_sdk':
all_boards.append(entry.name)
all_boards.sort()
# success, failed, skipped
ret = [0, 0, 0]
if build_system == 'cmake':
for board in all_boards:
if build_board_cmake(board, toolchain):
ret[0] += 1
else:
ret[1] += 1
elif build_system == 'make':
all_examples = get_examples(family)
for example in all_examples:
with Pool(processes=os.cpu_count()) as pool:
pool_args = list((map(lambda b, e=example, o=f"TOOLCHAIN={toolchain}": [e, b, o], all_boards)))
r = pool.starmap(build_utils.build_example, pool_args)
# sum all element of same index (column sum)
rsum = list(map(sum, list(zip(*r))))
ret[0] += rsum[0]
ret[1] += rsum[1]
ret[2] += rsum[2]
# If only-one flag is set, select one random board
if one_per_family:
for b in boards:
# skip if -b already specify one in this family
if find_family(b) == family:
return ret
all_boards = [random.choice(all_boards)]
# success, failed, skipped
all_examples = get_examples(family)
for board in all_boards:
r = [0, 0, 0]
if build_system == 'cmake':
r = build_board_cmake(board, toolchain)
elif build_system == 'make':
r = build_board_make_all_examples(board, toolchain, all_examples)
ret[0] += r[0]
ret[1] += r[1]
ret[2] += r[2]
return ret
@ -131,12 +161,14 @@ def main():
parser.add_argument('-b', '--board', action='append', default=[], help='Boards to build')
parser.add_argument('-t', '--toolchain', default='gcc', help='Toolchain to use, default is gcc')
parser.add_argument('-s', '--build-system', default='cmake', help='Build system to use, default is cmake')
parser.add_argument('-1', '--one-per-family', action='store_true', default=False, help='Build only one random board inside a family')
args = parser.parse_args()
families = args.families
boards = args.board
toolchain = args.toolchain
build_system = args.build_system
one_per_family = args.one_per_family
if len(families) == 0 and len(boards) == 0:
print("Please specify families or board to build")
@ -145,50 +177,42 @@ def main():
print(build_separator)
print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM'))
total_time = time.monotonic()
total_result = [0, 0, 0]
result = [0, 0, 0]
# build families: cmake, make
if families is not None:
all_families = []
if 'all' in families:
for entry in os.scandir("hw/bsp"):
if entry.is_dir() and entry.name != 'espressif' and os.path.isfile(entry.path + "/family.cmake"):
all_families.append(entry.name)
else:
all_families = list(families)
all_families.sort()
# build families
all_families = []
if 'all' in families:
for entry in os.scandir("hw/bsp"):
if entry.is_dir() and entry.name != 'espressif' and os.path.isfile(entry.path + "/family.cmake"):
all_families.append(entry.name)
else:
all_families = list(families)
all_families.sort()
# succeeded, failed
for f in all_families:
fret = build_family(f, toolchain, build_system)
total_result[0] += fret[0]
total_result[1] += fret[1]
total_result[2] += fret[2]
# succeeded, failed
for f in all_families:
fret = build_family(f, toolchain, build_system, one_per_family, boards)
result[0] += fret[0]
result[1] += fret[1]
result[2] += fret[2]
# build board (only cmake)
if boards is not None:
for b in boards:
if build_system == 'cmake':
r = build_board_cmake(b, toolchain)
total_result[0] += r[0]
total_result[1] += r[1]
total_result[2] += r[2]
elif build_system == 'make':
all_examples = get_examples(find_family(b))
with Pool(processes=os.cpu_count()) as pool:
pool_args = list((map(lambda e, bb=b, o=f"TOOLCHAIN={toolchain}": [e, bb, o], all_examples)))
r = pool.starmap(build_utils.build_example, pool_args)
# sum all element of same index (column sum)
rsum = list(map(sum, list(zip(*r))))
total_result[0] += rsum[0]
total_result[1] += rsum[1]
total_result[2] += rsum[2]
# build boards
for b in boards:
r = [0, 0, 0]
if build_system == 'cmake':
r = build_board_cmake(b, toolchain)
elif build_system == 'make':
all_examples = get_examples(find_family(b))
r = build_board_make_all_examples(b, toolchain, all_examples)
result[0] += r[0]
result[1] += r[1]
result[2] += r[2]
total_time = time.monotonic() - total_time
print(build_separator)
print(f"Build Summary: {total_result[0]} {SUCCEEDED}, {total_result[1]} {FAILED} and took {total_time:.2f}s")
print(f"Build Summary: {result[0]} {SUCCEEDED}, {result[1]} {FAILED} and took {total_time:.2f}s")
print(build_separator)
return total_result[1]
return result[1]
if __name__ == '__main__':