Initialize the PlatformIO build directory. Assumes lock is already held by caller. When use_fbuild=True, skips PIO-specific package management and the pio run build. The build directory, platformio.ini, and source files are still set up since fbuild uses the same project structure.
(
board: Board,
verbose: bool,
example: str,
paths: FastLEDPaths,
build_dir: Optional[Path] = None,
additional_defines: Optional[list[str]] = None,
additional_include_dirs: Optional[list[str]] = None,
additional_libs: Optional[list[str]] = None,
use_fbuild: bool = False,
)
| 56 | |
| 57 | |
| 58 | def _init_platformio_build( |
| 59 | board: Board, |
| 60 | verbose: bool, |
| 61 | example: str, |
| 62 | paths: FastLEDPaths, |
| 63 | build_dir: Optional[Path] = None, |
| 64 | additional_defines: Optional[list[str]] = None, |
| 65 | additional_include_dirs: Optional[list[str]] = None, |
| 66 | additional_libs: Optional[list[str]] = None, |
| 67 | use_fbuild: bool = False, |
| 68 | ) -> InitResult: |
| 69 | """Initialize the PlatformIO build directory. Assumes lock is already held by caller. |
| 70 | |
| 71 | When use_fbuild=True, skips PIO-specific package management and the pio run build. |
| 72 | The build directory, platformio.ini, and source files are still set up since fbuild |
| 73 | uses the same project structure. |
| 74 | """ |
| 75 | project_root = resolve_project_root() |
| 76 | build_dir = build_dir or (project_root / ".build" / "pio" / board.board_name) |
| 77 | |
| 78 | if not use_fbuild: |
| 79 | # Check for and fix corrupted packages before building |
| 80 | # Find platform path based on board's platform URL (works for any platform) |
| 81 | platform_path = find_platform_path_from_board(board, paths) |
| 82 | detect_and_fix_corrupted_packages_dynamic( |
| 83 | paths, board.board_name, platform_path |
| 84 | ) |
| 85 | |
| 86 | # Lock is already held by build() - no need to acquire again |
| 87 | |
| 88 | # Setup the build directory. |
| 89 | build_dir.mkdir(parents=True, exist_ok=True) |
| 90 | platformio_ini = build_dir / "platformio.ini" |
| 91 | |
| 92 | if not use_fbuild: |
| 93 | # Ensure platform is installed if needed (fbuild handles this itself) |
| 94 | if not ensure_platform_installed(board): |
| 95 | return InitResult( |
| 96 | success=False, |
| 97 | output=f"Failed to install platform for {board.board_name}", |
| 98 | build_dir=build_dir, |
| 99 | ) |
| 100 | |
| 101 | board_with_sketch_include = board.clone() |
| 102 | if board_with_sketch_include.build_flags is None: |
| 103 | board_with_sketch_include.build_flags = [] |
| 104 | |
| 105 | # Make the staged source roots available as include roots so sketch-relative |
| 106 | # includes resolve consistently under both PlatformIO and fbuild. |
| 107 | default_include_dirs = [ |
| 108 | (build_dir / "src").resolve().as_posix(), |
| 109 | (build_dir / "src" / "sketch").resolve().as_posix(), |
| 110 | ] |
| 111 | merged_include_dirs = list(default_include_dirs) |
| 112 | if additional_include_dirs: |
| 113 | merged_include_dirs.extend(additional_include_dirs) |
| 114 | |
| 115 | # Optimization report (`-fopt-info-all`) is OPT-IN per board because the |
no test coverage detected