diff --git a/esphome/build_gen/arduino8266.py b/esphome/build_gen/arduino8266.py index 111a233f57..043c18f989 100644 --- a/esphome/build_gen/arduino8266.py +++ b/esphome/build_gen/arduino8266.py @@ -28,7 +28,7 @@ from esphome.build_helpers.ninja import shell_token as _shell_token from esphome.components.esp8266 import build_surgery from esphome.core import CORE, EsphomeError from esphome.helpers import mkdir_p, write_file_if_changed -from esphome.platformio.library import lex_build_flags, raise_on_empty_arg_flags +from esphome.platformio.library import lex_build_flags if TYPE_CHECKING: from esphome.arduino8266.framework import InstalledPaths @@ -248,10 +248,8 @@ def _lexed_build_flags() -> list[str]: Lex once per build; consumers share the tokens. """ - tokens = lex_build_flags(sorted(CORE.build_flags), "esphome") - # Raises for every consumer of the shared token list - raise_on_empty_arg_flags(tokens, "build_flags") - return tokens + # The funnel warns and drops empty glued arguments (-D "") itself + return lex_build_flags(sorted(CORE.build_flags), "esphome") def _flag_defines(unflags: set[str], tokens: list[str]) -> dict[str, str]: diff --git a/tests/unit_tests/build_gen/test_arduino8266.py b/tests/unit_tests/build_gen/test_arduino8266.py index 6f1d7f9272..41f506f713 100644 --- a/tests/unit_tests/build_gen/test_arduino8266.py +++ b/tests/unit_tests/build_gen/test_arduino8266.py @@ -591,12 +591,15 @@ def test_vtables_conflicting_raises() -> None: _resolve("-DVTABLES_IN_DRAM", "-DVTABLES_IN_IRAM") -def test_empty_lib_flags_raise() -> None: - """A bare -L would silently add the CWD to the search path; the shared - lex point raises for every consumer.""" - CORE.build_flags = {'-L ""', '-l ""'} - with pytest.raises(EsphomeError, match=r"empty-argument flag\(s\): -L, -l"): - arduino8266._lexed_build_flags() +def test_empty_lib_flags_warned_and_dropped( + caplog: pytest.LogCaptureFixture, +) -> None: + """A bare -L would silently add the CWD to the search path; the lex + funnel warns and drops it for every consumer.""" + CORE.build_flags = {'-L ""', '-l ""', "-DFOO"} + assert arduino8266._lexed_build_flags() == ["-DFOO"] + assert "Ignoring '-L' with empty argument" in caplog.text + assert "Ignoring '-l' with empty argument" in caplog.text def test_generate_ld_scripts_surfaces_preprocessor_warnings( @@ -1017,12 +1020,15 @@ def test_generate_ld_scripts_unreadable_header_forces_regeneration( mock_run.assert_called_once() -def test_bare_include_and_define_raise() -> None: +def test_bare_include_and_define_dropped( + caplog: pytest.LogCaptureFixture, +) -> None: """An empty-argument -I or -D would make gcc eat the next flag as the - argument; the shared lex point raises for every consumer.""" + argument; the lex funnel warns and drops both.""" CORE.build_flags = {'-I ""', '-D ""'} - with pytest.raises(EsphomeError, match=r"empty-argument flag\(s\): -D, -I"): - arduino8266._lexed_build_flags() + assert arduino8266._lexed_build_flags() == [] + assert "Ignoring '-I' with empty argument" in caplog.text + assert "Ignoring '-D' with empty argument" in caplog.text def test_generate_ld_scripts_gcc_change_invalidates_stamp(tmp_path: Path) -> None: