(meta_json: dict[str, dict[str, Any]])
| 45 | |
| 46 | |
| 47 | def insert_tool_aliases(meta_json: dict[str, dict[str, Any]]) -> None: |
| 48 | for board in meta_json.keys(): |
| 49 | aliases: dict[str, Optional[str]] = {} |
| 50 | cc_path_value = meta_json[board].get("cc_path") |
| 51 | resolved_cc_path: Optional[Path] = None |
| 52 | if cc_path_value: |
| 53 | try: |
| 54 | candidate = Path(str(cc_path_value)) |
| 55 | if candidate.is_absolute() and candidate.exists(): |
| 56 | resolved_cc_path = candidate |
| 57 | elif candidate.exists(): |
| 58 | resolved_cc_path = candidate.resolve() |
| 59 | else: |
| 60 | which_result = shutil.which( |
| 61 | candidate.name if candidate.name else str(candidate) |
| 62 | ) |
| 63 | if which_result: |
| 64 | resolved_cc_path = Path(which_result) |
| 65 | except KeyboardInterrupt as ki: |
| 66 | handle_keyboard_interrupt(ki) |
| 67 | raise |
| 68 | except Exception: |
| 69 | resolved_cc_path = None |
| 70 | |
| 71 | # Try to infer toolchain bin directory and prefix from either CC or GDB path |
| 72 | tool_bin_dir: Optional[Path] = None |
| 73 | tool_prefix: str = "" |
| 74 | tool_suffix: str = "" |
| 75 | |
| 76 | if resolved_cc_path and resolved_cc_path.exists(): |
| 77 | cc_base = resolved_cc_path.name |
| 78 | # If cc_path points at a real gcc binary, derive prefix/suffix from it. |
| 79 | # If it's a wrapper (e.g. cached_CC.cmd) without "gcc" in the name, |
| 80 | # fall back to using gdb_path to derive the actual toolchain prefix/suffix. |
| 81 | if "gcc" in cc_base: |
| 82 | tool_bin_dir = resolved_cc_path.parent |
| 83 | tool_prefix = cc_base.split("gcc")[0] |
| 84 | tool_suffix = resolved_cc_path.suffix |
| 85 | else: |
| 86 | resolved_cc_path = None # Force gdb-based fallback below |
| 87 | if resolved_cc_path is None: |
| 88 | gdb_path_value = meta_json[board].get("gdb_path") |
| 89 | if gdb_path_value: |
| 90 | try: |
| 91 | gdb_path = Path(str(gdb_path_value)) |
| 92 | if not gdb_path.exists(): |
| 93 | which_gdb = shutil.which(gdb_path.name) |
| 94 | if which_gdb: |
| 95 | gdb_path = Path(which_gdb) |
| 96 | if gdb_path.exists(): |
| 97 | tool_bin_dir = gdb_path.parent |
| 98 | gdb_base = gdb_path.name |
| 99 | # Derive prefix like 'arm-none-eabi-' from 'arm-none-eabi-gdb' |
| 100 | tool_prefix = ( |
| 101 | gdb_base.split("gdb")[0] if "gdb" in gdb_base else "" |
| 102 | ) |
| 103 | tool_suffix = gdb_path.suffix |
| 104 | except KeyboardInterrupt as ki: |
no test coverage detected