[boards] Support and validate MCU name aliases
This commit is contained in:
2
.github/workflows/push-master.yml
vendored
2
.github/workflows/push-master.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install docs dependencies
|
||||
run: pip install -U ltchiptool boardgen
|
||||
run: pip install -U ltchiptool "boardgen>=0.11.0"
|
||||
|
||||
- name: Generate docs and static JSON files
|
||||
run: |
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
"url": "https://docs.libretiny.eu/boards/t102-v1.1/",
|
||||
"vendor": "Unknown",
|
||||
"doc": {
|
||||
"fccid": "2AU7O-T102V11"
|
||||
"fccid": "2AU7O-T102V11",
|
||||
"mcu": "w302"
|
||||
},
|
||||
"pcb": {
|
||||
"symbol": "T102_V1.1"
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
"url": "https://docs.libretiny.eu/boards/t112-v1.1/",
|
||||
"vendor": "Unknown",
|
||||
"doc": {
|
||||
"fccid": "2AU7O-T102V11"
|
||||
"fccid": "2AU7O-T102V11",
|
||||
"mcu": "w302"
|
||||
},
|
||||
"pcb": {
|
||||
"symbol": "T112_V1.1"
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Copyright (c) Kuba Szczodrzyński 2022-05-31.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
while os.getcwd() in sys.path:
|
||||
sys.path.remove(os.getcwd())
|
||||
|
||||
import re
|
||||
from os.path import dirname, isfile, join
|
||||
|
||||
@@ -48,19 +54,41 @@ def get_families_json() -> dict[str, int]:
|
||||
}
|
||||
|
||||
|
||||
def get_mcus_boards(boards: list[Board]) -> dict[str, str]:
|
||||
def get_mcus_boards(boards: list[Board], aliases: dict[str, str]) -> dict[str, str]:
|
||||
out = {}
|
||||
for board in boards:
|
||||
mcu_name: str = board["build.mcu"].upper()
|
||||
family_name: str = board.family.short_name
|
||||
|
||||
def check_mcu(mcu_name, family_name):
|
||||
if mcu_name in out and out[mcu_name] != family_name:
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: MCU '{mcu_name}' of board '{board.name}' belongs to multiple families: '{out[mcu_name]}' and '{family_name}'"
|
||||
+ Style.RESET_ALL
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
continue
|
||||
out[mcu_name] = family_name
|
||||
|
||||
for board in boards:
|
||||
mcu_name: str = board["build.mcu"].upper()
|
||||
mcu_alias: str = board["doc.mcu"]
|
||||
family_name: str = board.family.short_name
|
||||
check_mcu(mcu_name, family_name)
|
||||
if mcu_alias:
|
||||
mcu_alias = mcu_alias.upper()
|
||||
check_mcu(mcu_alias, family_name)
|
||||
if mcu_alias not in aliases:
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: MCU alias '{mcu_alias}' of board '{board.name}' is not defined in enum"
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
elif aliases[mcu_alias] != mcu_name:
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: MCU alias '{mcu_alias}' of board '{board.name}' doesn't match real name '{mcu_name}'"
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
@@ -315,7 +343,8 @@ if __name__ == "__main__":
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: Invalid build.variant of '{board['source']}': '{board.name}'"
|
||||
+ Style.RESET_ALL
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
errors = True
|
||||
|
||||
@@ -323,8 +352,8 @@ if __name__ == "__main__":
|
||||
families_enum = get_families_enum(code)
|
||||
families_json_keys = set(families_json.keys())
|
||||
families_enum_keys = set(families_enum.keys())
|
||||
mcus_boards = get_mcus_boards(boards)
|
||||
mcus_enum, mcu_aliases = get_mcus_enum(code)
|
||||
mcus_boards = get_mcus_boards(boards, mcu_aliases)
|
||||
mcus_boards_keys = set(mcus_boards.keys())
|
||||
mcus_enum_keys = set(mcus_enum.keys())
|
||||
mcus_missing_in_boards = mcus_enum_keys - mcus_boards_keys
|
||||
@@ -332,14 +361,19 @@ if __name__ == "__main__":
|
||||
|
||||
# check if all families are defined in lt_types.h and families.json
|
||||
if families_json_keys != families_enum_keys:
|
||||
print(Fore.RED + f"ERROR: Inconsistent lt_types.h vs families.json:")
|
||||
print(
|
||||
"- Missing in JSON: " + ", ".join(families_enum_keys - families_json_keys)
|
||||
Fore.RED + f"ERROR: Inconsistent lt_types.h vs families.json:",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
"- Missing in enum: " + ", ".join(families_json_keys - families_enum_keys)
|
||||
"- Missing in JSON: " + ", ".join(families_enum_keys - families_json_keys),
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(Style.RESET_ALL, end="")
|
||||
print(
|
||||
"- Missing in enum: " + ", ".join(families_json_keys - families_enum_keys),
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(Style.RESET_ALL, end="", file=sys.stderr)
|
||||
errors = True
|
||||
|
||||
# verify that family IDs match
|
||||
@@ -352,7 +386,8 @@ if __name__ == "__main__":
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: Family ID mismatch for '{family}': 0x{families_json[family]:08X} vs 0x{families_enum[family]:08X}"
|
||||
+ Style.RESET_ALL
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
errors = True
|
||||
|
||||
@@ -371,7 +406,8 @@ if __name__ == "__main__":
|
||||
Fore.RED
|
||||
+ f"ERROR: Undefined MCUs in lt_types.h: "
|
||||
+ ", ".join(mcus_missing_in_enum)
|
||||
+ Style.RESET_ALL
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
errors = True
|
||||
|
||||
@@ -385,7 +421,8 @@ if __name__ == "__main__":
|
||||
print(
|
||||
Fore.RED
|
||||
+ f"ERROR: MCU family mismatch for '{mcu}': '{mcus_boards[mcu]}' vs '{mcus_enum[mcu]}'"
|
||||
+ Style.RESET_ALL
|
||||
+ Style.RESET_ALL,
|
||||
file=sys.stderr,
|
||||
)
|
||||
errors = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user