Rename bazel overlay to queryview.

Bazel overlay is an experimental feature. This renames the feature to 'queryview' to better describe its purpose, and also move away from the already overloaded 'overlay' term in Android.

Test: m queryview && bazel query --package_path=out/soong/queryview //...
Change-Id: I8b5068c7db46cb61a03a8e87af9c7c9077ebeff9
This commit is contained in:
Jingwen Chen 2020-11-05 07:42:11 -05:00
parent b0a713acf9
commit 50f93d2078
6 changed files with 45 additions and 44 deletions

View file

@ -16,7 +16,6 @@ bootstrap_go_package {
"api_levels.go",
"arch.go",
"bazel_handler.go",
"bazel_overlay.go",
"config.go",
"csuite_config.go",
"defaults.go",
@ -44,6 +43,7 @@ bootstrap_go_package {
"prebuilt.go",
"prebuilt_build_tool.go",
"proto.go",
"queryview.go",
"register.go",
"rule_builder.go",
"sandbox.go",

View file

@ -22,55 +22,55 @@ import (
"github.com/google/blueprint"
)
// The Bazel Overlay singleton is responsible for generating the Ninja actions
// The Bazel QueryView singleton is responsible for generating the Ninja actions
// for calling the soong_build primary builder in the main build.ninja file.
func init() {
RegisterSingletonType("bazel_overlay", BazelOverlaySingleton)
RegisterSingletonType("bazel_queryView", BazelQueryViewSingleton)
}
func BazelOverlaySingleton() Singleton {
return &bazelOverlaySingleton{}
func BazelQueryViewSingleton() Singleton {
return &bazelQueryViewSingleton{}
}
type bazelOverlaySingleton struct{}
type bazelQueryViewSingleton struct{}
func (c *bazelOverlaySingleton) GenerateBuildActions(ctx SingletonContext) {
// Create a build and rule statement, using the Bazel overlay's WORKSPACE
func (c *bazelQueryViewSingleton) GenerateBuildActions(ctx SingletonContext) {
// Create a build and rule statement, using the Bazel QueryView's WORKSPACE
// file as the output file marker.
var deps Paths
moduleListFilePath := pathForBuildToolDep(ctx, ctx.Config().moduleListFile)
deps = append(deps, moduleListFilePath)
deps = append(deps, pathForBuildToolDep(ctx, ctx.Config().ProductVariablesFileName))
bazelOverlayDirectory := PathForOutput(ctx, "bazel_overlay")
bazelOverlayWorkspaceFile := bazelOverlayDirectory.Join(ctx, "WORKSPACE")
bazelQueryViewDirectory := PathForOutput(ctx, "queryview")
bazelQueryViewWorkspaceFile := bazelQueryViewDirectory.Join(ctx, "WORKSPACE")
primaryBuilder := primaryBuilderPath(ctx)
bazelOverlay := ctx.Rule(pctx, "bazelOverlay",
bazelQueryView := ctx.Rule(pctx, "bazelQueryView",
blueprint.RuleParams{
Command: fmt.Sprintf(
"rm -rf ${outDir}/* && %s --bazel_overlay_dir ${outDir} %s && echo WORKSPACE: `cat %s` > ${outDir}/.overlay-depfile.d",
"rm -rf ${outDir}/* && %s --bazel_queryview_dir ${outDir} %s && echo WORKSPACE: `cat %s` > ${outDir}/.queryview-depfile.d",
primaryBuilder.String(),
strings.Join(os.Args[1:], " "),
moduleListFilePath.String(), // Use the contents of Android.bp.list as the depfile.
),
CommandDeps: []string{primaryBuilder.String()},
Description: fmt.Sprintf(
"Creating the Bazel overlay workspace with %s at $outDir",
"Creating the Bazel QueryView workspace with %s at $outDir",
primaryBuilder.Base()),
Deps: blueprint.DepsGCC,
Depfile: "${outDir}/.overlay-depfile.d",
Depfile: "${outDir}/.queryview-depfile.d",
},
"outDir")
ctx.Build(pctx, BuildParams{
Rule: bazelOverlay,
Output: bazelOverlayWorkspaceFile,
Rule: bazelQueryView,
Output: bazelQueryViewWorkspaceFile,
Inputs: deps,
Args: map[string]string{
"outDir": bazelOverlayDirectory.String(),
"outDir": bazelQueryViewDirectory.String(),
},
})
// Add a phony target for building the bazel overlay
ctx.Phony("bazel_overlay", bazelOverlayWorkspaceFile)
// Add a phony target for building the Bazel QueryView
ctx.Phony("queryview", bazelQueryViewWorkspaceFile)
}

View file

@ -26,10 +26,10 @@ bootstrap_go_binary {
srcs: [
"main.go",
"writedocs.go",
"bazel_overlay.go",
"queryview.go",
],
testSrcs: [
"bazel_overlay_test.go",
"queryview_test.go",
],
primaryBuilder: true,
}

View file

@ -26,13 +26,13 @@ import (
)
var (
docFile string
bazelOverlayDir string
docFile string
bazelQueryViewDir string
)
func init() {
flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output")
flag.StringVar(&bazelOverlayDir, "bazel_overlay_dir", "", "path to the bazel overlay directory")
flag.StringVar(&bazelQueryViewDir, "bazel_queryview_dir", "", "path to the bazel queryview directory")
}
func newNameResolver(config android.Config) *android.NameResolver {
@ -113,8 +113,8 @@ func main() {
ctx = newContext(srcDir, configuration)
bootstrap.Main(ctx.Context, configuration, extraNinjaDeps...)
}
if bazelOverlayDir != "" {
if err := createBazelOverlay(ctx, bazelOverlayDir); err != nil {
if bazelQueryViewDir != "" {
if err := createBazelQueryView(ctx, bazelQueryViewDir); err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}
@ -140,7 +140,7 @@ func main() {
}
func shouldPrepareBuildActions() bool {
// If we're writing soong_docs or bazel_overlay, don't write build.ninja or
// If we're writing soong_docs or queryview, don't write build.ninja or
// collect metrics.
return docFile == "" && bazelOverlayDir == ""
return docFile == "" && bazelQueryViewDir == ""
}

View file

@ -31,7 +31,7 @@ import (
const (
// The default `load` preamble for every generated BUILD file.
soongModuleLoad = `package(default_visibility = ["//visibility:public"])
load("//build/bazel/overlay_rules:soong_module.bzl", "soong_module")
load("//build/bazel/queryview_rules:soong_module.bzl", "soong_module")
`
@ -62,7 +62,7 @@ load("//build/bazel/overlay_rules:soong_module.bzl", "soong_module")
soongModuleBzl = `
%s
load("//build/bazel/overlay_rules:providers.bzl", "SoongModuleInfo")
load("//build/bazel/queryview_rules:providers.bzl", "SoongModuleInfo")
def _generic_soong_module_impl(ctx):
return [
@ -396,7 +396,7 @@ func createRuleShims(packages []*bpdoc.Package) (map[string]RuleShim, error) {
ruleShims := map[string]RuleShim{}
for _, pkg := range packages {
content := "load(\"//build/bazel/overlay_rules:providers.bzl\", \"SoongModuleInfo\")\n"
content := "load(\"//build/bazel/queryview_rules:providers.bzl\", \"SoongModuleInfo\")\n"
bzlFileName := strings.ReplaceAll(pkg.Path, "android/soong/", "")
bzlFileName = strings.ReplaceAll(bzlFileName, ".", "_")
@ -441,10 +441,10 @@ func createRuleShims(packages []*bpdoc.Package) (map[string]RuleShim, error) {
return ruleShims, nil
}
func createBazelOverlay(ctx *android.Context, bazelOverlayDir string) error {
func createBazelQueryView(ctx *android.Context, bazelQueryViewDir string) error {
blueprintCtx := ctx.Context
blueprintCtx.VisitAllModules(func(module blueprint.Module) {
buildFile, err := buildFileForModule(blueprintCtx, module)
buildFile, err := buildFileForModule(blueprintCtx, module, bazelQueryViewDir)
if err != nil {
panic(err)
}
@ -455,12 +455,12 @@ func createBazelOverlay(ctx *android.Context, bazelOverlayDir string) error {
var err error
// Write top level files: WORKSPACE and BUILD. These files are empty.
if err = writeReadOnlyFile(bazelOverlayDir, "WORKSPACE", ""); err != nil {
if err = writeReadOnlyFile(bazelQueryViewDir, "WORKSPACE", ""); err != nil {
return err
}
// Used to denote that the top level directory is a package.
if err = writeReadOnlyFile(bazelOverlayDir, "BUILD", ""); err != nil {
if err = writeReadOnlyFile(bazelQueryViewDir, "BUILD", ""); err != nil {
return err
}
@ -474,7 +474,7 @@ func createBazelOverlay(ctx *android.Context, bazelOverlayDir string) error {
}
// Write .bzl Starlark files into the bazel_rules top level directory (provider and rule definitions)
bazelRulesDir := bazelOverlayDir + "/build/bazel/overlay_rules"
bazelRulesDir := bazelQueryViewDir + "/build/bazel/queryview_rules"
if err = writeReadOnlyFile(bazelRulesDir, "BUILD", ""); err != nil {
return err
}
@ -497,7 +497,7 @@ func generateSoongModuleBzl(bzlLoads map[string]RuleShim) string {
var loadStmts string
var moduleRuleMap string
for bzlFileName, ruleShim := range bzlLoads {
loadStmt := "load(\"//build/bazel/overlay_rules:"
loadStmt := "load(\"//build/bazel/queryview_rules:"
loadStmt += bzlFileName
loadStmt += ".bzl\""
for _, rule := range ruleShim.rules {
@ -563,9 +563,10 @@ func generateSoongModuleTarget(
attributes)
}
func buildFileForModule(ctx *blueprint.Context, module blueprint.Module) (*os.File, error) {
func buildFileForModule(
ctx *blueprint.Context, module blueprint.Module, bazelQueryViewDir string) (*os.File, error) {
// Create nested directories for the BUILD file
dirPath := filepath.Join(bazelOverlayDir, packagePath(ctx, module))
dirPath := filepath.Join(bazelQueryViewDir, packagePath(ctx, module))
createDirectoryIfNonexistent(dirPath)
// Open the file for appending, and create it if it doesn't exist
f, err := os.OpenFile(
@ -594,7 +595,7 @@ func createDirectoryIfNonexistent(dir string) {
}
}
// The overlay directory should be read-only, sufficient for bazel query. The files
// The QueryView directory should be read-only, sufficient for bazel query. The files
// are not intended to be edited by end users.
func writeReadOnlyFile(dir string, baseName string, content string) error {
createDirectoryIfNonexistent(dir)

View file

@ -28,7 +28,7 @@ var buildDir string
func setUp() {
var err error
buildDir, err = ioutil.TempDir("", "bazel_overlay_test")
buildDir, err = ioutil.TempDir("", "bazel_queryview_test")
if err != nil {
panic(err)
}
@ -63,7 +63,7 @@ func customModuleFactory() android.Module {
return module
}
func TestGenerateBazelOverlayFromBlueprint(t *testing.T) {
func TestGenerateBazelQueryViewFromBlueprint(t *testing.T) {
testCases := []struct {
bp string
expectedBazelTarget string
@ -362,7 +362,7 @@ func TestGenerateModuleRuleShims(t *testing.T) {
}
}
expectedBzl := `load("//build/bazel/overlay_rules:providers.bzl", "SoongModuleInfo")
expectedBzl := `load("//build/bazel/queryview_rules:providers.bzl", "SoongModuleInfo")
def _foo_binary_impl(ctx):
return [SoongModuleInfo()]
@ -440,7 +440,7 @@ func TestGenerateSoongModuleBzl(t *testing.T) {
}
actualSoongModuleBzl := generateSoongModuleBzl(ruleShims)
expectedLoad := "load(\"//build/bazel/overlay_rules:foo.bzl\", \"foo_binary\", \"foo_library\", \"foo_test_\")"
expectedLoad := "load(\"//build/bazel/queryview_rules:foo.bzl\", \"foo_binary\", \"foo_library\", \"foo_test_\")"
expectedRuleMap := `soong_module_rule_map = {
"foo_binary": foo_binary,
"foo_library": foo_library,