eren-terzioglu opened a new issue, #19817: URL: https://github.com/apache/nuttx/issues/19817
## Summary Commit https://github.com/apache/nuttx/commit/9b0d46c222907112e5127591e05cb1e39f7cb1de (`cmake: normalize .config on reconfigure`) runs `nuttx_olddefconfig()` on **every CMake reconfigure** when `.config` already exists. The commit message / code comments claim this matches Make: > Run olddefconfig on reconfigure as well, **as the Make flow does on every build**. That statement is incorrect. Make does **not** run `olddefconfig` on a normal build. This breaks workflows that intentionally edit `.config` after configure (for example `kconfig-merge` / `kconfig-tweak` of out-of-tree fragments) and then reconfigure / rebuild with CMake. `olddefconfig` drops unknown symbols and resets assignments whose dependencies are not satisfied, so those edits are silently discarded on the next `cmake -B` / reconfigure. ## Incorrect Make claim — references ### Make: `olddefconfig` is an explicit target only In `tools/Unix.mk`, `olddefconfig` is a manual phony-style target. A normal `make` / `make context` does not invoke it: ```753:756:tools/Unix.mk olddefconfig: $(Q) $(MAKE) clean_context $(Q) $(MAKE) apps_preconfig $(Q) ${KCONFIG_ENV} ${KCONFIG_OLDDEFCONFIG} ``` `context` regenerates `include/nuttx/config.h` from the existing `.config` via `tools/mkconfig`. It does **not** call `olddefconfig`: ```266:275:tools/Unix.mk include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT) $(Q) grep -v "CONFIG_BASE_DEFCONFIG" "$(TOPDIR)/.config" > "$(TOPDIR)/.config.tmp" ... $(Q) tools/mkconfig $(TOPDIR) > [email protected] ``` ```466:466:tools/Unix.mk context: tools/incdir$(HOSTEXEEXT) include/nuttx/config.h include/nuttx/version.h .dirlinks $(CONTEXTDIRS_DEPS) | staging ``` Also note: `olddefconfig` is not even listed among the common `.PHONY` config targets next to `config` / `oldconfig` / `menuconfig` in `tools/Unix.mk` (line ~162). It is only used when requested (or once from `tools/configure.c` during initial configure). ### Make: when `olddefconfig` *does* run - Once during initial board configure (`tools/configure.c` → `run_make("olddefconfig")`) - When the user explicitly runs `make olddefconfig` - From helper scripts such as `tools/sethost.sh` / `tools/refresh.sh` after they intentionally tweak config It does **not** run on every incremental build. ### CMake change that diverges https://github.com/apache/nuttx/commit/9b0d46c222907112e5127591e05cb1e39f7cb1de adds: ```cmake else() # Normalize user modifications to .config (e.g. kconfig-tweak) so dependent # defaults materialize, as the Make flow does on each build set(ENV{KCONFIG_CONFIG} ${NUTTX_BINARY_DIR}/.config) nuttx_olddefconfig() endif() ``` So every reconfigure path (existing `.config`, same `BOARD_CONFIG`) now rewrites `.config` through `olddefconfig`. That is new CMake behavior, not Make parity. ## Reproducer (minimal) ```bash cmake -B build -DBOARD_CONFIG=esp32c6-devkitc:nsh -GNinja # Simulate an out-of-tree / post-configure fragment merge echo 'CONFIG_SOME_OUT_OF_TREE_OPTION=y' >> build/.config # or: kconfig-merge -m -O build build/.config /path/to/fragment # Any reconfigure (same board) now runs olddefconfig again cmake -B build -GNinja # CONFIG_SOME_OUT_OF_TREE_OPTION is gone (unknown symbol dropped) grep CONFIG_SOME_OUT_OF_TREE_OPTION build/.config || echo "stripped by olddefconfig" ``` Contrast with Make: ```bash ./tools/configure.sh esp32c6-devkitc:nsh echo 'CONFIG_SOME_OUT_OF_TREE_OPTION=y' >> .config make -j$(nproc) # does NOT run olddefconfig; line remains in .config # (may still be absent from config.h if truly unknown — but Make does not rewrite .config away) ``` ## Real-world impact Out-of-tree app / library integrations commonly do: 1. `cmake -B build -DBOARD_CONFIG=<board>:<config>` 2. `kconfig-merge` extra options into `build/.config` 3. `cmake --build build -t olddefconfig` (explicit, once) 4. merge again if needed 5. `cmake -B build` again so CMake picks up new `CONFIG_*` for `if(CONFIG_...)` 6. `cmake --build build` Step 5 used to preserve the merged `.config`. After `9b0d46c`, step 5 silently runs `olddefconfig` and drops any symbols that are not currently visible in the NuttX/apps Kconfig tree (or whose deps are not yet satisfied), which breaks those integrations. We hit this with an external LP-core sample that merges options after configure; the same flow still works with Make because Make does not auto-`olddefconfig` on build/reconfigure. ## Expected behavior CMake should match Make: - Run `olddefconfig` on **initial** configure from defconfig (already done). - Do **not** automatically run `olddefconfig` on every reconfigure / build. - Keep `olddefconfig` as an explicit target (`cmake --build -t olddefconfig`), same as `make olddefconfig`. If the goal of `9b0d46c` is to refresh dependent defaults after `kconfig-tweak`, that should be opt-in (explicit target / documented step), not implicit on every reconfigure. The commit’s Make-parity rationale is not accurate. ## Suggested fix 1. Revert the `else() { nuttx_olddefconfig(); }` path from `CMakeLists.txt`, **or** gate it behind an explicit option / target. 2. Update the commit message / comments so they do not claim Make runs `olddefconfig` on every build. 3. If dependent-default refresh after tweak is still desired, document: ```bash kconfig-tweak ... cmake --build build -t olddefconfig cmake -B build # re-export CONFIG_* without another olddefconfig ``` ## Commit under discussion - https://github.com/apache/nuttx/commit/9b0d46c222907112e5127591e05cb1e39f7cb1de - Files: `CMakeLists.txt`, `cmake/nuttx_kconfig.cmake` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
