Log information for Mixed Builds modules.
Test: Output matches expected. https://paste.googleplex.com/5913495636803584?raw
Performance evaluated: https://docs.google.com/spreadsheets/d/1X7eOVBKEZUwUWl5i8CDfBo9yUeZrDPXWi2JYO4BEZt4/edit?resourcekey=0-co8crIFW9dpiedhCMkhAgw#gid=0
Change-Id: I88780c7cc52a189a72216c5e2e499c96574b3731
diff --git a/android/bazel.go b/android/bazel.go
index 4ef8d78..67002ec 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -338,9 +338,19 @@
return false
}
-// MixedBuildsEnabled checks that a module is ready to be replaced by a
+// MixedBuildsEnabled returns true if a module is ready to be replaced by a
+// converted or handcrafted Bazel target. As a side effect, calling this
+// method will also log whether this module is mixed build enabled for
+// metrics reporting.
+func MixedBuildsEnabled(ctx ModuleContext) bool {
+ mixedBuildEnabled := mixedBuildPossible(ctx)
+ ctx.Config().LogMixedBuild(ctx, mixedBuildEnabled)
+ return mixedBuildEnabled
+}
+
+// mixedBuildPossible returns true if a module is ready to be replaced by a
// converted or handcrafted Bazel target.
-func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool {
+func mixedBuildPossible(ctx ModuleContext) bool {
if ctx.Os() == Windows {
// Windows toolchains are not currently supported.
return false
diff --git a/android/config.go b/android/config.go
index ee058e8..d695217 100644
--- a/android/config.go
+++ b/android/config.go
@@ -170,6 +170,10 @@
ninjaFileDepsSet sync.Map
OncePer
+
+ mixedBuildsLock sync.Mutex
+ mixedBuildEnabledModules map[string]struct{}
+ mixedBuildDisabledModules map[string]struct{}
}
type deviceConfig struct {
@@ -375,7 +379,9 @@
// passed to PathForSource or PathForModuleSrc.
TestAllowNonExistentPaths: true,
- BazelContext: noopBazelContext{},
+ BazelContext: noopBazelContext{},
+ mixedBuildDisabledModules: make(map[string]struct{}),
+ mixedBuildEnabledModules: make(map[string]struct{}),
}
config.deviceConfig = &deviceConfig{
config: config,
@@ -466,8 +472,10 @@
runGoTests: runGoTests,
multilibConflicts: make(map[ArchType]bool),
- moduleListFile: moduleListFile,
- fs: pathtools.NewOsFs(absSrcDir),
+ moduleListFile: moduleListFile,
+ fs: pathtools.NewOsFs(absSrcDir),
+ mixedBuildDisabledModules: make(map[string]struct{}),
+ mixedBuildEnabledModules: make(map[string]struct{}),
}
config.deviceConfig = &deviceConfig{
@@ -2038,3 +2046,14 @@
func (c *config) UseHostMusl() bool {
return Bool(c.productVariables.HostMusl)
}
+
+func (c *config) LogMixedBuild(ctx ModuleContext, useBazel bool) {
+ moduleName := ctx.Module().Name()
+ c.mixedBuildsLock.Lock()
+ defer c.mixedBuildsLock.Unlock()
+ if useBazel {
+ c.mixedBuildEnabledModules[moduleName] = struct{}{}
+ } else {
+ c.mixedBuildDisabledModules[moduleName] = struct{}{}
+ }
+}
diff --git a/android/filegroup.go b/android/filegroup.go
index 50356d1..1bf5e07 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -115,7 +115,7 @@
}
func (fg *fileGroup) maybeGenerateBazelBuildActions(ctx ModuleContext) {
- if !fg.MixedBuildsEnabled(ctx) {
+ if !MixedBuildsEnabled(ctx) {
return
}
diff --git a/android/metrics.go b/android/metrics.go
index 9038bde..1580f82 100644
--- a/android/metrics.go
+++ b/android/metrics.go
@@ -17,6 +17,7 @@
import (
"io/ioutil"
"runtime"
+ "sort"
"github.com/google/blueprint/metrics"
"google.golang.org/protobuf/proto"
@@ -78,6 +79,23 @@
}
metrics.Events = append(metrics.Events, &perfInfo)
}
+ mixedBuildsInfo := soong_metrics_proto.MixedBuildsInfo{}
+ mixedBuildEnabledModules := make([]string, 0, len(config.mixedBuildEnabledModules))
+ for module, _ := range config.mixedBuildEnabledModules {
+ mixedBuildEnabledModules = append(mixedBuildEnabledModules, module)
+ }
+
+ mixedBuildDisabledModules := make([]string, 0, len(config.mixedBuildDisabledModules))
+ for module, _ := range config.mixedBuildDisabledModules {
+ mixedBuildDisabledModules = append(mixedBuildDisabledModules, module)
+ }
+ // Sorted for deterministic output.
+ sort.Strings(mixedBuildEnabledModules)
+ sort.Strings(mixedBuildDisabledModules)
+
+ mixedBuildsInfo.MixedBuildEnabledModules = mixedBuildEnabledModules
+ mixedBuildsInfo.MixedBuildDisabledModules = mixedBuildDisabledModules
+ metrics.MixedBuildsInfo = &mixedBuildsInfo
return metrics
}