From 9d1aeebc27c5077ede5f47463e66f184529c03f0 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 23 Sep 2016 14:18:21 +0530 Subject: [PATCH] ninja: Don't add every CustomTarget to 'all' Otherwise they are built regardless of whether they are actually used by anything else. Only build them if they're going to be installed or always-built. Ideally, we should also do this with all BuildTargets, and provide a mechanism for people to specify which targets they want built with 'all', and a way for people to add them to custom targets.. Without this, things like tests and examples are *always* built with no way to turn that off. For now, we just do this because it also with tests that check for dependency issues. Including all CustomTargets in `all` results in dangling targets to also be built, which hides the problem and makes it racy. --- mesonbuild/backend/ninjabackend.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b54fc759d..930d37f9e 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1920,8 +1920,16 @@ rule FORTRAN_DEP_HACK elem.write(outfile) def generate_ending(self, outfile): - targetlist = [self.get_target_filename(t) for t in self.build.get_targets().values()\ - if not isinstance(t, build.RunTarget)] + targetlist = [] + for t in self.build.get_targets().values(): + # RunTargets are meant to be invoked manually + if isinstance(t, build.RunTarget): + continue + # CustomTargets that aren't installed should only be built if they + # are used by something else or are meant to be always built + if isinstance(t, build.CustomTarget) and not (t.install or t.build_always): + continue + targetlist.append(self.get_target_filename(t)) elem = NinjaBuildElement(self.all_outputs, 'all', 'phony', targetlist) elem.write(outfile)