Skip to content

apps: fix distclean for partial builds and residual .kconfig files#3585

Open
Zepp-Hanzj wants to merge 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/distclean-context-partial-build
Open

apps: fix distclean for partial builds and residual .kconfig files#3585
Zepp-Hanzj wants to merge 1 commit into
apache:masterfrom
Zepp-Hanzj:fix/distclean-context-partial-build

Conversation

@Zepp-Hanzj

@Zepp-Hanzj Zepp-Hanzj commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Directory.mk's distclean only traverses CLEANSUBDIRS — directories with .built, .depend, or .kconfig markers. When a build fails before these markers are written (e.g. Python configure succeeds but compilation fails), distclean skips the directory entirely, leaving behind build/, config.site, and other artifacts.

Fix: use SUBDIRS (all directories with Makefiles) for distclean. It is idempotent, so calling it on un-built directories is harmless.

Changes

File Change
Directory.mk distclean traverse SUBDIRS instead of CLEANSUBDIRS; inline target definitions with TOPDIR; - prefix for error resilience
Application.mk distclean: add $(call DELFILE, .kconfig)
audioutils/lame/Makefile guard cd $(DST_PATH) against already-deleted directory
crypto/wolfssl/Makefile distclean: -> distclean:: (conflicted with Application.mk)

Companion PR

Requires nuttx#19310 which passes TOPDIR in SDIR_template / MAKE_template.

Verification

The bug: when a build fails between context:: and depend:: phases, .built and .depend markers are never written. The old distclean uses CLEANSUBDIRS which requires these markers, so it skips the directory and leaves artifacts behind.

To reproduce, simulate a partial build by creating the residual files a failed Python configure would leave, without .built/.depend markers:

$ cd ~/workspace/nuttx-apps/interpreters/python
$ rm -rf build install .kconfig .built .depend
$ mkdir -p build/target/{Modules,Objects,Parser,Python}
$ touch build/target/{Makefile,pyconfig.h,config.log}
$ touch config.site Setup.local .kconfig
$ test -f .built && echo "exists" || echo "not exists"
not exists
$ test -f .depend && echo "exists" || echo "not exists"
not exists

Run distclean through the NuttX build system (note: apps is a symlink to nuttx-apps):

$ cd ~/workspace/nuttx
$ make -C apps/interpreters/python distclean TOPDIR=$(pwd) APPDIR=$(pwd)/apps V=1
make: Entering directory '/home/hanzj-mi/workspace/nuttx-apps/interpreters/python'
rm -rf  /home/hanzj-mi/workspace/nuttx-apps/interpreters/python/build
rm -rf  /home/hanzj-mi/workspace/nuttx-apps/interpreters/python/install
rm -rf  Python
rm -f  v3.13.0.zip
rm -f  romfs_cpython_modules.img
rm -f  romfs_cpython_modules.h
rm -f  config.site
rm -f  Setup.local
rm -f  .built
rm -f *.o *.a *~ .*.swp  /home/hanzj-mi/workspace/nuttx/apps/libapps.a /home/hanzj-mi/workspace/nuttx/apps/libapps.a.lock
rm -f  .kconfig
rm -f  Make.dep
rm -f  .depend
make: Leaving directory '/home/hanzj-mi/workspace/nuttx-apps/interpreters/python'

Verify all residuals are cleaned:

$ cd ~/workspace/nuttx-apps/interpreters/python
$ test ! -d build && echo "build/ cleaned" || echo "build/ still exists"
build/ cleaned
$ test ! -f config.site && echo "config.site cleaned" || echo "config.site still exists"
config.site cleaned
$ test ! -f Setup.local && echo "Setup.local cleaned" || echo "Setup.local still exists"
Setup.local cleaned
$ test ! -f .kconfig && echo ".kconfig cleaned" || echo ".kconfig still exists"
.kconfig cleaned

Without this patch, make distclean produces no output (CLEANSUBDIRS is empty, nothing is traversed) and all residuals remain.

Fixes #2895

@Zepp-Hanzj Zepp-Hanzj marked this pull request as draft July 3, 2026 15:13
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch from 8d39253 to d6d4f3f Compare July 5, 2026 01:33
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch from d6d4f3f to 1f90ced Compare July 5, 2026 03:53
@Zepp-Hanzj Zepp-Hanzj changed the title build: introduce .context marker for distclean after partial builds apps: fix distclean for partial builds and residual .kconfig files Jul 5, 2026
@Zepp-Hanzj Zepp-Hanzj marked this pull request as ready for review July 5, 2026 03:53
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch from 1f90ced to d2d19d7 Compare July 5, 2026 06:06
Comment thread audioutils/lame/Makefile Outdated
Comment thread Directory.mk Outdated
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch 2 times, most recently from 06e44e7 to 29ca83b Compare July 5, 2026 10:45
@Zepp-Hanzj

Copy link
Copy Markdown
Contributor Author

Hi, the CI failure on Linux (arm-02) appears to be a timeout issue rather than a build failure caused by this PR.

Looking at the arm-02 logs:

  • The job ran for ~2h27m before being terminated
  • All builds that completed showed successful Normalize (no compilation errors)
  • The testbuild.sh script was cut short mid-way through the testlist (last completed: teensy-lc/nsh)
  • The cat: x264/config.h: No such file or directory and choosenim: command not found messages are pre-existing CI environment issues, not related to this PR
  • All other failing jobs show cancelled status (cascade from arm-02)

Could someone re-run the CI? The timeout seems to be an infrastructure issue. Thank you!

@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch from 29ca83b to 1b8feed Compare July 5, 2026 23:36
Comment thread Directory.mk Outdated
# like cargo). TOPDIR is passed so that sub-makes can include
# $(TOPDIR)/Make.defs and define SDIR_template for further recursion.

$(foreach SDIR, $(SUBDIRS), $(eval .PHONY: $(SDIR)_clean))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let extend SDIR_template instead duplicating the code

The current distclean implementation has two issues:

1. Application.mk does not remove .kconfig on distclean, so stale
   config fragments from earlier builds can pollute subsequent ones.

2. Several external-library Makefiles (lame, libshvc, libulut) run
   "make -C <subdir> distclean" without checking whether the
   subdirectory exists.  When the library was never downloaded (common
   in CI partial-build environments), distclean fails with "No such
   file or directory".

Fix:

- Application.mk: add $(call DELFILE, .kconfig) to the distclean
  target so that .kconfig is cleaned along with .built, .depend, etc.

- audioutils/lame/Makefile: guard the distclean recipe with
  "if [ -d $(DST_PATH) ]; then ...; fi" and use $(MAKE) instead
  of bare make.

- netutils/libshvc/Makefile, netutils/libulut/Makefile: same
  directory-existence guard for their distclean recipes.

- crypto/wolfssl/Makefile: change "distclean:" to "distclean::"
  (double-colon) so it does not override the distclean:: rule
  inherited from Application.mk.

Signed-off-by: hanzhijian <hanzhijian@zepp.com>
@Zepp-Hanzj Zepp-Hanzj force-pushed the fix/distclean-context-partial-build branch from 1b8feed to 1ba1b22 Compare July 6, 2026 02:12
@github-actions github-actions Bot added Size: XS and removed Size: S labels Jul 6, 2026
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.

[BUG] Python interperter distclean isn't working

2 participants