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

Commit fc1ad29e authored by Jingwen Chen's avatar Jingwen Chen Committed by Gerrit Code Review
Browse files

Merge "bp2build: framework for generating BazelTargetModules."

parents e09ac174 73850676
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package android

import (
	"android/soong/bazel"
	"fmt"
	"os"
	"path"
@@ -491,6 +492,26 @@ type Module interface {
	TransitivePackagingSpecs() []PackagingSpec
}

type BazelTargetModule interface {
	Module

	BazelTargetModuleProperties() *bazel.BazelTargetModuleProperties
}

func InitBazelTargetModule(module BazelTargetModule) {
	module.AddProperties(module.BazelTargetModuleProperties())
	InitAndroidModule(module)
}

type BazelTargetModuleBase struct {
	ModuleBase
	Properties bazel.BazelTargetModuleProperties
}

func (btmb *BazelTargetModuleBase) BazelTargetModuleProperties() *bazel.BazelTargetModuleProperties {
	return &btmb.Properties
}

// Qualified id for a module
type qualifiedModuleName struct {
	// The package (i.e. directory) in which the module is defined, without trailing /
@@ -1069,6 +1090,9 @@ type ModuleBase struct {
	archProperties          [][]interface{}
	customizableProperties  []interface{}

	// Properties specific to the Blueprint to BUILD migration.
	bazelTargetModuleProperties bazel.BazelTargetModuleProperties

	// Information about all the properties on the module that contains visibility rules that need
	// checking.
	visibilityPropertyInfo []visibilityProperty
+25 −3
Original line number Diff line number Diff line
@@ -44,9 +44,16 @@ func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
	}
}

func registerMutatorsForBazelConversion(ctx *blueprint.Context) {
	// FIXME(b/171263886): Start bringing in mutators to make the Bionic
	// module subgraph suitable for automated conversion.
// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
func RegisterMutatorsForBazelConversion(ctx *blueprint.Context, bp2buildMutators []RegisterMutatorFunc) {
	mctx := &registerMutatorsContext{}

	// Register bp2build mutators
	for _, f := range bp2buildMutators {
		f(mctx)
	}

	registerMutatorsToContext(ctx, mctx.mutators)
}

func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) {
@@ -196,6 +203,21 @@ func FinalDepsMutators(f RegisterMutatorFunc) {
	finalDeps = append(finalDeps, f)
}

var bp2buildMutators = []RegisterMutatorFunc{}

// RegisterBp2BuildMutator registers specially crafted mutators for
// converting Blueprint/Android modules into special modules that can
// be code-generated into Bazel BUILD targets.
//
// TODO(b/178068862): bring this into TestContext.
func RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) {
	mutatorName := moduleType + "_bp2build"
	f := func(ctx RegisterMutatorsContext) {
		ctx.TopDown(mutatorName, m)
	}
	bp2buildMutators = append(bp2buildMutators, f)
}

type BaseMutatorContext interface {
	BaseModuleContext

+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ func (ctx *Context) RegisterForBazelConversion() {
		ctx.RegisterSingletonType(t.name, SingletonFactoryAdaptor(ctx, t.factory))
	}

	registerMutatorsForBazelConversion(ctx.Context)
	RegisterMutatorsForBazelConversion(ctx.Context, bp2buildMutators)
}

// Register the pipeline of singletons, module types, and mutators for
+16 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ func NewTestArchContext(config Config) *TestContext {
type TestContext struct {
	*Context
	preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc
	bp2buildMutators                      []RegisterMutatorFunc
	NameResolver                          *NameResolver
}

@@ -81,12 +82,27 @@ func (ctx *TestContext) FinalDepsMutators(f RegisterMutatorFunc) {
	ctx.finalDeps = append(ctx.finalDeps, f)
}

// RegisterBp2BuildMutator registers a BazelTargetModule mutator for converting a module
// type to the equivalent Bazel target.
func (ctx *TestContext) RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) {
	mutatorName := moduleType + "_bp2build"
	f := func(ctx RegisterMutatorsContext) {
		ctx.TopDown(mutatorName, m)
	}
	bp2buildMutators = append(bp2buildMutators, f)
}

func (ctx *TestContext) Register() {
	registerMutators(ctx.Context.Context, ctx.preArch, ctx.preDeps, ctx.postDeps, ctx.finalDeps)

	ctx.RegisterSingletonType("env", EnvSingleton)
}

// RegisterForBazelConversion prepares a test context for bp2build conversion.
func (ctx *TestContext) RegisterForBazelConversion() {
	RegisterMutatorsForBazelConversion(ctx.Context.Context, bp2buildMutators)
}

func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) {
	// This function adapts the old style ParseFileList calls that are spread throughout the tests
	// to the new style that takes a config.
+8 −1
Original line number Diff line number Diff line
@@ -19,9 +19,16 @@ type bazelModuleProperties struct {
	Label string
}

// Properties contains common module properties for migration purposes.
// Properties contains common module properties for Bazel migration purposes.
type Properties struct {
	// In USE_BAZEL_ANALYSIS=1 mode, this represents the Bazel target replacing
	// this Soong module.
	Bazel_module bazelModuleProperties
}

// BazelTargetModuleProperties contain properties and metadata used for
// Blueprint to BUILD file conversion.
type BazelTargetModuleProperties struct {
	// The Bazel rule class for this target.
	Rule_class string
}
Loading