Inject cfg's build_flags / overlay into the [env:esp32s3] block. This is a targeted regex patch — we don't fully re-parse INI because PlatformIO's flavor of INI carries continuation lines and `${var.x}` interpolations that configparser mangles. The regex target is the literal `[env:
(cfg: OptInConfig)
| 180 | |
| 181 | |
| 182 | def patch_platformio_ini(cfg: OptInConfig) -> None: |
| 183 | """Inject cfg's build_flags / overlay into the [env:esp32s3] block. |
| 184 | |
| 185 | This is a targeted regex patch — we don't fully re-parse INI |
| 186 | because PlatformIO's flavor of INI carries continuation lines and |
| 187 | `${var.x}` interpolations that configparser mangles. The regex |
| 188 | target is the literal `[env:esp32s3]` header through the next |
| 189 | `[env:` header (or EOF), which is well-defined in practice. |
| 190 | """ |
| 191 | text = PLATFORMIO_INI.read_text(encoding="utf-8") |
| 192 | block_re = re.compile(r"(\[env:esp32s3\][^\[]*?)(?=\n\[env:|\Z)", re.DOTALL) |
| 193 | match = block_re.search(text) |
| 194 | if not match: |
| 195 | print( |
| 196 | "measure-opt-ins: could not locate [env:esp32s3] block in platformio.ini", |
| 197 | file=sys.stderr, |
| 198 | ) |
| 199 | sys.exit(2) |
| 200 | block = match.group(1) |
| 201 | if cfg.build_flags: |
| 202 | extra = "\n " + "\n ".join(cfg.build_flags) |
| 203 | if "build_flags =" in block: |
| 204 | block = re.sub( |
| 205 | r"(build_flags\s*=)", |
| 206 | r"\1" + extra, |
| 207 | block, |
| 208 | count=1, |
| 209 | ) |
| 210 | else: |
| 211 | block = block.rstrip() + "\nbuild_flags =" + extra + "\n" |
| 212 | if cfg.overlay: |
| 213 | line = f"board_build.sdkconfig_defaults = {OVERLAY_PATH}\n" |
| 214 | if "board_build.sdkconfig_defaults" in block: |
| 215 | block = re.sub( |
| 216 | r"board_build\.sdkconfig_defaults\s*=.*", |
| 217 | line.rstrip(), |
| 218 | block, |
| 219 | ) |
| 220 | else: |
| 221 | block = block.rstrip() + "\n" + line |
| 222 | new_text = text[: match.start()] + block + text[match.end() :] |
| 223 | PLATFORMIO_INI.write_text(new_text, encoding="utf-8") |
| 224 | |
| 225 | |
| 226 | def _run_compile_cmd(example: str) -> list[str]: |
no test coverage detected