Ninja: Handle depfiles with absolute paths to generated files
Ninja treats every (normalized) path as its own node. It does not
recognize /abs/path/to/file
in a depfile as matching path/to/file
even when build.ninja
and the working directory are in /abs/
.
See Ninja Issue 1251. In cases where we pass absolute paths to the
compiler, it will write a depfile containing absolute paths. If those
files are generated in the build tree by custom commands, build.ninja
references them by relative path in build statement outputs, so Ninja
does not hook up the dependency and rebuild the project correctly.
Add infrastructure to work around this problem by adding implicit
outputs to custom command build statements that reference the main
outputs by absolute path. Use a ${cmake_ninja_workdir}
placeholder
to avoid repeating the base path. For example:
build out.txt | ${cmake_ninja_workdir}out.txt: CUSTOM_COMMAND ...
Ninja will create two nodes for the output file, one with a relative path and one with an absolute path. A depfile may then mention either form of the path and Ninja will hook up the dependency. Unfortunately Ninja will also stat the file twice.
Issue: #13894 (closed)
Fixes: #21865 (closed)