Merge branch 'esp32-idf-pch' into platformio-pch-rp2

This commit is contained in:
J. Nick Koston
2026-08-26 09:08:05 -05:00
4 changed files with 24 additions and 3 deletions
+3
View File
@@ -1271,6 +1271,9 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool:
)
write_file_if_changed(pch_header, pch_text)
if checksum is not None:
# Valid only for a ninja run started by write_project: a
# direct ninja invocation can rebuild the .gch via its
# depfile while this generate-time .sum lags behind
write_file_if_changed(
build_dir / f"{PCH_HEADER_NAME}.gch.sum", checksum + "\n"
)
+8 -1
View File
@@ -354,7 +354,14 @@ def prepare_pch(
_log_pch_in_use()
try:
result = subprocess.run(
cmd, cwd=cmd_dir, capture_output=True, text=True, check=False, timeout=300
cmd,
cwd=cmd_dir,
# C locale keeps diagnostics matchable by _TRANSIENT_ERRORS
env={**os.environ, "LC_ALL": "C"},
capture_output=True,
text=True,
check=False,
timeout=300,
)
error = None
if result.returncode < 0:
+7 -1
View File
@@ -95,6 +95,8 @@ def _compile_gch(cxx, flags, header: Path, gch: Path, proj_dir: Path):
result = subprocess.run( # noqa: PLW1510
[cxx, "-x", "c++-header", *flags, "-c", str(header), "-o", str(gch)],
cwd=proj_dir,
# C locale keeps diagnostics matchable by _TRANSIENT_ERRORS
env={**os.environ, "LC_ALL": "C"},
capture_output=True,
text=True,
)
@@ -318,7 +320,11 @@ def _setup_pch() -> None:
# entries: GCC only uses a .gch while no other tokens have been seen.
# The relative name also reaches "pio run -t idedata" output; external
# consumers replaying cxx_flags must run from the project dir.
projenv.Prepend(CXXFLAGS=["-Winvalid-pch", "-include", header.name]) # noqa: F821
projenv.Prepend( # noqa: F821
# -Wno-error: the probe is per-process, so a later cc1plus can still
# reject the .gch; that must stay a warning under user -Werror
CXXFLAGS=["-Winvalid-pch", "-Wno-error=invalid-pch", "-include", header.name]
)
print("ESPHome: Compiling with precompiled header")
@@ -156,7 +156,12 @@ def test_pch_script_builds_and_prepends_relative_include(tmp_path: Path) -> None
assert (proj / "esphome_pch.h.gch").is_file()
assert len((proj / "esphome_pch.h.gch.sum").read_text().strip()) == 64
# Relative include: an absolute path would poison ccache keys
assert scons_env.prepended == ["-Winvalid-pch", "-include", "esphome_pch.h"]
assert scons_env.prepended == [
"-Winvalid-pch",
"-Wno-error=invalid-pch",
"-include",
"esphome_pch.h",
]
# In production projenv["ENV"] aliases os.environ; only the -include
# flags are genuinely scoped to projenv (src compiles)
assert scons_env["ENV"]["CCACHE_SLOPPINESS"] == "pch_defines,time_macros"