Skip to content

Commit 57b0d56

Browse files
authored
Merge pull request #10 from FastLED/copilot/warn-on-non-optimal-g3-setting
2 parents e6f781f + 2440745 commit 57b0d56

2 files changed

Lines changed: 45 additions & 20 deletions

File tree

src/fbuild/build/flag_builder.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,19 @@ def _add_board_extra_flags(self, flags: Dict[str, List[str]]) -> None:
222222
if flag.startswith("-D"):
223223
flags["common"].append(flag)
224224

225-
def _warn_debug_flags_in_quick_profile(self) -> None:
226-
"""Warn if user has debug flags (-g*) in global build_flags during quick profile.
227-
228-
In quick profile, fbuild defaults to -g0 (no debug info) for fast builds.
229-
If the user puts -g/-g1/-g2/-g3 in build_flags, it overrides -g0 and applies
230-
to ALL compilation (sketch, core, and libraries), massively inflating .o files
231-
and slowing linking. The user likely intended debug info for their sketch only.
225+
def _warn_debug_build_flags(self) -> None:
226+
"""Warn if user has debug flags (-g*) in global build_flags.
227+
228+
Flags like -g, -g1, -g2, -g3 in build_flags apply to ALL compilation
229+
(sketch, core, and libraries), not just the user's own code. Compiling
230+
the framework with debug info massively inflates object files and slows
231+
linking — it is highly unlikely the user intended to debug the framework
232+
itself. Suggest moving the flag to build_src_flags so it only affects
233+
sketch files, or replacing it with -g0 to disable debug info entirely.
232234
"""
233235
if self._debug_flag_warning_shown:
234236
return
235237

236-
from fbuild.build.build_profiles import BuildProfile
237-
238-
if self.context.profile != BuildProfile.QUICK:
239-
return
240-
241238
debug_flags = [f for f in self.user_build_flags if f == "-g" or (f.startswith("-g") and f[2:3] in ("0", "1", "2", "3", "g", "d") and not f.startswith("-gnone") and f != "-g0")]
242239
if not debug_flags:
243240
return
@@ -249,8 +246,9 @@ def _warn_debug_flags_in_quick_profile(self) -> None:
249246
flag_str = " ".join(debug_flags)
250247
log_warning(
251248
f"build_flags contains '{flag_str}' which applies to ALL files (sketch, core, libraries).\n"
252-
f" In quick profile this overrides the default -g0, inflating object files ~30x and slowing linking.\n"
253-
f" Recommendation: move '{flag_str}' from build_flags to build_src_flags so it only applies to your sketch code."
249+
f" Compiling the framework with debug info inflates object files ~30x and massively slows linking.\n"
250+
f" Recommendation: move '{flag_str}' from build_flags to build_src_flags so it only applies to your sketch code,\n"
251+
f" or replace it with '-g0' in build_flags to disable debug info for all files."
254252
)
255253

256254
def _add_user_flags(self, flags: Dict[str, List[str]]) -> None:
@@ -265,7 +263,7 @@ def _add_user_flags(self, flags: Dict[str, List[str]]) -> None:
265263
Args:
266264
flags: Flags dictionary to update
267265
"""
268-
self._warn_debug_flags_in_quick_profile()
266+
self._warn_debug_build_flags()
269267

270268
i = 0
271269
user_flags = self.user_build_flags

tests/unit/build/test_build_src_flags.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
1. Are parsed correctly by ini_parser
66
2. Flow through BuildContext
77
3. Are applied only to sketch compilation (not core or libraries)
8-
4. Work with the debug flag warning in quick profile
8+
4. Work with the debug flag warning (fired for all build profiles)
99
"""
1010

1111
from pathlib import Path
@@ -491,12 +491,12 @@ def mock_compile_source(source_path: Path, output_path=None, extra_flags=None) -
491491

492492

493493
# ===========================================================================
494-
# 5. Debug flag warning in quick profile
494+
# 5. Debug flag warning (all build profiles)
495495
# ===========================================================================
496496

497497

498498
class TestDebugFlagWarning:
499-
"""Test that FlagBuilder warns when -g* is in build_flags during quick profile."""
499+
"""Test that FlagBuilder warns when -g* is in build_flags (any profile)."""
500500

501501
def test_warns_on_g3_in_quick_profile(self) -> None:
502502
ctx = _make_mock_context(
@@ -546,14 +546,41 @@ def test_no_warn_on_g0(self) -> None:
546546
fb.build_flags()
547547
mock_warn.assert_not_called()
548548

549-
def test_no_warn_in_release_profile(self) -> None:
550-
"""-g3 in release profile is fineno warning."""
549+
def test_warns_on_g3_in_release_profile(self) -> None:
550+
"""-g3 in release profile must warnframework compiled with debug info is always slow."""
551551
ctx = _make_mock_context(
552552
user_build_flags=["-g3"],
553553
user_build_src_flags=[],
554554
profile=BuildProfile.RELEASE,
555555
)
556556
fb = FlagBuilder(ctx)
557+
with patch("fbuild.output.log_warning") as mock_warn:
558+
fb.build_flags()
559+
mock_warn.assert_called_once()
560+
msg = mock_warn.call_args[0][0]
561+
assert "-g3" in msg
562+
assert "build_src_flags" in msg
563+
564+
def test_warns_on_g_in_release_profile(self) -> None:
565+
"""-g in release profile must also warn."""
566+
ctx = _make_mock_context(
567+
user_build_flags=["-g"],
568+
user_build_src_flags=[],
569+
profile=BuildProfile.RELEASE,
570+
)
571+
fb = FlagBuilder(ctx)
572+
with patch("fbuild.output.log_warning") as mock_warn:
573+
fb.build_flags()
574+
mock_warn.assert_called_once()
575+
576+
def test_no_warn_on_g0_in_release_profile(self) -> None:
577+
"""-g0 in release profile should not warn."""
578+
ctx = _make_mock_context(
579+
user_build_flags=["-g0"],
580+
user_build_src_flags=[],
581+
profile=BuildProfile.RELEASE,
582+
)
583+
fb = FlagBuilder(ctx)
557584
with patch("fbuild.output.log_warning") as mock_warn:
558585
fb.build_flags()
559586
mock_warn.assert_not_called()

0 commit comments

Comments
 (0)