# Symlinks on macOS can result in "error: still dirty after 100 tries" when using Ninja

**URL:** https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647
**Category:** Usage
**Created:** [June 28, 2021, 7:04pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647 "2021-06-28T19:04:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mantognini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mantognini/32/1591_2.png) [@mantognini](https://discourse.cmake.org/u/mantognini)
#### Post date: [June 28, 2021, 7:04pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/1 "2021-06-28T19:04:53Z")

</div>

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.

```auto
#!/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://discourse.cmake.org/t/infinite-re-run-loop-with-cmake-3-5-1-and-ninja-1-10-0/1435) [https://gitlab.kitware.com/cmake/cmake/-/issues/20873](https://gitlab.kitware.com/cmake/cmake/-/issues/20873) .

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 28, 2021, 7:26pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/2 "2021-06-28T19:26:34Z")

</div>

This is known. The tracking issue is [here](https://gitlab.kitware.com/cmake/cmake/-/issues/16228). Basically, CMake tries to preserve `$PWD` if possible for some HPC use cases. Unfortunately, the use case was made at a deep level and has proven a _long_ thread to pull out. If you’re using symlinks for build trees, I recommend using a single way of accessing this path rather than expecting any name of the directory to work equivalently. `cd "$(pwd -P)"` is probably the best way to do it.

---

<div class="post-metadata">

### Author: ![mantognini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mantognini/32/1591_2.png) [@mantognini](https://discourse.cmake.org/u/mantognini)
#### Post date: [June 29, 2021, 5:09pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/3 "2021-06-29T17:09:52Z")

</div>

Thanks for the link, and glad this is known. Looks involved indeed.

Maybe one day there’ll be a flag to chose the behaviour, or some other kind of solution. I guess I could write a small wrapper for this purpose, but it would need to be generic enough to integrate into my various workflows (shell, IDE integration, etc…). Anyway, I think I’ll avoid symlinks for the time being, it feels not worth the hassle for my needs.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 29, 2021, 5:16pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/4 "2021-06-29T17:16:56Z")

</div>

It can’t be a flag because it’s not something someone is going to know how to use properly. The trigger is that `$PWD` is a different name for `pwd` and causes CMake to use `$PWD` as an equivalent name. I use symlinks all the time, but I use `realpath` to avoid the translation map.

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [September 5, 2021, 3:34pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/5 "2021-09-05T15:34:35Z")

</div>

I am having the same issue on Mac OS but without any symlink.  
Could this be related?

Thanks,  
Serge

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 6, 2021, 2:18pm UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/6 "2021-09-06T14:18:53Z")

</div>

Unlikely. More information would be helpful to diagnose it. Please open a new discussion thread.

---

<div class="post-metadata">

### Author: ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)
#### Post date: [September 13, 2021, 7:05am UTC](https://discourse.cmake.org/t/symlinks-on-macos-can-result-in-error-still-dirty-after-100-tries-when-using-ninja/3647/7 "2021-09-13T07:05:58Z")

</div>

I was trying to create a sample that recreates this issue but somehow it does not happen anymore after rebooting Mac…

Thanks for your answers,  
Serge
