Hello,
I’ve noticed the following behaviour: when using symbolic links on macOS (11.4 in my case), with CMake 3.20.5 and Ninja 1.10.2 (from homebrew), building can result in “ninja: error: manifest ‘build.ninja’ still dirty after 100 tries”.
I’ve reduced the issue to the following script to replicate easily. It seems related to physical vs logical path, but I wouldn’t know whether it’s an issue on CMake’s or Ninja’s side. This doesn’t seem to be an issue with Makefiles in case it matters.
#!/usr/bin/env bash
set -eux
rm -rf "project" "build"
mkdir -p "project" "build"
cat >project/CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.20)
project(FOO)
option(USE_ASAN "Use ASAN" OFF)
add_executable(foo main.cpp)
if(USE_ASAN)
message(WARNING "Enable ASan")
target_compile_options(foo PRIVATE "-fsanitize=address" "-fno-omit-frame-pointer")
target_link_options(foo PRIVATE "-fsanitize=address")
endif()
EOF
cat <<EOF >project/main.cpp
int main(int, char const* const*) { return 0; }
EOF
# cmake -G "Unix Makefiles" -B "$(pwd)/build" -S "$(pwd)/project"
# No bug with Makefiles.
cmake -G Ninja -B "$(pwd)/build" -S "$(pwd)/project"
cd build
cmake --build .
cmake . -DUSE_ASAN=ON
cmake --build .
cd ../project
ln -s "$(pwd)/../build" build
cd build
cd $(pwd -P) # IMPORTANT
cmake . -DUSE_ASAN=OFF
cmake --build .
# All fine so far!
cd ../project/build
# no cd $(pwd -P) this time.
cmake . -DUSE_ASAN=ON
cmake --build .
# Last build command fails with:
# ninja: error: manifest 'build.ninja' still dirty after 100 tries
It seems running CMake from a logical path different than the physical path corrupts the cache somehow: some variables refer to the logical path. It may be possible to restore the cache to a valid state once this has happened, but I haven’t figured it out.
Happy to provide additional information if needed. Hopefully someone else has a better idea of what’s happening here.
PS: this looks to be a different issue than Infinite re-run loop with CMake 3.5.1 and Ninja 1.10.0 https://gitlab.kitware.com/cmake/cmake/-/issues/20873 .