Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff851b83 authored by MarkDacek's avatar MarkDacek Committed by Mark Dacek
Browse files

Log information for Mixed Builds modules.

parent e91f9d43
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -338,9 +338,19 @@ func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, di
	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
+22 −3
Original line number Diff line number Diff line
@@ -170,6 +170,10 @@ type config struct {
	ninjaFileDepsSet sync.Map

	OncePer

	mixedBuildsLock           sync.Mutex
	mixedBuildEnabledModules  map[string]struct{}
	mixedBuildDisabledModules map[string]struct{}
}

type deviceConfig struct {
@@ -376,6 +380,8 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
		TestAllowNonExistentPaths: true,

		BazelContext:              noopBazelContext{},
		mixedBuildDisabledModules: make(map[string]struct{}),
		mixedBuildEnabledModules:  make(map[string]struct{}),
	}
	config.deviceConfig = &deviceConfig{
		config: config,
@@ -468,6 +474,8 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin

		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) RBEWrapper() string {
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{}{}
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ func FileGroupFactory() Module {
}

func (fg *fileGroup) maybeGenerateBazelBuildActions(ctx ModuleContext) {
	if !fg.MixedBuildsEnabled(ctx) {
	if !MixedBuildsEnabled(ctx) {
		return
	}

+18 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package android
import (
	"io/ioutil"
	"runtime"
	"sort"

	"github.com/google/blueprint/metrics"
	"google.golang.org/protobuf/proto"
@@ -78,6 +79,23 @@ func collectMetrics(config Config, eventHandler metrics.EventHandler) *soong_met
		}
		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
}
+1 −1
Original line number Diff line number Diff line
@@ -1789,7 +1789,7 @@ func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool {
	bazelActionsUsed := false
	// Mixed builds mode is disabled for modules outside of device OS.
	// TODO(b/200841190): Support non-device OS in mixed builds.
	if c.MixedBuildsEnabled(actx) && c.bazelHandler != nil {
	if android.MixedBuildsEnabled(actx) && c.bazelHandler != nil {
		bazelActionsUsed = c.bazelHandler.GenerateBazelBuildActions(actx, bazelModuleLabel)
	}
	return bazelActionsUsed
Loading