From 4da4ccc20347481e2ab09345643147f7a22118ba Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Thu, 6 Jul 2023 10:56:29 +0900 Subject: [PATCH] Add write_if_changed property to genrule When "write_if_changed: true" is set, it will call restat for ninja. With this option the output file will be copied only if it is changed. Bug: 290130959 Test: ninja rule include "--write-if-changed" Change-Id: I8bd77b43b22eb0115e0bdc73718b2d6997d92652 --- genrule/genrule.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/genrule/genrule.go b/genrule/genrule.go index 99c91667c..a470c5e8a 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -151,6 +151,9 @@ type generatorProperties struct { // input files to exclude Exclude_srcs []string `android:"path,arch_variant"` + + // Enable restat to update the output only if the output is changed + Write_if_changed *bool } type Module struct { @@ -467,6 +470,9 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { // Use a RuleBuilder to create a rule that runs the command inside an sbox sandbox. rule := getSandboxedRuleBuilder(ctx, android.NewRuleBuilder(pctx, ctx).Sbox(task.genDir, manifestPath)) + if Bool(g.properties.Write_if_changed) { + rule.Restat() + } cmd := rule.Command() for _, out := range task.out {