Download all packages and swap URLs for local file path URLs. This method will: 1. Resolve platform shorthand names to URLs using PlatformIO CLI (only for *.zip URLs when full=False) 2. Replace shorthand names with resolved URLs in-place (only when full=True for fra
(self, cache: "PlatformIOCache", full: bool = False)
| 2099 | return output.getvalue() |
| 2100 | |
| 2101 | def optimize(self, cache: "PlatformIOCache", full: bool = False) -> None: |
| 2102 | """ |
| 2103 | Download all packages and swap URLs for local file path URLs. |
| 2104 | |
| 2105 | This method will: |
| 2106 | 1. Resolve platform shorthand names to URLs using PlatformIO CLI (only for *.zip URLs when full=False) |
| 2107 | 2. Replace shorthand names with resolved URLs in-place (only when full=True for frameworks) |
| 2108 | 3. Find all platform and framework URLs that point to zip files |
| 2109 | 4. Download and cache them using the provided PlatformIO cache system |
| 2110 | 5. Replace the URLs in-place with local file:// URLs |
| 2111 | |
| 2112 | Args: |
| 2113 | cache: PlatformIOCache instance to use for downloading and caching packages. |
| 2114 | full: When True, resolve all platform/framework shorthand names to URLs. |
| 2115 | When False (default), only optimize *.zip URLs for caching. |
| 2116 | """ |
| 2117 | # Import here to avoid circular dependencies |
| 2118 | from ci.compiler.platformio_cache import _is_zip_web_url, handle_zip_artifact |
| 2119 | |
| 2120 | cache_manager = cache |
| 2121 | |
| 2122 | # Step 1: Resolve shorthand platform names to URLs (always happens) |
| 2123 | logger.debug("Resolving platform shorthand names to URLs...") |
| 2124 | platform_resolutions = self.resolve_platform_urls() |
| 2125 | platform_replacements_made = 0 |
| 2126 | |
| 2127 | for platform_name, resolved_url in platform_resolutions.items(): |
| 2128 | if resolved_url: |
| 2129 | # Replace shorthand names with resolved URLs (regardless of whether they're zip URLs) |
| 2130 | for ( |
| 2131 | section_name, |
| 2132 | option_name, |
| 2133 | current_url, |
| 2134 | ) in self.get_platform_urls(): |
| 2135 | if current_url == platform_name: |
| 2136 | self.replace_url( |
| 2137 | section_name, option_name, platform_name, resolved_url |
| 2138 | ) |
| 2139 | platform_replacements_made += 1 |
| 2140 | logger.debug( |
| 2141 | f"Resolved platform {platform_name} -> {resolved_url} in {section_name}" |
| 2142 | ) |
| 2143 | |
| 2144 | if platform_replacements_made > 0: |
| 2145 | logger.info( |
| 2146 | f"Resolved {platform_replacements_made} platform shorthand names" |
| 2147 | ) |
| 2148 | |
| 2149 | # Step 2: Resolve shorthand framework names to URLs (always happens) |
| 2150 | logger.debug("Resolving framework shorthand names to URLs...") |
| 2151 | framework_resolutions = self.resolve_framework_urls() |
| 2152 | framework_replacements_made = 0 |
| 2153 | |
| 2154 | for framework_name, resolved_url in framework_resolutions.items(): |
| 2155 | if resolved_url: |
| 2156 | # Replace shorthand names with resolved URLs (regardless of whether they're zip URLs) |
| 2157 | for ( |
| 2158 | section_name, |