Expose all deps on genrules

For remote builds, we actually need to know that we depend on all
outputs from a genrule, not just the first one. But having every user
depend on every genrule output increases the ninja file size by >40%.

So to work around the increase in file size, use a ninja phony rule to
produce a single alias to all of the files. Unlike make, where phony
rules are always dirty, ninja does not attempt to stat phony rules as
long as they have inputs, so they act as an alias. (If they don't have
inputs, it will stat the file an only consider it dirty if it doesn't
exist.)

My remote build tooling can then see that it's a phony rule with inputs,
and collapse all of these inputs onto the actual rule.

This only applies to genrules that have >6 outputs, in order to keep the
graph simpler and easier to read for the common case. That's ~10% of the
genrules in AOSP, and it increases the ninja file size by ~1.3%.

Test: manual ninja file inspection
Test: treehugger
Change-Id: I1a26a02fe983f0c92ce726ada3133707223e662e
This commit is contained in:
Dan Willemsen 2019-08-09 16:21:29 -07:00
parent dfee9b4364
commit ddf504caea

View file

@ -40,6 +40,7 @@ var (
)
func init() {
pctx.Import("android/soong/android")
pctx.HostBinToolVariable("sboxCmd", "sbox")
}
@ -425,7 +426,24 @@ func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask
for _, outputFile := range task.out {
g.outputFiles = append(g.outputFiles, outputFile)
}
g.outputDeps = append(g.outputDeps, task.out[0])
// For <= 6 outputs, just embed those directly in the users. Right now, that covers >90% of
// the genrules on AOSP. That will make things simpler to look at the graph in the common
// case. For larger sets of outputs, inject a phony target in between to limit ninja file
// growth.
if len(task.out) <= 6 {
g.outputDeps = g.outputFiles
} else {
phonyFile := android.PathForModuleGen(ctx, "genrule-phony")
ctx.Build(pctx, android.BuildParams{
Rule: android.Phony,
Output: phonyFile,
Inputs: g.outputFiles,
})
g.outputDeps = android.Paths{phonyFile}
}
}
// Collect information for opening IDE project files in java/jdeps.go.