mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-02-27 14:26:36 +00:00
Bump project version to 2.2.3 and fix release.py (#1771)
* chore: Bump project version to 2.2.3 and refactor board configuration parsing in release script - Updated PROJECT_VER in CMakeLists.txt from 2.2.2 to 2.2.3. - Refactored the board configuration parsing logic in release.py to improve clarity and efficiency by eliminating the mapping function and directly searching for the board type in the CMakeLists.txt file. * refactor: Remove unused system_info.h include and delete obsolete source root file - Removed the inclusion of system_info.h in main.cc as it was no longer needed. - Deleted the _codeql_detected_source_root file, which was obsolete. * feat: Add lcd_init_cmds.h include for display initialization in esp32-p4-nano board - Included the lcd_init_cmds.h header file in esp32-p4-nano.cc to support display initialization commands, enhancing the board's functionality. * chore: Update build workflow and board configuration files - Changed the build job name in the GitHub Actions workflow to use the full name of the matrix variant for better clarity. - Refactored CMakeLists.txt to improve the formatting of the BOARD_SOURCES file globbing. - Added manufacturer information to the config.json files for the eda-robot-pro, eda-super-bear, and eda-tv-pro boards to ensure consistency in configuration.
This commit is contained in:
@@ -74,9 +74,12 @@ def _collect_variants(config_filename: str = "config.json") -> list[dict[str, st
|
||||
"""Traverse all boards under main/boards, collect variant information.
|
||||
|
||||
Return example:
|
||||
[{"board": "bread-compact-ml307", "name": "bread-compact-ml307"}, ...]
|
||||
[{"board": "bread-compact-ml307", "name": "bread-compact-ml307", "full_name": "bread-compact-ml307"}, ...]
|
||||
[{"board": "waveshare/esp32-p4-nano", "name": "esp32-p4-nano-10.1-a", "full_name": "waveshare-esp32-p4-nano-10.1-a"}, ...]
|
||||
"""
|
||||
variants: list[dict[str, str]] = []
|
||||
errors: list[str] = []
|
||||
|
||||
for cfg_path in _BOARDS_DIR.rglob(config_filename):
|
||||
board_dir = cfg_path.parent
|
||||
if board_dir.name == "common":
|
||||
@@ -87,41 +90,74 @@ def _collect_variants(config_filename: str = "config.json") -> list[dict[str, st
|
||||
with cfg_path.open() as f:
|
||||
cfg = json.load(f)
|
||||
|
||||
manufacturer = _get_manufacturer(cfg)
|
||||
|
||||
# Check manufacturer consistency with directory structure
|
||||
if "/" in board:
|
||||
# Board is in a subdirectory (e.g., waveshare/esp32-p4-nano)
|
||||
expected_manufacturer = board.split("/")[0]
|
||||
if not manufacturer:
|
||||
errors.append(
|
||||
f"{cfg_path}: Board is in '{expected_manufacturer}/' subdirectory, "
|
||||
f"but config.json is missing \"manufacturer\": \"{expected_manufacturer}\""
|
||||
)
|
||||
elif manufacturer != expected_manufacturer:
|
||||
errors.append(
|
||||
f"{cfg_path}: manufacturer mismatch, "
|
||||
f"directory is '{expected_manufacturer}/' but config.json has \"{manufacturer}\""
|
||||
)
|
||||
else:
|
||||
# Board is directly under boards/ directory
|
||||
if manufacturer:
|
||||
errors.append(
|
||||
f"{cfg_path}: Board is not in a manufacturer subdirectory, "
|
||||
f"but config.json defines manufacturer \"{manufacturer}\", "
|
||||
f"please move board to main/boards/{manufacturer}/{board}/"
|
||||
)
|
||||
|
||||
for build in cfg.get("builds", []):
|
||||
name = build["name"]
|
||||
full_name = f"{manufacturer}-{name}" if manufacturer else name
|
||||
variants.append({
|
||||
"board": board,
|
||||
"name": name
|
||||
"name": name,
|
||||
"full_name": full_name
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] 解析 {cfg_path} 失败: {e}", file=sys.stderr)
|
||||
print(f"[ERROR] Failed to parse {cfg_path}: {e}", file=sys.stderr)
|
||||
|
||||
# Report all errors at once
|
||||
if errors:
|
||||
print("\n[ERROR] Found manufacturer configuration issues:", file=sys.stderr)
|
||||
for err in errors:
|
||||
print(f" - {err}", file=sys.stderr)
|
||||
print(file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
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")
|
||||
mapping: dict[str, str] = {}
|
||||
lines = cmake_file.read_text(encoding="utf-8").splitlines()
|
||||
for idx, line in enumerate(lines):
|
||||
if "if(CONFIG_BOARD_TYPE_" in line:
|
||||
config_name = line.strip().split("if(")[1].split(")")[0]
|
||||
if idx + 1 < len(lines):
|
||||
next_line = lines[idx + 1].strip()
|
||||
if next_line.startswith("set(BOARD_TYPE"):
|
||||
board_type = next_line.split('"')[1]
|
||||
mapping[config_name] = board_type
|
||||
return mapping
|
||||
|
||||
|
||||
def _find_board_config(board_type: str) -> Optional[str]:
|
||||
"""Find the corresponding CONFIG_BOARD_TYPE_xxx for the given board_type"""
|
||||
for config, b_type in _parse_board_config_map().items():
|
||||
if b_type == board_type:
|
||||
return config
|
||||
"""Find the corresponding CONFIG_BOARD_TYPE_xxx for the given board_type
|
||||
|
||||
Search backwards from 'set(BOARD_TYPE "xxx")' to find the nearest if(CONFIG_BOARD_TYPE_).
|
||||
"""
|
||||
board_leaf = board_type.split("/")[-1]
|
||||
pattern = f'set(BOARD_TYPE "{board_leaf}")'
|
||||
|
||||
cmake_file = Path("main/CMakeLists.txt")
|
||||
lines = cmake_file.read_text(encoding="utf-8").splitlines()
|
||||
|
||||
for idx, line in enumerate(lines):
|
||||
if pattern in line:
|
||||
# Found the BOARD_TYPE line, search backwards for the config
|
||||
for back_idx in range(idx - 1, -1, -1):
|
||||
back_line = lines[back_idx]
|
||||
if "if(CONFIG_BOARD_TYPE_" in back_line:
|
||||
return back_line.strip().split("if(")[1].split(")")[0]
|
||||
break
|
||||
return None
|
||||
|
||||
|
||||
@@ -190,7 +226,7 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
|
||||
"""
|
||||
cfg_path = _BOARDS_DIR / Path(board_type) / config_filename
|
||||
if not cfg_path.exists():
|
||||
print(f"[WARN] {cfg_path} 不存在,跳过 {board_type}")
|
||||
print(f"[WARN] {cfg_path} does not exist, skipping {board_type}")
|
||||
return
|
||||
|
||||
project_version = get_project_version()
|
||||
@@ -205,7 +241,7 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
|
||||
if filter_name:
|
||||
builds = [b for b in builds if b["name"] == filter_name]
|
||||
if not builds:
|
||||
print(f"[ERROR] 未在 {board_type} 的 {config_filename} 中找到变体 {filter_name}", file=sys.stderr)
|
||||
print(f"[ERROR] Variant {filter_name} not found in {board_type}'s {config_filename}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
for build in builds:
|
||||
@@ -213,12 +249,12 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
|
||||
board_leaf = board_type.split("/")[-1]
|
||||
|
||||
if board_leaf not in name:
|
||||
raise ValueError(f"build.name {name} 必须包含 {board_leaf}")
|
||||
raise ValueError(f"build.name {name} must contain {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"跳过 {final_name} 因为 {output_path} 已存在")
|
||||
print(f"Skipping {final_name} because {output_path} already exists")
|
||||
continue
|
||||
|
||||
# Process sdkconfig_append
|
||||
@@ -265,11 +301,11 @@ def release(board_type: str, config_filename: str = "config.json", *, filter_nam
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("board", nargs="?", default=None, help="板子类型或 all")
|
||||
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-boards,JSON 格式输出")
|
||||
parser.add_argument("--name", help="指定变体名称,仅编译匹配的变体(使用原始name,不带厂商前缀)")
|
||||
parser.add_argument("board", nargs="?", default=None, help="Board type or 'all'")
|
||||
parser.add_argument("-c", "--config", default="config.json", help="Config filename (default: config.json)")
|
||||
parser.add_argument("--list-boards", action="store_true", help="List all supported boards and variants")
|
||||
parser.add_argument("--json", action="store_true", help="Output in JSON format (use with --list-boards)")
|
||||
parser.add_argument("--name", help="Variant name to compile (original name without manufacturer prefix)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -288,7 +324,7 @@ if __name__ == "__main__":
|
||||
merge_bin()
|
||||
curr_board_type = get_board_type_from_compile_commands()
|
||||
if curr_board_type is None:
|
||||
print("未能从 compile_commands.json 解析 board_type", file=sys.stderr)
|
||||
print("Failed to parse board_type from compile_commands.json", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
project_ver = get_project_version()
|
||||
zip_bin(curr_board_type, project_ver)
|
||||
@@ -300,7 +336,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Check board_type in CMakeLists
|
||||
if board_type_input != "all" and not _board_type_exists(board_type_input):
|
||||
print(f"[ERROR] main/CMakeLists.txt 中未找到 board_type {board_type_input}", file=sys.stderr)
|
||||
print(f"[ERROR] board_type {board_type_input} not found in main/CMakeLists.txt", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
variants_all = _collect_variants(config_filename=args.config)
|
||||
@@ -314,10 +350,10 @@ if __name__ == "__main__":
|
||||
|
||||
for bt in sorted(target_board_types):
|
||||
if not _board_type_exists(bt):
|
||||
print(f"[ERROR] main/CMakeLists.txt 中未找到 board_type {bt}", file=sys.stderr)
|
||||
print(f"[ERROR] board_type {bt} not found in main/CMakeLists.txt", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
cfg_path = _BOARDS_DIR / bt / args.config
|
||||
if bt == board_type_input and not cfg_path.exists():
|
||||
print(f"开发板 {bt} 未定义 {args.config} 配置文件,跳过")
|
||||
print(f"Board {bt} has no {args.config} config file, skipping")
|
||||
sys.exit(0)
|
||||
release(bt, config_filename=args.config, filter_name=name_filter if bt == board_type_input else None)
|
||||
|
||||
Reference in New Issue
Block a user