ninjatool: rebuild multi-output targets if outputs are missing
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 11 Sep 2020 11:14:38 +0000 (13:14 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 30 Sep 2020 17:09:19 +0000 (19:09 +0200)
The "stamp file trick" used to group targets of a single multi-output rule
prevents the user from deleting one such target in order to force its
rebuild.  Doing so will not touch the stamp file, and therefore only
the dummy ":" command will be executed.

With this patch, ninjatool writes rules that force-rebuild the stamp
file if any of its outputs are missing.  Rebuilding the missing
target therefore causes the stamp file to be rebuilt too.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
scripts/ninjatool.py

index 627a1cab4570e2d266391611a616e8d7beaff63c..6f0e35c727f74c28ab79762f1237ceff2a7fa3d6 100755 (executable)
@@ -908,6 +908,9 @@ class Ninja2Make(NinjaParserEventsWithVars):
             else:
                 stamp = '%s@%s.stamp' % (rule, sha1_text(targets)[0:11])
             self.print('%s: %s; @:' % (targets, stamp))
+            self.print('ifneq (%s, $(wildcard %s))' % (targets, targets))
+            self.print('.PHONY: %s' % (stamp, ))
+            self.print('endif')
             self.print('%s: %s | %s; ${ninja-command-restat}' % (stamp, inputs, orderonly))
             self.rule_targets[rule].append(stamp)
             self.stamp_targets[rule].append(stamp)