Refactor mixed builds to only take one pass

This large refactoring has both immense performance implications and
improves mixed builds complexity / usability. Summary:

1. Queueing calls to Bazel is done in a new mutator instead of a full
   soong_build pass. Normal soong_build flow is interrupted (via a
   functional hook in blueprint) to invoke bazel and parse its response.
2. Implementing mixed build support for additional modules is as simple
   as implementing MixedBuildsBuildable. In this interface, define the
   request that must be queued to Bazel, and then subsequently define
   how to handle the returned bazel cquery metadata.
3. Mixed builds consists of only a single pass. This greatly
   improves mixed build performance.

Result:
  A 33% runtime improvement on soong analysis phase with mixed builds.

Caveats:
  C++ BazelHandler handling still remains a bit of a mess; I did what
  I could within this CL's scope, but this may require additional cleanup.

Test: Treehugger
Test: Verified that aosp_arm ninja file is bit-for-bit identical with or
without this change.

Change-Id: I412d9c94d429105f4ebfafc84100d546069e6621
This commit is contained in:
Chris Parsons
2022-05-10 13:50:12 -04:00
parent 53c6c67cbb
commit f874e46153
14 changed files with 383 additions and 285 deletions

View File

@@ -17,6 +17,7 @@ package cc
import (
"path/filepath"
"android/soong/bazel/cquery"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -562,25 +563,32 @@ func (binary *binaryDecorator) verifyHostBionicLinker(ctx ModuleContext, in, lin
}
type ccBinaryBazelHandler struct {
android.BazelHandler
BazelHandler
module *Module
}
func (handler *ccBinaryBazelHandler) GenerateBazelBuildActions(ctx android.ModuleContext, label string) bool {
func (handler *ccBinaryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
bazelCtx := ctx.Config().BazelContext
filePaths, ok := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
if ok {
if len(filePaths) != 1 {
ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, filePaths)
return false
}
outputFilePath := android.PathForBazelOut(ctx, filePaths[0])
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
// TODO(b/220164721): We need to decide if we should return the stripped as the unstripped.
handler.module.linker.(*binaryDecorator).unstrippedOutputFile = outputFilePath
bazelCtx.QueueBazelRequest(label, cquery.GetOutputFiles, android.GetConfigKey(ctx))
}
func (handler *ccBinaryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
bazelCtx := ctx.Config().BazelContext
filePaths, err := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf(err.Error())
return
}
return ok
if len(filePaths) != 1 {
ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, filePaths)
return
}
outputFilePath := android.PathForBazelOut(ctx, filePaths[0])
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
// TODO(b/220164721): We need to decide if we should return the stripped as the unstripped.
handler.module.linker.(*binaryDecorator).unstrippedOutputFile = outputFilePath
}
func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {