Skip to content

Clean only the named target in clean_<target> - #11909

Merged
sensei-hacker merged 4 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:chore/build-and-dead-code
Oct 4, 2026
Merged

sensei-hacker merged 4 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:chore/build-and-dead-code

Conversation

@Raffi1202

@Raffi1202 Raffi1202 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#6135 (stronnag): after make MATEKF405 WINGFC MATEKF722, make clean_MATEKF405 removes the build output of every target, so the next make MATEKF722 is a full rebuild instead of a no-op. Fixes #6135.

Cause

clean_<name> runs the generator's global clean (COMMAND ${generator_cmd} clean in ${CMAKE_BINARY_DIR}); <name> is never used. The same block sits in cmake/stm32.cmake, cmake/at32.cmake, cmake/rp2350.cmake and cmake/sitl.cmake.

Change

add_clean_target() in cmake/main.cmake plus the script cmake/clean_target.cmake, run with cmake -P, so it behaves the same for Make and Ninja. stm32, at32, rp2350 and sitl pass their executables and output files (hex/bin/uf2/exe, plus the bootloader variants and the combined hex where they are built). The helper adds each executable's ELF and its map file where one is generated, the target's generated settings files and the *.o / *.obj / *.d files under CMakeFiles/<exe>.dir. The directory itself stays, because the Makefile generator keeps build.make there. All paths are literal: a $<TARGET_FILE:...> in the command would make clean_<name> build the target before deleting it.

Test

Local Linux build, CMake 4.4.3, Ninja 1.13.2, GNU Make 4.4.1, Release, WARNINGS_AS_ERRORS=ON.

  • Ninja, after ninja MATEKF405 MATEKF722. Before this PR, ninja clean_MATEKF405 deleted 1107 files (550 MATEKF405, 557 MATEKF722) and ninja -n MATEKF722 then had 551 objects to compile. With this PR, ninja clean_MATEKF722 deletes 558 files, all of them MATEKF722's: the same 557 plus bin/MATEKF722.elf.map, which ninja clean does not know about and left behind. ninja -n MATEKF405 then has no object to compile (only the hex step, which always runs). ninja MATEKF722 rebuilds to the same size.
  • ninja -n clean_<X> on an unbuilt tree: 1 step for MATEKF405, MATEKF722, MATEKF722SE, MATEKF405SE, IFLIGHT_BLITZ_ATF435 and RP2350_PICO. Nothing is built.
  • Make: same check for MATEKF405, including the rebuild after make clean_MATEKF405 without re-running cmake. make clean_MATEKF722SE on an unbuilt tree compiles nothing.
  • SITL (Ninja): clean_SITL removes only the SITL build output.
  • CI builds with Ninja and never runs a clean_<target>, so CI only confirms that every target still configures.

Flash / RAM

No source file changes. MATEKF722 and MATEKF405 text/data/bss are identical to the base.

Docs

None needed. docs/development/Building in Linux.md ("Cleaning") and build.sh already describe clean_<target> as cleaning one target; this PR makes that true.

Raphael Hunziker added 2 commits September 10, 2026 20:08
clean_<target> ran the generator clean in the build directory, so it wiped
every target instead of the one that was named. Remove the artefacts of that
target instead: its binary, map file, object files, generated settings and
the hex/bin files built from it.

Neither "make clean" nor "ninja clean" can be limited to a single target, so
the paths are removed by a small cmake script. That keeps the behaviour
identical for the Makefile and the Ninja generator. The object directory
itself is kept, because the Makefile generator stores the build rules of the
target (build.make, DependInfo.cmake, ...) next to the object files and
without them the next build fails until cmake is run again.

at32, rp2350 and sitl carried the same code and now share add_clean_target()
with stm32.

Fixes iNavFlight#6135
getMotorAveragePeriod() was guarded by USE_ESC_SENSOR_TELEMETRY and
USE_DSHOT_TELEMETRY. Neither of them exists in INAV, so only the #else
branch was ever compiled. The guarded code also calls getEscSensorData(),
a Betaflight API; INAV has escSensorGetData() and getEscTelemetry().

The function stays, srxlFrameRpm() still calls it and reports the RPM field
as unused. Only the branches go, together with the defines and the
esc_sensor.h include that nothing else used.

Fixes iNavFlight#11298
@Raffi1202
Raffi1202 marked this pull request as ready for review September 11, 2026 15:49
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Scope clean targets and remove dead Spektrum RPM telemetry code

🐞 Bug fix ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Restricts clean_ to artifacts belonging only to the named firmware target.
• Centralizes generator-independent cleanup across STM32, AT32, RP2350, and SITL builds.
• Removes unreachable Spektrum SRXL RPM telemetry branches referencing unsupported APIs.
Diagram

graph TD
  PLAT["Platform targets"] -->|"registers"| HELPER["Clean helper"] -->|"passes paths"| SCRIPT["Cleanup script"] -->|"removes outputs"| ART["Target artifacts"]
  SRXL["SRXL telemetry"] -->|"emits"| RPM["Unused RPM marker"]
Loading
High-Level Assessment

The centralized CMake-script approach is appropriate because generator-native clean targets are global, generator-specific implementations would duplicate logic, and deleting complete object directories would break subsequent Makefile builds. Preserving build metadata while removing compiler outputs provides consistent behavior across supported generators; Makefile and Ninja CI should confirm artifact coverage.

Files changed (7) +84 / -103

Bug fix (6) +83 / -62
at32.cmakeScope AT32 cleanup to target-specific artifacts +9/-15

Scope AT32 cleanup to target-specific artifacts

• Replaces the generator-wide clean command with the shared cleanup helper. Main and optional bootloader executables, HEX/BIN outputs, and the combined image are registered for removal.

cmake/at32.cmake

clean_target.cmakeAdd generator-independent artifact cleanup script +26/-0

Add generator-independent artifact cleanup script

• Adds a build-time CMake script that removes explicit files and recursively deletes only '.o', '.obj', and '.d' compiler outputs. Object directories and generator-owned build metadata remain intact for subsequent Makefile builds.

cmake/clean_target.cmake

main.cmakeCentralize named-target cleanup registration +34/-0

Centralize named-target cleanup registration

• Adds 'add_clean_target()' to collect firmware outputs, map files, generated settings, and object directories. The helper creates an excluded custom target that invokes the shared cleanup script without depending on Make or Ninja commands.

cmake/main.cmake

rp2350.cmakeAdopt scoped cleanup for RP2350 targets +3/-16

Adopt scoped cleanup for RP2350 targets

• Replaces global generator cleanup with the shared helper, registering the executable and its HEX, BIN, and UF2 outputs.

cmake/rp2350.cmake

sitl.cmakeAdopt scoped cleanup for SITL targets +1/-16

Adopt scoped cleanup for SITL targets

• Routes SITL clean targets through the shared helper and limits removal to the selected executable and output file.

cmake/sitl.cmake

stm32.cmakeScope STM32 cleanup and include binary outputs +10/-15

Scope STM32 cleanup and include binary outputs

• Captures the main BIN filename and registers main firmware artifacts with the shared cleanup helper. Bootloader, bootloader-compatible, and combined outputs are included only when that target configuration produces them.

cmake/stm32.cmake

Refactor (1) +1 / -41
srxl.cRemove unreachable Spektrum RPM telemetry branches +1/-41

Remove unreachable Spektrum RPM telemetry branches

• Removes unused ESC sensor dependencies, RPM conversion constants, and branches guarded by unsupported feature macros. The still-used period function now directly returns the SRXL unused-RPM sentinel.

src/main/telemetry/srxl.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@sensei-hacker sensei-hacker added this to the 10.0 milestone Sep 20, 2026
@b14ckyy b14ckyy linked an issue Sep 22, 2026 that may be closed by this pull request
@b14ckyy

b14ckyy commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Tested the clean part with the Makefile generator. The per-target scope works (MATEKF722SE stays untouched and make MATEKF722SE is a no-op afterwards), but the $<TARGET_FILE:...> expressions in the add_custom_target COMMAND make clean_ depend on every executable of X, including _bl and _for_bl:

  • make clean_MATEKF405SE on an unbuilt tree compiles 1180 objects and links three ELFs before deleting them.
  • After a normal build it still builds the bootloader variants (633 objects) first.
  • make clean_MATEKF722SE fails: MATEKF722SE_for_bl.elf overflows FLASH1, the link aborts and nothing is cleaned.

