Loading android/bazel_paths.go +3 −4 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ type BazelConversionPathContext interface { EarlyModulePathContext GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) Module() Module ModuleType() string OtherModuleName(m blueprint.Module) string Loading Loading @@ -331,11 +332,9 @@ func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes // module. The label will be relative to the current directory if appropriate. The dependency must // already be resolved by either deps mutator or path deps mutator. func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWholeLibs bool) bazel.Label { m, _ := ctx.GetDirectDep(dep) m, _ := ctx.ModuleFromName(dep) if m == nil { panic(fmt.Errorf(`Cannot get direct dep %q of %q. This is likely because it was not added via AddDependency(). This may be due a mutator skipped during bp2build.`, dep, ctx.Module().Name())) panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name())) } otherLabel := bazelModuleLabel(ctx, m, tag) label := bazelModuleLabel(ctx, ctx.Module(), "") Loading android/module.go +19 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,8 @@ type BaseModuleContext interface { // the first DependencyTag. GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple // direct dependencies on the same module visit will be called multiple times on that module // and OtherModuleDependencyTag will return a different tag for each. Loading Loading @@ -2037,8 +2039,13 @@ type baseModuleContext struct { tagPath []blueprint.DependencyTag strictVisitDeps bool // If true, enforce that all dependencies are enabled bazelConversionMode bool } func (b *baseModuleContext) BazelConversionMode() bool { return b.bazelConversionMode } func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) } Loading Loading @@ -2378,6 +2385,18 @@ func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, bluepri return b.getDirectDepFirstTag(name) } func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) { if !b.BazelConversionMode() { panic("cannot call ModuleFromName if not in bazel conversion mode") } if len(name) > 1 && (name[0] == ':' || (name[0] == '/' && name[1] == '/')) { moduleName, _ := SrcIsModuleWithTag(name) return b.bp.ModuleFromName(moduleName) } else { return b.bp.ModuleFromName(name) } } func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { b.bp.VisitDirectDeps(visit) } Loading android/mutator.go +14 −32 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import ( // continue on to GenerateAndroidBuildActions // RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing. func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) { func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildMutators []RegisterMutatorFunc) { mctx := ®isterMutatorsContext{ bazelConversionMode: true, } Loading @@ -53,16 +53,6 @@ func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutat f(mctx) } bp2buildDepsMutators = append([]RegisterMutatorFunc{ registerDepsMutatorBp2Build, registerPathDepsMutator, registerBp2buildArchPathDepsMutator, }, depsMutators...) for _, f := range bp2buildDepsMutators { f(mctx) } // Register bp2build mutators for _, f := range bp2buildMutators { f(mctx) Loading Loading @@ -227,7 +217,6 @@ func FinalDepsMutators(f RegisterMutatorFunc) { } var bp2buildPreArchMutators = []RegisterMutatorFunc{} var bp2buildDepsMutators = []RegisterMutatorFunc{} var bp2buildMutators = map[string]RegisterMutatorFunc{} // See http://b/192523357 Loading @@ -254,12 +243,6 @@ func PreArchBp2BuildMutators(f RegisterMutatorFunc) { bp2buildPreArchMutators = append(bp2buildPreArchMutators, f) } // DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into // Bazel BUILD targets that should run prior to conversion to resolve dependencies. func DepsBp2BuildMutators(f RegisterMutatorFunc) { bp2buildDepsMutators = append(bp2buildDepsMutators, f) } type BaseMutatorContext interface { BaseModuleContext Loading @@ -269,6 +252,9 @@ type BaseMutatorContext interface { // Rename all variants of a module. The new name is not visible to calls to ModuleName, // AddDependency or OtherModuleName until after this mutator pass is complete. Rename(name string) // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion. BazelConversionMode() bool } type TopDownMutator func(TopDownMutatorContext) Loading Loading @@ -410,26 +396,24 @@ type BottomUpMutatorContext interface { // variant of the current module. The value should not be modified after being passed to // SetVariationProvider. SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion. BazelConversionMode() bool } type bottomUpMutatorContext struct { bp blueprint.BottomUpMutatorContext baseModuleContext finalPhase bool bazelConversionMode bool } func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, finalPhase, bazelConversionMode bool) BottomUpMutatorContext { moduleContext := a.base().baseModuleContextFactory(ctx) moduleContext.bazelConversionMode = bazelConversionMode return &bottomUpMutatorContext{ bp: ctx, baseModuleContext: a.base().baseModuleContextFactory(ctx), finalPhase: finalPhase, bazelConversionMode: bazelConversionMode, } } Loading Loading @@ -462,9 +446,11 @@ func (x *registerMutatorsContext) mutatorName(name string) string { func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { f := func(ctx blueprint.TopDownMutatorContext) { if a, ok := ctx.Module().(Module); ok { moduleContext := a.base().baseModuleContextFactory(ctx) moduleContext.bazelConversionMode = x.bazelConversionMode actx := &topDownMutatorContext{ bp: ctx, baseModuleContext: a.base().baseModuleContextFactory(ctx), baseModuleContext: moduleContext, } m(actx) } Loading Loading @@ -733,7 +719,3 @@ func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVaria func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { b.bp.SetVariationProvider(module, provider, value) } func (b *bottomUpMutatorContext) BazelConversionMode() bool { return b.bazelConversionMode } android/register.go +1 −1 Original line number Diff line number Diff line Loading @@ -180,7 +180,7 @@ func (ctx *Context) RegisterForBazelConversion() { bp2buildMutatorList = append(bp2buildMutatorList, f) } RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildDepsMutators, bp2buildMutatorList) RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildMutatorList) } // Register the pipeline of singletons, module types, and mutators for Loading android/testing.go +4 −10 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ func NewTestArchContext(config Config) *TestContext { type TestContext struct { *Context preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc bp2buildPreArch, bp2buildDeps, bp2buildMutators []RegisterMutatorFunc bp2buildPreArch, bp2buildMutators []RegisterMutatorFunc NameResolver *NameResolver // The list of pre-singletons and singletons registered for the test. Loading Loading @@ -224,12 +224,6 @@ func (ctx *TestContext) PreArchBp2BuildMutators(f RegisterMutatorFunc) { ctx.bp2buildPreArch = append(ctx.bp2buildPreArch, f) } // DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into // Bazel BUILD targets that should run prior to conversion to resolve dependencies. func (ctx *TestContext) DepsBp2BuildMutators(f RegisterMutatorFunc) { ctx.bp2buildDeps = append(ctx.bp2buildDeps, f) } // registeredComponentOrder defines the order in which a sortableComponent type is registered at // runtime and provides support for reordering the components registered for a test in the same // way. Loading Loading @@ -464,7 +458,7 @@ func (ctx *TestContext) Register() { // RegisterForBazelConversion prepares a test context for bp2build conversion. func (ctx *TestContext) RegisterForBazelConversion() { RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildDeps, ctx.bp2buildMutators) RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildMutators) } func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) { Loading Loading
android/bazel_paths.go +3 −4 Original line number Diff line number Diff line Loading @@ -73,6 +73,7 @@ type BazelConversionPathContext interface { EarlyModulePathContext GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) Module() Module ModuleType() string OtherModuleName(m blueprint.Module) string Loading Loading @@ -331,11 +332,9 @@ func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes // module. The label will be relative to the current directory if appropriate. The dependency must // already be resolved by either deps mutator or path deps mutator. func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string, isWholeLibs bool) bazel.Label { m, _ := ctx.GetDirectDep(dep) m, _ := ctx.ModuleFromName(dep) if m == nil { panic(fmt.Errorf(`Cannot get direct dep %q of %q. This is likely because it was not added via AddDependency(). This may be due a mutator skipped during bp2build.`, dep, ctx.Module().Name())) panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name())) } otherLabel := bazelModuleLabel(ctx, m, tag) label := bazelModuleLabel(ctx, ctx.Module(), "") Loading
android/module.go +19 −0 Original line number Diff line number Diff line Loading @@ -223,6 +223,8 @@ type BaseModuleContext interface { // the first DependencyTag. GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) ModuleFromName(name string) (blueprint.Module, bool) // VisitDirectDepsBlueprint calls visit for each direct dependency. If there are multiple // direct dependencies on the same module visit will be called multiple times on that module // and OtherModuleDependencyTag will return a different tag for each. Loading Loading @@ -2037,8 +2039,13 @@ type baseModuleContext struct { tagPath []blueprint.DependencyTag strictVisitDeps bool // If true, enforce that all dependencies are enabled bazelConversionMode bool } func (b *baseModuleContext) BazelConversionMode() bool { return b.bazelConversionMode } func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { return b.bp.OtherModuleName(m) } Loading Loading @@ -2378,6 +2385,18 @@ func (b *baseModuleContext) GetDirectDep(name string) (blueprint.Module, bluepri return b.getDirectDepFirstTag(name) } func (b *baseModuleContext) ModuleFromName(name string) (blueprint.Module, bool) { if !b.BazelConversionMode() { panic("cannot call ModuleFromName if not in bazel conversion mode") } if len(name) > 1 && (name[0] == ':' || (name[0] == '/' && name[1] == '/')) { moduleName, _ := SrcIsModuleWithTag(name) return b.bp.ModuleFromName(moduleName) } else { return b.bp.ModuleFromName(name) } } func (b *baseModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { b.bp.VisitDirectDeps(visit) } Loading
android/mutator.go +14 −32 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ import ( // continue on to GenerateAndroidBuildActions // RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing. func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) { func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, bp2buildMutators []RegisterMutatorFunc) { mctx := ®isterMutatorsContext{ bazelConversionMode: true, } Loading @@ -53,16 +53,6 @@ func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators, depsMutat f(mctx) } bp2buildDepsMutators = append([]RegisterMutatorFunc{ registerDepsMutatorBp2Build, registerPathDepsMutator, registerBp2buildArchPathDepsMutator, }, depsMutators...) for _, f := range bp2buildDepsMutators { f(mctx) } // Register bp2build mutators for _, f := range bp2buildMutators { f(mctx) Loading Loading @@ -227,7 +217,6 @@ func FinalDepsMutators(f RegisterMutatorFunc) { } var bp2buildPreArchMutators = []RegisterMutatorFunc{} var bp2buildDepsMutators = []RegisterMutatorFunc{} var bp2buildMutators = map[string]RegisterMutatorFunc{} // See http://b/192523357 Loading @@ -254,12 +243,6 @@ func PreArchBp2BuildMutators(f RegisterMutatorFunc) { bp2buildPreArchMutators = append(bp2buildPreArchMutators, f) } // DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into // Bazel BUILD targets that should run prior to conversion to resolve dependencies. func DepsBp2BuildMutators(f RegisterMutatorFunc) { bp2buildDepsMutators = append(bp2buildDepsMutators, f) } type BaseMutatorContext interface { BaseModuleContext Loading @@ -269,6 +252,9 @@ type BaseMutatorContext interface { // Rename all variants of a module. The new name is not visible to calls to ModuleName, // AddDependency or OtherModuleName until after this mutator pass is complete. Rename(name string) // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion. BazelConversionMode() bool } type TopDownMutator func(TopDownMutatorContext) Loading Loading @@ -410,26 +396,24 @@ type BottomUpMutatorContext interface { // variant of the current module. The value should not be modified after being passed to // SetVariationProvider. SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion. BazelConversionMode() bool } type bottomUpMutatorContext struct { bp blueprint.BottomUpMutatorContext baseModuleContext finalPhase bool bazelConversionMode bool } func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, finalPhase, bazelConversionMode bool) BottomUpMutatorContext { moduleContext := a.base().baseModuleContextFactory(ctx) moduleContext.bazelConversionMode = bazelConversionMode return &bottomUpMutatorContext{ bp: ctx, baseModuleContext: a.base().baseModuleContextFactory(ctx), finalPhase: finalPhase, bazelConversionMode: bazelConversionMode, } } Loading Loading @@ -462,9 +446,11 @@ func (x *registerMutatorsContext) mutatorName(name string) string { func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { f := func(ctx blueprint.TopDownMutatorContext) { if a, ok := ctx.Module().(Module); ok { moduleContext := a.base().baseModuleContextFactory(ctx) moduleContext.bazelConversionMode = x.bazelConversionMode actx := &topDownMutatorContext{ bp: ctx, baseModuleContext: a.base().baseModuleContextFactory(ctx), baseModuleContext: moduleContext, } m(actx) } Loading Loading @@ -733,7 +719,3 @@ func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVaria func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { b.bp.SetVariationProvider(module, provider, value) } func (b *bottomUpMutatorContext) BazelConversionMode() bool { return b.bazelConversionMode }
android/register.go +1 −1 Original line number Diff line number Diff line Loading @@ -180,7 +180,7 @@ func (ctx *Context) RegisterForBazelConversion() { bp2buildMutatorList = append(bp2buildMutatorList, f) } RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildDepsMutators, bp2buildMutatorList) RegisterMutatorsForBazelConversion(ctx, bp2buildPreArchMutators, bp2buildMutatorList) } // Register the pipeline of singletons, module types, and mutators for Loading
android/testing.go +4 −10 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ func NewTestArchContext(config Config) *TestContext { type TestContext struct { *Context preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc bp2buildPreArch, bp2buildDeps, bp2buildMutators []RegisterMutatorFunc bp2buildPreArch, bp2buildMutators []RegisterMutatorFunc NameResolver *NameResolver // The list of pre-singletons and singletons registered for the test. Loading Loading @@ -224,12 +224,6 @@ func (ctx *TestContext) PreArchBp2BuildMutators(f RegisterMutatorFunc) { ctx.bp2buildPreArch = append(ctx.bp2buildPreArch, f) } // DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into // Bazel BUILD targets that should run prior to conversion to resolve dependencies. func (ctx *TestContext) DepsBp2BuildMutators(f RegisterMutatorFunc) { ctx.bp2buildDeps = append(ctx.bp2buildDeps, f) } // registeredComponentOrder defines the order in which a sortableComponent type is registered at // runtime and provides support for reordering the components registered for a test in the same // way. Loading Loading @@ -464,7 +458,7 @@ func (ctx *TestContext) Register() { // RegisterForBazelConversion prepares a test context for bp2build conversion. func (ctx *TestContext) RegisterForBazelConversion() { RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildDeps, ctx.bp2buildMutators) RegisterMutatorsForBazelConversion(ctx.Context, ctx.bp2buildPreArch, ctx.bp2buildMutators) } func (ctx *TestContext) ParseFileList(rootDir string, filePaths []string) (deps []string, errs []error) { Loading