From 29ad6dd90c07d4cd762f3eeaf9f61324f7311baf Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 22 May 2023 16:11:25 -0400 Subject: [PATCH] avoid endless reconfigure loops when a build directory is copied around ninja's configured command for regenerating a build directory on any action that *requires* reconfiguring, specifies the source and build directories as they were known during initial project generation. This means that if the build directory is no longer the *same* build directory, we will regenerate... the original location, rather than the location we want. After that, ninja notices that build.ninja is still out of date, so it goes and reconfigures again. And again. And again. This is probably broken intentions, but endless reconfigure loops are a kind of evil beyond all evils. There are no valid options here whatsoever other than: - doing what the user actually meant - spawning a clear error message describing why meson refuses to work, then exiting with a fatal error But it turns out that it's actually pretty easy to do what the user actually meant, and reconfigure the current build directory instead of the original one. This permanently breaks the link between the two. Fixes #6131 --- mesonbuild/backend/ninjabackend.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 4cb680b15..19da2499a 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1293,7 +1293,9 @@ class NinjaBackend(backends.Backend): ['--internal', 'regenerate', self.environment.get_source_dir(), - self.environment.get_build_dir()] + # Ninja always runs from the build_dir. This includes cases where the user moved the + # build directory and invalidated most references. Make sure it still regenerates. + '.'] self.add_rule(NinjaRule('REGENERATE_BUILD', c, [], 'Regenerating build files.',