Enable restat for go binaries

Many Android build tools are written in go, and changes to Soong or
Blueprint can cause them to rebuild.  Almost everything in an
Android build is downstream of at least one of these tools, so
they all rebuild too.

Go binaries are static, so their contents will always change if any
of their dependencies change.  Only update output files of go compile
and go link if the contents change, and enable restat for the rules.

Test: m soong_zip && m soong_zip
Test: m soong_zip && touch build/soong/zip/cmd/main.go && m soong_zip
Change-Id: I9267580f644b42b44d43fb0a2674dc5234f127e5
This commit is contained in:
Colin Cross 2018-09-28 16:15:58 -07:00
parent c54f732470
commit 6c92af937e

View file

@ -57,18 +57,22 @@ var (
compile = pctx.StaticRule("compile",
blueprint.RuleParams{
Command: "GOROOT='$goRoot' $compileCmd $parallelCompile -o $out " +
"-p $pkgPath -complete $incFlags -pack $in",
Command: "GOROOT='$goRoot' $compileCmd $parallelCompile -o $out.tmp " +
"-p $pkgPath -complete $incFlags -pack $in && " +
"if cmp --quiet $out.tmp $out; then rm $out.tmp; else mv -f $out.tmp $out; fi",
CommandDeps: []string{"$compileCmd"},
Description: "compile $out",
Restat: true,
},
"pkgPath", "incFlags")
link = pctx.StaticRule("link",
blueprint.RuleParams{
Command: "GOROOT='$goRoot' $linkCmd -o $out $libDirFlags $in",
Command: "GOROOT='$goRoot' $linkCmd -o $out.tmp $libDirFlags $in && " +
"if cmp --quiet $out.tmp $out; then rm $out.tmp; else mv -f $out.tmp $out; fi",
CommandDeps: []string{"$linkCmd"},
Description: "link $out",
Restat: true,
},
"libDirFlags")
@ -435,10 +439,12 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
buildGoPackage(ctx, objDir, name, archiveFile, srcs, genSrcs)
var linkDeps []string
var libDirFlags []string
ctx.VisitDepsDepthFirstIf(isGoPackageProducer,
func(module blueprint.Module) {
dep := module.(goPackageProducer)
linkDeps = append(linkDeps, dep.GoPackageTarget())
libDir := dep.GoPkgRoot()
libDirFlags = append(libDirFlags, "-L "+libDir)
deps = append(deps, dep.GoTestTargets()...)
@ -450,11 +456,12 @@ func (g *goBinary) GenerateBuildActions(ctx blueprint.ModuleContext) {
}
ctx.Build(pctx, blueprint.BuildParams{
Rule: link,
Outputs: []string{aoutFile},
Inputs: []string{archiveFile},
Args: linkArgs,
Optional: true,
Rule: link,
Outputs: []string{aoutFile},
Inputs: []string{archiveFile},
Implicits: linkDeps,
Args: linkArgs,
Optional: true,
})
ctx.Build(pctx, blueprint.BuildParams{