Ninja failed recompaction after CMake 3.19.2/Ninja 1.10.2 update
This looks like a variation of #20274 (closed) which happens after we updated to the version of CMake/Ninja that were bundled with Visual Studio 2019 16.9.
I am trying to come up with an example I can share, but the gist of our build process is like this:
-
We first build a regular C++ library, e.g. libPrimary.
-
libPrimary is loaded into a code generator which then outputs (thousands of) .cpp files, as well as two text files containing the generated header and source filenames. The code generation is invoked through a custom-command which outputs the two text files, as well as having a dependency on libPrimary. We then set up a custom-target depending on the text file output of the custom command.
-
A second library (libSecondary) is set up to be built in another subdirectory. For this directory we set the CMAKE_CONFIGURE_DEPENDS directory property to the two generated text files containing the filenames. In addition libSecondary depends on a custom-target which depends on the custom command from 2).
The above has been working well for us with CMake 3.19.1 (and 3.18 series), but when when using CMake 3.19.6 (or3.19.20122902-MSVC_2) we get the following error:
C:\project\HwCore\develop\out\build\Debug-VS2015\EXEC : CMake error :
Running
'C:/PROGRA~2/MIB055~1/2019/PROFES~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe' '-C' 'C:/project/HwCore/develop/out/build/Debug-VS2015' '-t' 'recompact'
failed with:
C:\project\HwCore\develop\out\build\Debug-VS2015\ninja : error : failed recompaction: Permission denied
CMake Generate step failed. Build files cannot be regenerated correctly.
FAILED: build.ninja
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --regenerate-during-build -SC:\project\HwCore\develop -BC:\project\HwCore\develop\out\build\Debug-VS2015
C:\project\HwCore\develop\out\build\Debug-VS2015\ninja : error : rebuilding 'build.ninja': subcommand failed
My hypothesis is that it worked due to the Ninja workarounds that were removed from CMake 3.19.2 in !5555 (merged), but that the bug fixes in upstream Ninja does not cover our (corner) case.
Like I said, I will try to create a reproducible example, for now our workaround is to stay on CMake 3.19.1.