diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2019-04-10 14:49:29 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2019-04-27 15:57:01 +0100 |
commit | 0debaab8d1547570e321ea11ea4fc8307ae55874 (patch) | |
tree | fc33733a7e738de73830df38391995a54a32be63 /mesonbuild/backend/ninjabackend.py | |
parent | 091459cbdf6261f677b29eb27e04666a331ad996 (diff) | |
download | meson-0debaab8d1547570e321ea11ea4fc8307ae55874.zip meson-0debaab8d1547570e321ea11ea4fc8307ae55874.tar.gz meson-0debaab8d1547570e321ea11ea4fc8307ae55874.tar.bz2 |
ninja: Suppress unused rules in output
Don't bother outputting any rules which aren't referenced by any build
statement.
Diffstat (limited to 'mesonbuild/backend/ninjabackend.py')
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 968fcf9..9a6fdad 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -85,8 +85,12 @@ class NinjaRule: self.depfile = depfile self.extra = extra self.rspable = rspable # if a rspfile can be used + self.refcount = 0 def write(self, outfile): + if not self.refcount: + return + outfile.write('rule %s\n' % self.name) if self.rspable: outfile.write(' command = %s @$out.rsp\n' % ' '.join(self.command)) @@ -275,7 +279,7 @@ int dummy; with self.detect_vs_dep_prefix(tempfilename) as outfile: self.generate_rules() - self.write_rules(outfile) + self.build_elements = [] self.generate_phony() self.add_build_comment(NinjaComment('Build rules for targets')) @@ -293,7 +297,10 @@ int dummy; self.add_build_comment(NinjaComment('Suffix')) self.generate_utils() self.generate_ending() + + self.write_rules(outfile) self.write_builds(outfile) + default = 'default all\n\n' outfile.write(default) # Only overwrite the old build file after the new one has been @@ -830,6 +837,7 @@ int dummy; def generate_rules(self): self.rules = [] + self.ruledict = {} self.add_rule_comment(NinjaComment('Rules for compiling.')) self.generate_compile_rules() @@ -865,10 +873,15 @@ int dummy; def add_rule(self, rule): self.rules.append(rule) + self.ruledict[rule.name] = rule def add_build(self, build): self.build_elements.append(build) + # increment rule refcount + if build.rule != 'phony': + self.ruledict[build.rule].refcount += 1 + def write_rules(self, outfile): for r in self.rules: r.write(outfile) |