Literal paths (the output directories are known) instead of generator expressions would avoid the dependency.

Please drop the srxl.c commit from this PR: #11605 ports exactly that block to INAV's escSensorGetData() and needs the constants removed here, so the two would conflict. That PR is the right fix for #11298. With that the PR is also down to one topic.

This reverts commit 119a245.

iNavFlight#11605 replaces the same block with a working escSensorGetData() path
and still uses MICROSEC_PER_MINUTE, SPEKTRUM_MIN_RPM and SPEKTRUM_MAX_RPM,
so removing them here would conflict with it. iNavFlight#11298 is left to that PR
and this PR keeps to the clean target only.
$<TARGET_FILE:...> and the other target generator expressions in the
COMMAND of add_custom_target() add a target-level dependency on that
executable. clean_<target> therefore built the main, _bl and _for_bl
executables before deleting them: on an unbuilt tree clean_MATEKF722
compiled about 1200 objects and linked three ELFs, and the clean failed
outright where the _for_bl image does not fit into flash.

Pass literal paths instead. The executable lives in the target's
RUNTIME_OUTPUT_DIRECTORY and the map file follows the naming of
generate_map_file(), so the list of removed files is unchanged.
@Raffi1202 Raffi1202 changed the title Clean only the named target, and drop dead Spektrum RPM code Clean only the named target in clean_<target> Oct 2, 2026
@Raffi1202

Copy link
Copy Markdown
Contributor Author

Both points addressed:

  • The generator expressions are gone from clean_<target> (639c0a3). add_clean_target() now passes literal paths: the executable from its RUNTIME_OUTPUT_DIRECTORY, the map file named as generate_map_file() names it. The generated command line is identical to the one before, only the dependency is gone. Ninja, ninja -n clean_<X> on an unbuilt tree: before 1208 steps for MATEKF722 (1198 compiles, 3 links), 536 for IFLIGHT_BLITZ_ATF435, 528 for RP2350_PICO; now 1 step for each of them. With the Makefile generator clean_MATEKF722SE.dir/all no longer has the .elf targets as prerequisites, and make clean_MATEKF722SE on an unbuilt tree finishes without compiling anything.
  • The srxl.c commit is reverted (6af7208), so Dead code in spectrum telemetry #11298 stays with Add bidirectional DShot ESC telemetry #11605 and the PR touches only the build files. The removal had no size effect anyway: MATEKF405 (which compiles SRXL telemetry) had the same text/data/bss with and without it.

Heads-up: 119a245 still carries Fixes #11298 in its commit message. The PR body no longer references #11298. If the PR is merged with a merge commit and GitHub closes #11298 from that commit, #11298 needs reopening; a squash merge with an edited message avoids it.

Retested after a MATEKF405 MATEKF722 build (Ninja): clean_MATEKF722 removes 558 files, all of them MATEKF722's; ninja -n MATEKF405 afterwards has nothing to compile, and ninja MATEKF722 rebuilds it to the same size. Same check with make for MATEKF405, including a rebuild without re-running cmake.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

RAM / Flash usage vs. base commit 76ee415 — commit 639c0a3

Target Flash Δ RAM Δ
MATEKF405 ⚠️ +23108 B (+3.31%) -12636 B (-8.46%)
MATEKF722 ⚠️ +10340 B (+2.20%) -13256 B (-10.58%)
MATEKF765 ⚠️ +15708 B (+2.13%) -11512 B (-6.96%)
MATEKH743 ⚠️ +22516 B (+2.91%) -10688 B (-6.32%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Test firmware build ready — commit 639c0a3

Download firmware for PR #11909

251 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

@sensei-hacker
sensei-hacker merged commit a815d61 into iNavFlight:maintenance-10.x Oct 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cmake] make clean_TARGET cleans all targets

3 participants