()
| 180 | |
| 181 | |
| 182 | def main() -> int: |
| 183 | args = parse_args() |
| 184 | if args.cwd: |
| 185 | root_build_dir = args.cwd / ".build" |
| 186 | else: |
| 187 | root_build_dir = Path(".build") |
| 188 | |
| 189 | # Support nested PlatformIO structure: .build/pio/<board> |
| 190 | nested_pio_dir = root_build_dir / "pio" |
| 191 | if nested_pio_dir.is_dir(): |
| 192 | root_build_dir = nested_pio_dir |
| 193 | |
| 194 | board_dirs = [d for d in root_build_dir.iterdir() if d.is_dir()] |
| 195 | if not board_dirs: |
| 196 | print(f"No board directories found in {root_build_dir.absolute()}") |
| 197 | return 1 |
| 198 | |
| 199 | print("Available boards:") |
| 200 | for i, board_dir in enumerate(board_dirs): |
| 201 | print(f"[{i}]: {board_dir.name}") |
| 202 | |
| 203 | which = ( |
| 204 | 0 |
| 205 | if args.first |
| 206 | else int(input("Enter the number of the board you want to inspect: ")) |
| 207 | ) |
| 208 | board_dir = board_dirs[which] |
| 209 | |
| 210 | # Find build_info.json (try example-specific files first, then generic) |
| 211 | build_info_files = list(board_dir.glob("build_info_*.json")) |
| 212 | if build_info_files: |
| 213 | # Prefer example-specific files |
| 214 | build_info_json = build_info_files[0] |
| 215 | else: |
| 216 | # Fall back to generic build_info.json |
| 217 | build_info_json = board_dir / "build_info.json" |
| 218 | |
| 219 | if not build_info_json.exists(): |
| 220 | print(f"Error: No build_info*.json found in {board_dir}") |
| 221 | return 1 |
| 222 | |
| 223 | build_info = load_build_info(build_info_json) |
| 224 | board = board_dir.name |
| 225 | board_info = build_info.get(board) or build_info[next(iter(build_info))] |
| 226 | |
| 227 | # Validate paths from build_info.json |
| 228 | elf_path = Path(board_info.get("prog_path", "")) |
| 229 | if not elf_path.exists(): |
| 230 | print( |
| 231 | f"Error: ELF path '{elf_path}' does not exist. Check the 'prog_path' in build_info.json." |
| 232 | ) |
| 233 | return 1 |
| 234 | |
| 235 | bin_file = elf_path.with_suffix(".bin") |
| 236 | if not bin_file.exists(): |
| 237 | # use .hex or .uf2 if .bin doesn't exist |
| 238 | bin_file = elf_path.with_suffix(".hex") |
| 239 | if not bin_file.exists(): |
no test coverage detected