fix: Categorizing waveshare products (#1734)

content: Update the README.md

ci: Adapt to the lower directory

ci: the lower directory support

ci: board type errors fixed.

ci: board_type errors fixed to board_leaf.

fix: A naming error problem

fix: jd9365 member error

fix: Update product naming

feat: Add manufacturer parameters to the firmware name for 'release'

fix: Verification logic

fix: Verification logic
This commit is contained in:
Y1hsiaochunnn
2026-02-04 21:03:23 +08:00
committed by GitHub
parent 173eaa7463
commit 6f71868bad
128 changed files with 1977 additions and 1345 deletions

View File

@ -57,13 +57,19 @@ def zip_bin(name: str, version: str) -> None:
zipf.write("build/merged-binary.bin", arcname="merged-binary.bin")
print(f"zip bin to {output_path} done")
def _get_manufacturer(cfg: dict) -> Optional[str]:
"""Read manufacturer from config.json"""
m = cfg.get("manufacturer")
if isinstance(m, str) and m.strip():
return m.strip()
return None
################################################################################
# board / variant related functions
################################################################################
_BOARDS_DIR = Path("main/boards")
def _collect_variants(config_filename: str = "config.json") -> list[dict[str, str]]:
"""Traverse all boards under main/boards, collect variant information.
@ -71,25 +77,30 @@ def _collect_variants(config_filename: str = "config.json") -> list[dict[str, st
[{"board": "bread-compact-ml307", "name": "bread-compact-ml307"}, ...]
"""
variants: list[dict[str, str]] = []
for board_path in _BOARDS_DIR.iterdir():
if not board_path.is_dir():
continue
if board_path.name == "common":
continue
cfg_path = board_path / config_filename
if not cfg_path.exists():
print(f"[WARN] {cfg_path} does not exist, skip", file=sys.stderr)
for cfg_path in _BOARDS_DIR.rglob(config_filename):
board_dir = cfg_path.parent
if board_dir.name == "common":
continue
board = board_dir.relative_to(_BOARDS_DIR).as_posix()
try:
with cfg_path.open() as f:
cfg = json.load(f)
for build in cfg.get("builds", []):
variants.append({"board": board_path.name, "name": build["name"]})
name = build["name"]
variants.append({
"board": board,
"name": name
})
except Exception as e:
print(f"[ERROR] 解析 {cfg_path} 失败: {e}", file=sys.stderr)
return variants
def _parse_board_config_map() -> dict[str, str]:
"""Build the mapping of CONFIG_BOARD_TYPE_xxx and board_type from main/CMakeLists.txt"""
cmake_file = Path("main/CMakeLists.txt")
@ -160,9 +171,10 @@ def _apply_auto_selects(sdkconfig_append: list[str]) -> list[str]:
################################################################################
def _board_type_exists(board_type: str) -> bool:
cmake_file = Path("main/CMakeLists.txt")
pattern = f'set(BOARD_TYPE "{board_type}")'
return pattern in cmake_file.read_text(encoding="utf-8")
cmake_file = Path("main/CMakeLists.txt").read_text(encoding="utf-8")
board_leaf = board_type.split("/")[-1]
pattern = f'set(BOARD_TYPE "{board_leaf}")'
return pattern in cmake_file
################################################################################
# Compile implementation
@ -176,7 +188,7 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
config_filename: config.json name (default: config.json)
filter_name: if specified, only compile the build["name"] that matches
"""
cfg_path = _BOARDS_DIR / board_type / config_filename
cfg_path = _BOARDS_DIR / Path(board_type) / config_filename
if not cfg_path.exists():
print(f"[WARN] {cfg_path} 不存在,跳过 {board_type}")
return
@ -187,6 +199,7 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
with cfg_path.open() as f:
cfg = json.load(f)
target = cfg["target"]
manufacturer = _get_manufacturer(cfg)
builds = cfg.get("builds", [])
if filter_name:
@ -197,12 +210,15 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
for build in builds:
name = build["name"]
if not name.startswith(board_type):
raise ValueError(f"build.name {name} 必须以 {board_type} 开头")
board_leaf = board_type.split("/")[-1]
output_path = Path("releases") / f"v{project_version}_{name}.zip"
if board_leaf not in name:
raise ValueError(f"build.name {name} 必须包含 {board_leaf}")
final_name = f"{manufacturer}-{name}" if manufacturer else name
output_path = Path("releases") / f"v{project_version}_{final_name}.zip"
if output_path.exists():
print(f"跳过 {name} 因为 {output_path} 已存在")
print(f"跳过 {final_name} 因为 {output_path} 已存在")
continue
# Process sdkconfig_append
@ -212,8 +228,10 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
sdkconfig_append = _apply_auto_selects(sdkconfig_append)
print("-" * 80)
print(f"name: {name}")
print(f"name: {final_name}")
print(f"target: {target}")
if manufacturer:
print(f"manufacturer: {manufacturer}")
for item in sdkconfig_append:
print(f"sdkconfig_append: {item}")
@ -239,7 +257,7 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
merge_bin()
# Zip
zip_bin(name, project_version)
zip_bin(final_name, project_version)
################################################################################
# CLI entry
@ -251,7 +269,7 @@ if __name__ == "__main__":
parser.add_argument("-c", "--config", default="config.json", help="指定 config 文件名,默认 config.json")
parser.add_argument("--list-boards", action="store_true", help="列出所有支持的 board 及变体列表")
parser.add_argument("--json", action="store_true", help="配合 --list-boardsJSON 格式输出")
parser.add_argument("--name", help="指定变体名称,仅编译匹配的变体")
parser.add_argument("--name", help="指定变体名称,仅编译匹配的变体使用原始name不带厂商前缀")
args = parser.parse_args()