Possible dependency error with Swift / Ninja generator
I started to notice a lot of unnecessary rebuilds of generated files in my project, so I asked Ninja to -d explain
and found that the generator executable was dirty. Then I asked Ninja to explain that, and got this:
ninja explain: output Tests/CMakeFiles/GenerateHyloFileTests.dir/__/Sources/GenerateHyloFileTests/FullPathInFatalErrors.swift.o older than most recent input /Users/dave/src/hylo/Sources/GenerateHyloFileTests/GenerateHyloFileTests.swift (1712268734414433958 vs 1712360681254644617)
I noticed that nothing tries to rebuild this .o
file to make it newer than the most recent input. In some sense, there's no reason it should do that—since the .o
file is newer than the .swift
file from which it was produced—except that I know the rebuilds are unneeed and based on Ninja's explanation that seems the only way to suppress them.
The executable is produced from just two Swift files, FullPathInFatalErrors.swift
and GenerateHyloFileTests.swift
. The only slightly unusual factor here is that the actual path to FullPathInFatalErrors.swift
included in the target happens to be a symlink. That doesn't seem like it could be the source of the problem, though: the .o
file is newer than both the symlink and the file it points to.
-rw-r--r--@ 1 dave staff 14184 Apr 4 15:12 .ninja-build/Tests/CMakeFiles/GenerateHyloFileTests.dir/__/Sources/GenerateHyloFileTests/FullPathInFatalErrors.swift.o
lrwxr-xr-x 1 dave staff 37 Mar 6 14:31 Sources/GenerateHyloFileTests/FullPathInFatalErrors.swift -> ../Shared/FullPathInFatalErrors.swift
-rw-r--r-- 1 dave staff 1732 Mar 6 14:31 Sources/Shared/FullPathInFatalErrors.swift
Update: after touch
ing the symlinked file and rebuilding, it has settled on a new (similar) explanation for rebuilding each time, but this time the .o
file is not built from a symlinked source file:
ninja explain: output Sources/CMakeFiles/Utils.dir/Utils/BitArray.swift.o older than most recent input /Users/dave/src/hylo/Sources/Utils/FullPathInFatalErrors.swift (1712268733590489500 vs 1713233323155414000)
Happy to provide more information. A (not small) reproducer is in the cmake-issue-25902
tag of https://github.com/hylo-lang/hylo