Find the platform path from board's platform URL using cache directory naming.
(
board: "Board", paths: "FastLEDPaths"
)
| 15 | |
| 16 | |
| 17 | def find_platform_path_from_board( |
| 18 | board: "Board", paths: "FastLEDPaths" |
| 19 | ) -> Optional[Path]: |
| 20 | """Find the platform path from board's platform URL using cache directory naming.""" |
| 21 | from ci.util.url_utils import sanitize_url_for_path |
| 22 | |
| 23 | if not board.platform: |
| 24 | print(f"No platform URL defined for board {board.board_name}") |
| 25 | return None |
| 26 | |
| 27 | print(f"Looking for platform cache: {board.platform}") |
| 28 | |
| 29 | # Convert platform URL to expected cache directory name |
| 30 | expected_cache_name = sanitize_url_for_path(board.platform) |
| 31 | print(f"Expected cache directory: {expected_cache_name}") |
| 32 | |
| 33 | # Search in global cache directory |
| 34 | cache_dir = paths.global_platformio_cache_dir |
| 35 | expected_cache_path = cache_dir / expected_cache_name / "extracted" |
| 36 | |
| 37 | if ( |
| 38 | expected_cache_path.exists() |
| 39 | and (expected_cache_path / "platform.json").exists() |
| 40 | ): |
| 41 | print(f"Found platform cache: {expected_cache_path}") |
| 42 | return expected_cache_path |
| 43 | |
| 44 | # Fallback: search for any directory that contains the platform name |
| 45 | # Extract platform name from URL (e.g., "platform-espressif32" from github URL) |
| 46 | platform_name = None |
| 47 | if "platform-" in board.platform: |
| 48 | # Extract platform name from URL path |
| 49 | parts = board.platform.split("/") |
| 50 | for part in parts: |
| 51 | if ( |
| 52 | "platform-" in part |
| 53 | and not part.endswith(".git") |
| 54 | and not part.endswith(".zip") |
| 55 | ): |
| 56 | platform_name = part |
| 57 | break |
| 58 | |
| 59 | if platform_name: |
| 60 | print(f"Searching for platform by name: {platform_name}") |
| 61 | for cache_item in cache_dir.glob(f"*{platform_name}*"): |
| 62 | extracted_path = cache_item / "extracted" |
| 63 | if extracted_path.exists() and (extracted_path / "platform.json").exists(): |
| 64 | print(f"Found platform by name search: {extracted_path}") |
| 65 | return extracted_path |
| 66 | |
| 67 | print(f"Platform cache not found for {board.board_name}") |
| 68 | return None |
| 69 | |
| 70 | |
| 71 | def get_platform_required_packages(platform_path: Path) -> list[str]: |
no test coverage detected