From a7e4cf536b64cbf177191be773af0b9a726d4489 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 25 Aug 2026 20:43:37 -0500 Subject: [PATCH] Drop duplicate ccache test, keep full compiler output at debug, guard empty compile-DB directory --- esphome/build_helpers/pch.py | 4 +++- tests/unit_tests/build_gen/test_espidf.py | 15 +++++++++++++++ tests/unit_tests/test_espidf_framework.py | 18 ------------------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/esphome/build_helpers/pch.py b/esphome/build_helpers/pch.py index be08682fab..e30ca0821b 100644 --- a/esphome/build_helpers/pch.py +++ b/esphome/build_helpers/pch.py @@ -211,7 +211,7 @@ def pch_compile_command( if entry is None: _LOGGER.warning("No src C++ entry in the compile database, skipping pch") return None - cmd_dir = Path(entry.get("directory", build_dir)) + cmd_dir = Path(entry.get("directory") or build_dir) tokens = expand_response_files(split_command(entry.get("command", "")), cmd_dir) # A DB recorded with ccache enabled prefixes the compiler with the # launcher; the .gch must be compiled directly @@ -358,6 +358,8 @@ def prepare_pch( _LOGGER.warning( "Precompiled header failed; compiling without it: %s", error[:400] ) + # This path latches, so keep the full compiler output recoverable + _LOGGER.debug("Full pch compile output: %s", error) discard_pch(build_dir) # Skip retries until a header/flag/backend-identity/command change failed_marker.write_text(checksum + "\n", encoding="utf-8") diff --git a/tests/unit_tests/build_gen/test_espidf.py b/tests/unit_tests/build_gen/test_espidf.py index 6c62baa6f0..852526d648 100644 --- a/tests/unit_tests/build_gen/test_espidf.py +++ b/tests/unit_tests/build_gen/test_espidf.py @@ -675,6 +675,21 @@ def test_pch_compile_command_rejects_unusable_entries(tmp_path: Path) -> None: db.write_text(json.dumps(["just a string"])) assert pch_compile_command(build, header, gch) is None + # An empty-string directory must fall back to the build dir, not cwd + db.write_text( + json.dumps( + [ + { + "directory": "", + "command": f"g++ -DX=1 -o a.obj -c {src_file}", + "file": src_file, + } + ] + ) + ) + _, cmd_dir = pch_compile_command(build, header, gch) + assert cmd_dir == build + # arguments-style entry (allowed by the spec, unused by CMake) db.write_text( json.dumps([{"arguments": ["g++", "-c", src_file], "file": src_file}]) diff --git a/tests/unit_tests/test_espidf_framework.py b/tests/unit_tests/test_espidf_framework.py index 67e0aa8c29..cad66a948b 100644 --- a/tests/unit_tests/test_espidf_framework.py +++ b/tests/unit_tests/test_espidf_framework.py @@ -1976,21 +1976,3 @@ def test_check_windows_path_length_long_path_warns( assert "long path support" in message # The install is global now; the remedy is the prefix env, not moving the project. assert "ESPHOME_ESP_IDF_PREFIX" in message - - -def test_ccache_env_opt_in_with_usable_binary( - tmp_path: Path, caplog: pytest.LogCaptureFixture -) -> None: - # Forced on with a runnable binary: no warning, full env exported. - p1, p2, p3 = _ccache_patches(tmp_path, "/usr/bin/ccache", tmp_path / "build") - with ( - patch.dict("os.environ", {"IDF_CCACHE_ENABLE": "1"}, clear=True), - patch("esphome.espidf.framework.shutil.which", return_value="/usr/bin/ccache"), - patch("esphome.espidf.framework.tool_version_runs", return_value=True), - p1, - p2, - p3, - ): - env = _ccache_env() - assert env["IDF_CCACHE_ENABLE"] == "1" - assert not [r for r in caplog.records if r.levelno >= logging.WARNING]