From 3fac97867ec2aeca4b24f2fb0663614c7a36d31d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 30 Sep 2026 13:17:07 +0200 Subject: [PATCH] [espidf] Resolve cmake through the IDF environment when reading the CMake cache (#19947) --- esphome/espidf/toolchain.py | 4 +++- tests/unit_tests/test_espidf_toolchain.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/espidf/toolchain.py b/esphome/espidf/toolchain.py index d1aeae9603..4243eff0ba 100644 --- a/esphome/espidf/toolchain.py +++ b/esphome/espidf/toolchain.py @@ -138,7 +138,9 @@ def _get_cmake_output(build_dir) -> str: if not (Path(build_dir) / "CMakeCache.txt").is_file(): raise EsphomeError(f"No ESP-IDF build found in {build_dir}") - cmd = ["cmake", "-LA", "-N", "."] + # Resolve to an absolute path: Windows locates a child process + # through the parent's PATH, not the env passed to it. + cmd = [_get_idf_tool("cmake"), "-LA", "-N", "."] env = _get_idf_env() result = subprocess.run( diff --git a/tests/unit_tests/test_espidf_toolchain.py b/tests/unit_tests/test_espidf_toolchain.py index ee21cd77a9..c012785e89 100644 --- a/tests/unit_tests/test_espidf_toolchain.py +++ b/tests/unit_tests/test_espidf_toolchain.py @@ -264,6 +264,7 @@ def test_get_cmake_output_with_configured_build(setup_core: Path) -> None: ) with ( patch.object(toolchain, "_get_idf_env", return_value={}), + patch.object(toolchain, "_get_idf_tool", return_value="/idf/tools/cmake"), patch.object(toolchain.subprocess, "run", return_value=completed) as mock_run, ): assert toolchain._get_cmake_output(build_dir) == completed.stdout @@ -271,6 +272,9 @@ def test_get_cmake_output_with_configured_build(setup_core: Path) -> None: assert toolchain._get_cmake_output(build_dir) == completed.stdout mock_run.assert_called_once() + # The resolved path, never a bare "cmake": Windows locates the child + # through the parent's PATH, where the IDF-managed cmake is missing. + assert mock_run.call_args.args[0][0] == "/idf/tools/cmake" assert toolchain._get_cmake_tool_path("CMAKE_ADDR2LINE") == Path("/tool/addr2line")