mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 16:51:16 +08:00
fix(nuttx): prune stale apps Kconfig on clean
Upgrading the NuttX apps submodule (kernel bump or switching branches then `git submodule update`) updates tracked files only. When the new revision removes an application directory, the autogenerated Kconfig a previous build left inside it is untracked, so it survives `git clean -dX`. mkkconfig.sh keeps globbing that orphaned `*/Kconfig`, whose stale `source` points at a file that no longer exists, breaking `make olddefconfig`: olddefconfig: apps/gpsutils/Kconfig:9: 'apps/gpsutils/minmea/Kconfig' not found Add a `cmake -P` helper, invoked at the end of the `clean` target, that walks the apps Kconfig graph and removes only untracked Kconfig files that source a missing path. Tracked files and the nuttx tree (whose stale artifacts are all gitignored and already dropped by `git clean -dX`) are never touched, so a `make clean` before rebuilding now migrates cleanly across the upgrade. Assisted-by: Claude:claude-opus-4.8 Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
This commit is contained in:
1 parent
b12ec6b50c
commit
103a1501a4
2 files changed
+99
No files matched your search
@@ -625,6 +625,9 @@ validate_module_configs:
|
||||
clean:
|
||||
@[ ! -d "$(SRC_DIR)/build" ] || find "$(SRC_DIR)/build" -mindepth 1 -maxdepth 1 -type d -exec sh -c "echo {}; cmake --build {} -- clean || rm -rf {}" \; # use generated build system to clean, wipe build directory if it fails
|
||||
@git submodule foreach git clean -dX --force # some submodules generate build artifacts in source
|
||||
@# Remove orphaned autogenerated Kconfig left by app dirs deleted in a NuttX apps upgrade
|
||||
@# (untracked, so they survive 'git clean -dX' and break 'make olddefconfig').
|
||||
@cmake -P "$(SRC_DIR)/platforms/nuttx/NuttX/tools/prune_stale_apps_kconfig.cmake"
|
||||
|
||||
submodulesclean:
|
||||
@git submodule foreach --quiet --recursive git clean -ff -x -d
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
############################################################################
|
||||
#
|
||||
# prune_stale_apps_kconfig.cmake
|
||||
#
|
||||
# When the NuttX "apps" submodule is upgraded (e.g. a kernel version bump or
|
||||
# switching branches followed by `git submodule update`), git updates tracked
|
||||
# files only. If the new revision *removes* an application directory, the
|
||||
# autogenerated `Kconfig` that a previous build left inside it is untracked and
|
||||
# therefore survives `git clean -dX` (and a plain checkout). That orphaned
|
||||
# directory keeps getting picked up by apps/tools/mkkconfig.sh (which globs
|
||||
# `*/Kconfig`), and its stale `Kconfig` still `source`s files that no longer
|
||||
# exist, breaking `make olddefconfig`:
|
||||
#
|
||||
# olddefconfig: .../apps/gpsutils/Kconfig:9: '.../gpsutils/minmea/Kconfig'
|
||||
# not found ...
|
||||
#
|
||||
# This helper removes exactly those stale leftovers: *untracked* `Kconfig`
|
||||
# files under the apps tree that `source` a path which no longer exists. It
|
||||
# never touches tracked files and never touches the nuttx tree, whose stale
|
||||
# artifacts are all gitignored and already removed by `git clean -dX`.
|
||||
#
|
||||
# Usage: cmake -P prune_stale_apps_kconfig.cmake
|
||||
#
|
||||
############################################################################
|
||||
|
||||
get_filename_component(APPS_DIR "${CMAKE_CURRENT_LIST_DIR}/../apps" ABSOLUTE)
|
||||
|
||||
if(NOT IS_DIRECTORY "${APPS_DIR}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_program(GIT_EXECUTABLE git)
|
||||
if(NOT GIT_EXECUTABLE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Only operate inside a real git working tree (skip tarball exports).
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} -C "${APPS_DIR}" rev-parse --is-inside-work-tree
|
||||
RESULT_VARIABLE _in_worktree
|
||||
OUTPUT_QUIET ERROR_QUIET
|
||||
)
|
||||
if(NOT _in_worktree EQUAL 0)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Iterate until stable: removing a child Kconfig can make its parent stale too.
|
||||
set(_changed TRUE)
|
||||
while(_changed)
|
||||
set(_changed FALSE)
|
||||
|
||||
# Matches files named exactly "Kconfig" at every depth, including the root.
|
||||
file(GLOB_RECURSE _kconfigs "${APPS_DIR}/Kconfig")
|
||||
|
||||
foreach(_kf ${_kconfigs})
|
||||
if(NOT EXISTS "${_kf}")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
# Never remove tracked Kconfig files - only build-generated orphans.
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} -C "${APPS_DIR}" ls-files --error-unmatch "${_kf}"
|
||||
RESULT_VARIABLE _tracked
|
||||
OUTPUT_QUIET ERROR_QUIET
|
||||
)
|
||||
if(_tracked EQUAL 0)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
file(READ "${_kf}" _content)
|
||||
string(REGEX MATCHALL "source[ \t]+\"[^\"]+\"" _sources "${_content}")
|
||||
|
||||
set(_stale FALSE)
|
||||
foreach(_entry ${_sources})
|
||||
string(REGEX REPLACE ".*\"([^\"]+)\".*" "\\1" _path "${_entry}")
|
||||
if(NOT IS_ABSOLUTE "${_path}")
|
||||
set(_path "${APPS_DIR}/${_path}")
|
||||
endif()
|
||||
if(NOT EXISTS "${_path}")
|
||||
set(_stale TRUE)
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_stale)
|
||||
message(STATUS "pruning stale apps Kconfig: ${_kf}")
|
||||
file(REMOVE "${_kf}")
|
||||
set(_changed TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
endwhile()
|
||||
|
||||
# Note: a now-empty orphan directory (e.g. apps/gpsutils/) is harmless - git
|
||||
# does not track empty directories and mkkconfig.sh only globs `*/Kconfig`, so
|
||||
# an empty directory is never sourced. It is left in place to keep this script
|
||||
# free of recursive directory deletion.
|
||||
Reference in new issue
Block a user