Compile the PlatformIO project. On Windows Git Bash: Runs via cmd.exe with clean environment (no Git Bash indicators) On other platforms: Runs directly with UTF-8 environment Args: build_dir: Project directory containing platformio.ini environment: PlatformIO environmen
(
build_dir: Path,
environment: str | None = None,
verbose: bool = False,
clean: bool = False,
)
| 165 | |
| 166 | |
| 167 | def run_compile( |
| 168 | build_dir: Path, |
| 169 | environment: str | None = None, |
| 170 | verbose: bool = False, |
| 171 | clean: bool = False, |
| 172 | ) -> bool: |
| 173 | """Compile the PlatformIO project. |
| 174 | |
| 175 | On Windows Git Bash: Runs via cmd.exe with clean environment (no Git Bash indicators) |
| 176 | On other platforms: Runs directly with UTF-8 environment |
| 177 | |
| 178 | Args: |
| 179 | build_dir: Project directory containing platformio.ini |
| 180 | environment: PlatformIO environment to build (None = default) |
| 181 | verbose: Enable verbose output |
| 182 | clean: Clean build artifacts before compiling |
| 183 | |
| 184 | Returns: |
| 185 | True if compilation succeeded, False otherwise |
| 186 | """ |
| 187 | if clean: |
| 188 | clean_cmd = ["pio", "run", "--target", "clean", "--project-dir", str(build_dir)] |
| 189 | if environment: |
| 190 | clean_cmd.extend(["--environment", environment]) |
| 191 | print("🧹 Cleaning build artifacts...") |
| 192 | subprocess.run(clean_cmd, capture_output=True) |
| 193 | |
| 194 | cmd = ["pio", "run", "--project-dir", str(build_dir)] |
| 195 | if environment: |
| 196 | cmd.extend(["--environment", environment]) |
| 197 | if verbose: |
| 198 | cmd.append("--verbose") |
| 199 | |
| 200 | print("=" * 60) |
| 201 | print("COMPILING") |
| 202 | print("=" * 60) |
| 203 | |
| 204 | # Log which sketch is being compiled (from PLATFORMIO_SRC_DIR env var) |
| 205 | src_dir = os.environ.get("PLATFORMIO_SRC_DIR") |
| 206 | if src_dir: |
| 207 | # Convert to relative path for cleaner output |
| 208 | try: |
| 209 | rel_path = Path(src_dir).relative_to(build_dir) |
| 210 | print(f"📁 Source: {rel_path}") |
| 211 | except ValueError: |
| 212 | # Not relative to build_dir, show absolute path |
| 213 | print(f"📁 Source: {src_dir}") |
| 214 | else: |
| 215 | print("📁 Source: (using platformio.ini default)") |
| 216 | print() |
| 217 | |
| 218 | formatter = TimestampFormatter() |
| 219 | # Use create_pio_process() for Git Bash compatibility |
| 220 | proc = create_pio_process( |
| 221 | cmd, |
| 222 | cwd=build_dir, |
| 223 | output_formatter=formatter, |
| 224 | auto_run=True, |
no test coverage detected