Implement code-generation step for bp2build.
Implement bp2build codegen as a discrete step that runs after an alternatively registered pipeline of mutators, instead of a presingleton. bp2build codegen requires a Context that supports VisitAllModules and PathContext, so this CL also makes a BpToBuildWrapperContext that conforms to PathContext by adding two method implementations. Test: GENERATE_BAZEL_FILES=true m nothing && bazel query //... --config=bp2build | wc -l # 31433 Test: m queryview && bazel query //... --config=queryview # 63638 Change-Id: I0dd359746584b228046d2d0ff00895f28f9bdfc3
This commit is contained in:
@@ -39,8 +39,26 @@ type bpToBuildContext interface {
|
||||
ModuleSubDir(module blueprint.Module) string
|
||||
ModuleType(module blueprint.Module) string
|
||||
|
||||
VisitAllModulesBlueprint(visit func(blueprint.Module))
|
||||
VisitDirectDeps(module android.Module, visit func(android.Module))
|
||||
VisitAllModules(visit func(blueprint.Module))
|
||||
VisitDirectDeps(module blueprint.Module, visit func(blueprint.Module))
|
||||
}
|
||||
|
||||
type CodegenContext struct {
|
||||
config android.Config
|
||||
context android.Context
|
||||
}
|
||||
|
||||
func (ctx CodegenContext) AddNinjaFileDeps(...string) {}
|
||||
func (ctx CodegenContext) Config() android.Config { return ctx.config }
|
||||
func (ctx CodegenContext) Context() android.Context { return ctx.context }
|
||||
|
||||
// NewCodegenContext creates a wrapper context that conforms to PathContext for
|
||||
// writing BUILD files in the output directory.
|
||||
func NewCodegenContext(config android.Config, context android.Context) CodegenContext {
|
||||
return CodegenContext{
|
||||
context: context,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
// props is an unsorted map. This function ensures that
|
||||
@@ -57,7 +75,7 @@ func propsToAttributes(props map[string]string) string {
|
||||
|
||||
func GenerateSoongModuleTargets(ctx bpToBuildContext) map[string][]BazelTarget {
|
||||
buildFileToTargets := make(map[string][]BazelTarget)
|
||||
ctx.VisitAllModulesBlueprint(func(m blueprint.Module) {
|
||||
ctx.VisitAllModules(func(m blueprint.Module) {
|
||||
dir := ctx.ModuleDir(m)
|
||||
t := generateSoongModuleTarget(ctx, m)
|
||||
buildFileToTargets[ctx.ModuleDir(m)] = append(buildFileToTargets[dir], t)
|
||||
@@ -75,7 +93,7 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) BazelTa
|
||||
// out the implications of that.
|
||||
depLabels := map[string]bool{}
|
||||
if aModule, ok := m.(android.Module); ok {
|
||||
ctx.VisitDirectDeps(aModule, func(depModule android.Module) {
|
||||
ctx.VisitDirectDeps(aModule, func(depModule blueprint.Module) {
|
||||
depLabels[qualifiedTargetLabel(ctx, depModule)] = true
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user