casaroli opened a new pull request, #20817: URL: https://github.com/apache/nuttx/pull/20817
## Summary With CMake 4.3.0 or 4.3.1, a CMake reconfigure (for example after `menuconfig`, `olddefconfig`, or a second `cmake -B build`) deletes tracked files in the source tree. For `nucleo-f429zi:nsh`, all 16 files in `boards/arm/stm32f4/nucleo-f429zi/src/` are deleted. For `nucleo-l552ze:nsh`, also `boards/arm/stm32l5/drivers/Kconfig` is deleted. Then the reconfigure fails with `Failed to create link '.../arch/arm/src/board/board' because existing path cannot be removed: Not a directory`. `nuttx_create_symlink()` sets policy CMP0205 to NEW (#18964). With this policy, `file(CREATE_LINK)` in CMake 4.3.0 and 4.3.1 removes an existing destination directory recursively, also when the destination is a symbolic link to a directory. The removal follows the old link into the source tree. CMake 4.3.2 fixed this in CMake (Kitware/CMake issue 27747), but CMake 4.3.0 and 4.3.1 are in use (for example Homebrew installed 4.3.1). This PR removes an existing link with `file(REMOVE)` before `file(CREATE_LINK)`. `file(REMOVE)` removes the link, not its target. ## Impact CMake builds only. With CMake 4.3.0 and 4.3.1, a reconfigure no longer deletes files in the source tree. This applies to the `arch/<arch>/src/board/board` link (boards with `../common/CMakeLists.txt`, 164 boards), the `drivers/platform` link (cxd56xx, stm32l5, stm32u5, jz4780 boards), and the libcxx, libcxxabi, uClibc++ and libmcs include links. No change for other CMake versions, and no change on Windows and MSYS2, where directories are copied and not linked. ## Testing Reproducer: `cmake -B build -GNinja -DBOARD_CONFIG=nucleo-f429zi:nsh`, then `cmake -B build` again (or `kconfig-tweak` + `cmake --build build -t olddefconfig`), then `git status`. macOS, Ninja, arm-none-eabi-gcc 13.2. | CMake | master | this PR | |---|---|---| | 4.3.1 | reconfigure fails; `nucleo-f429zi/src/*` (16 files) deleted; for `nucleo-l552ze` also `stm32l5/drivers/Kconfig` | 4 reconfigures pass; `git status` clean | | 4.3.2 | `git status` clean | `git status` clean | | 4.2.3 | `git status` clean | `git status` clean | With CMake 4.3.1 and this PR, a configure, two or four reconfigures and a full build pass, and `git status` stays clean, for `nucleo-f429zi:nsh`, `nucleo-l552ze:nsh`, `mps2-an500:nsh`, `qemu-armv8a:nsh` and `sim:nsh`. A `cmake -P` test that calls `nuttx_create_symlink()` three times for a directory and for a file: on master with CMake 4.3.1, the second call deletes the directory content (also subdirectories) and fails; with this PR, all three calls pass on CMake 4.2.3, 4.3.1 and 4.3.2. `tools/checkpatch.sh -c -u -m -g` passes. No documentation change is necessary. -- 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]
