[esp32] Suppress -Wvolatile in the direct ESP-IDF build (#17404)

This commit is contained in:
J. Nick Koston
2026-07-06 03:02:12 +00:00
committed by GitHub
parent 39c0f9cc84
commit e095c457ff
10 changed files with 127 additions and 4 deletions
+23
View File
@@ -243,6 +243,7 @@ def test_get_project_cmakelists_no_cpp_standard(tmp_path: Path) -> None:
patch("esphome.build_gen.espidf.get_esp32_variant", return_value="ESP32"),
patch.object(CORE, "name", "test"),
patch.object(CORE, "cpp_standard", None),
patch.object(CORE, "cxx_build_flags", set()),
):
from esphome.build_gen.espidf import get_project_cmakelists
@@ -251,6 +252,28 @@ def test_get_project_cmakelists_no_cpp_standard(tmp_path: Path) -> None:
assert "CXX_COMPILE_OPTIONS" not in content
def test_get_project_cmakelists_cxx_build_flags(tmp_path: Path) -> None:
"""Flags registered via cg.add_cxx_build_flag() are appended to
CXX_COMPILE_OPTIONS (C++-only, GCC warns if they reach C compiles)
between include(project.cmake) and project()."""
with (
patch("esphome.build_gen.espidf.get_esp32_variant", return_value="ESP32"),
patch.object(CORE, "name", "test"),
patch.object(CORE, "cpp_standard", None),
patch.object(CORE, "cxx_build_flags", {"-Wno-volatile"}),
):
from esphome.build_gen.espidf import get_project_cmakelists
content = get_project_cmakelists(minimal=True)
flag_line = 'idf_build_set_property(CXX_COMPILE_OPTIONS "-Wno-volatile" APPEND)'
assert flag_line in content
include_pos = content.index("tools/cmake/project.cmake")
flag_pos = content.index(flag_line)
project_pos = content.index("project(test)")
assert include_pos < flag_pos < project_pos
def test_get_component_cmakelists_no_compile_features() -> None:
"""The C++ standard is pinned project-wide via CXX_COMPILE_OPTIONS in the
top-level CMakeLists; the src component must not set its own."""
@@ -200,3 +200,32 @@ def test_get_ini_content_no_cpp_standard(
content = platformio.get_ini_content()
assert "-std=" not in content
def test_write_cxx_flags_script_emits_registered_flags(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Flags registered via cg.add_cxx_build_flag() are emitted as CXXFLAGS,
sorted, so they apply to C++ compiles only."""
CORE.build_path = str(tmp_path)
monkeypatch.setattr(CORE, "cxx_build_flags", {"-Wno-volatile", "-Wno-deprecated"})
platformio.write_cxx_flags_script()
content = (tmp_path / platformio.CXX_FLAGS_FILE_NAME).read_text()
assert (
'env.Append(CXXFLAGS=["-Wno-deprecated"])\n'
'env.Append(CXXFLAGS=["-Wno-volatile"])\n'
) in content
def test_write_cxx_flags_script_no_flags(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
CORE.build_path = str(tmp_path)
monkeypatch.setattr(CORE, "cxx_build_flags", set())
platformio.write_cxx_flags_script()
content = (tmp_path / platformio.CXX_FLAGS_FILE_NAME).read_text()
assert "CXXFLAGS" not in content
@@ -26,6 +26,7 @@ from esphome.framework_helpers import (
create_venv,
download_from_mirrors,
get_project_compile_flags,
get_project_cxx_compile_flags,
get_project_link_flags,
get_python_env_executable_path,
get_system_python_path,
@@ -1048,3 +1049,25 @@ class TestGetProjectLinkFlags:
):
result = get_project_link_flags()
assert result == sorted(result)
def _make_core_cxx(flags: set[str]) -> MagicMock:
core = MagicMock()
core.cxx_build_flags = flags
return core
class TestGetProjectCxxCompileFlags:
def test_returns_sorted_flags(self) -> None:
with patch(
"esphome.core.CORE",
_make_core_cxx({"-Wno-volatile", "-Wno-deprecated"}),
):
assert get_project_cxx_compile_flags() == [
"-Wno-deprecated",
"-Wno-volatile",
]
def test_empty_flags(self) -> None:
with patch("esphome.core.CORE", _make_core_cxx(set())):
assert get_project_cxx_compile_flags() == []