CMake regeneration is broken

I’ve seen a couple of reports in IRC about how updating to new revisions results in spuriously broken builds. I ran into this myself today, and looking into it, our build system has somehow ended up in a weird situation where the build.ninja target itself ends up depending on a bunch of things in the build. This means that when a CMake file changes, ninja tries to regenerate the build system, but the regeneration itself requires things to be built (with the old build system), and that won’t work since the build needs the CMake changes to be reflected in order to work. I’m digging into what might have changed, but ideas would be appreciated as well.

This is happening because runtimes/Tests.cmake was marked as a BYPRODUCT of the runtimes configure step by ⚙ D121647 [runtimes] Detect changes to Tests.cmake. That makes sense conceptually, but it also means we end up in a circular situation where the runtimes configure depends on a lot of the LLVM build (for the just-built tools), so runtimes/Tests.cmake depends on all of that as well, and then the main configure depends on runtimes/Tests.cmake and so ends up depending on the build, which causes the problem here. CC @petrhosek, the author of that diff.

I also don’t understand the explicit use of CMAKE_CONFIGURE_DEPENDS for runtimes/Tests.cmake … the include() will be enough to get CMake to recognize the configuration dependency. Is it to handle the case where the file doesn’t exist (in the initial configure)?

Thank you for looking into this. When I saw the first message it occurred to me that ⚙ D121647 [runtimes] Detect changes to Tests.cmake could be the culprit. It looks like we’ll need a different solution that doesn’t introduce the cyclic dependency. I’ll be fine reverting that change in the meantime.

You’re right, I don’t think the use of CMAKE_CONFIGURE_DEPENDS is needed.

1 Like

Thanks, I pushed rGa831ce528fc0 to revert.

1 Like

I also created a Ninja issue Should ninja prevent build.ninja from depending on the build? · Issue #2135 · ninja-build/ninja · GitHub to ask if it (or CMake) should be diagnosing these sorts of issues.