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:
@@ -1742,6 +1742,19 @@ func WriteFileToOutputDir(path WritablePath, data []byte, perm os.FileMode) erro
|
||||
return ioutil.WriteFile(absolutePath(path.String()), data, perm)
|
||||
}
|
||||
|
||||
func RemoveAllOutputDir(path WritablePath) error {
|
||||
return os.RemoveAll(absolutePath(path.String()))
|
||||
}
|
||||
|
||||
func CreateOutputDirIfNonexistent(path WritablePath, perm os.FileMode) error {
|
||||
dir := absolutePath(path.String())
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
return os.MkdirAll(dir, os.ModePerm)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func absolutePath(path string) string {
|
||||
if filepath.IsAbs(path) {
|
||||
return path
|
||||
|
@@ -26,7 +26,6 @@ import (
|
||||
// for calling the soong_build primary builder in the main build.ninja file.
|
||||
func init() {
|
||||
RegisterSingletonType("bazel_queryview", BazelQueryViewSingleton)
|
||||
RegisterSingletonType("bazel_converter", BazelConverterSingleton)
|
||||
}
|
||||
|
||||
// BazelQueryViewSingleton is the singleton responsible for registering the
|
||||
@@ -52,13 +51,7 @@ type bazelConverterSingleton struct{}
|
||||
|
||||
func generateBuildActionsForBazelConversion(ctx SingletonContext, converterMode bool) {
|
||||
name := "queryview"
|
||||
additionalEnvVars := ""
|
||||
descriptionTemplate := "[EXPERIMENTAL, PRE-PRODUCTION] Creating the Bazel QueryView workspace with %s at $outDir"
|
||||
if converterMode {
|
||||
name = "bp2build"
|
||||
additionalEnvVars = "CONVERT_TO_BAZEL=true"
|
||||
descriptionTemplate = "[EXPERIMENTAL, PRE-PRODUCTION] Converting all Android.bp to Bazel BUILD files with %s at $outDir"
|
||||
}
|
||||
|
||||
// Create a build and rule statement, using the Bazel QueryView's WORKSPACE
|
||||
// file as the output file marker.
|
||||
@@ -74,9 +67,8 @@ func generateBuildActionsForBazelConversion(ctx SingletonContext, converterMode
|
||||
blueprint.RuleParams{
|
||||
Command: fmt.Sprintf(
|
||||
"rm -rf ${outDir}/* && "+
|
||||
"%s %s --bazel_queryview_dir ${outDir} %s && "+
|
||||
"%s --bazel_queryview_dir ${outDir} %s && "+
|
||||
"echo WORKSPACE: `cat %s` > ${outDir}/.queryview-depfile.d",
|
||||
additionalEnvVars,
|
||||
primaryBuilder.String(),
|
||||
strings.Join(os.Args[1:], " "),
|
||||
moduleListFilePath.String(), // Use the contents of Android.bp.list as the depfile.
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user