Refactor queryview.

Splits queryview into queryview and bp2build. The latter runs as a
presingleton (could be converted to a singleton). This prevents needing
to run soong_ui a subsequent time to build the query. Queryview remains
as a separate step to prevent increasing runtime due to this generation
every time Soong runs.

Currently this is running as a presingleton as this gives a translation
of Android.bp files after only LoadHooks have run, no mutators.

Test: go tests
Test: m queryview && bazel query --config=queryview //...
Change-Id: If2ba28c7ef60fbd41f43bda6623d41c8c7d23a1b
This commit is contained in:
Liz Kammer
2020-11-25 16:06:39 -08:00
parent 5bcf99a93a
commit 2dd9ca422d
16 changed files with 1467 additions and 959 deletions

View File

@@ -35,6 +35,9 @@ type singleton struct {
var singletons []singleton
var preSingletons []singleton
var bazelConverterSingletons []singleton
var bazelConverterPreSingletons []singleton
type mutator struct {
name string
bottomUpMutator blueprint.BottomUpMutator
@@ -79,6 +82,14 @@ func RegisterPreSingletonType(name string, factory SingletonFactory) {
preSingletons = append(preSingletons, singleton{name, factory})
}
func RegisterBazelConverterSingletonType(name string, factory SingletonFactory) {
bazelConverterSingletons = append(bazelConverterSingletons, singleton{name, factory})
}
func RegisterBazelConverterPreSingletonType(name string, factory SingletonFactory) {
bazelConverterPreSingletons = append(bazelConverterPreSingletons, singleton{name, factory})
}
type Context struct {
*blueprint.Context
config Config
@@ -94,13 +105,17 @@ func NewContext(config Config) *Context {
// singletons, module types and mutators to register for converting Blueprint
// files to semantically equivalent BUILD files.
func (ctx *Context) RegisterForBazelConversion() {
for _, t := range bazelConverterPreSingletons {
ctx.RegisterPreSingletonType(t.name, SingletonFactoryAdaptor(ctx, t.factory))
}
for _, t := range moduleTypes {
ctx.RegisterModuleType(t.name, ModuleFactoryAdaptor(t.factory))
}
bazelConverterSingleton := singleton{"bp2build", BazelConverterSingleton}
ctx.RegisterSingletonType(bazelConverterSingleton.name,
SingletonFactoryAdaptor(ctx, bazelConverterSingleton.factory))
for _, t := range bazelConverterSingletons {
ctx.RegisterSingletonType(t.name, SingletonFactoryAdaptor(ctx, t.factory))
}
registerMutatorsForBazelConversion(ctx.Context)
}