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", "api_levels.go",
"arch.go", "arch.go",
"bazel_handler.go", "bazel_handler.go",
"bazel_overlay.go",
"config.go", "config.go",
"csuite_config.go", "csuite_config.go",
"defaults.go", "defaults.go",
@@ -44,6 +43,7 @@ bootstrap_go_package {
"prebuilt.go", "prebuilt.go",
"prebuilt_build_tool.go", "prebuilt_build_tool.go",
"proto.go", "proto.go",
"queryview.go",
"register.go", "register.go",
"rule_builder.go", "rule_builder.go",
"sandbox.go", "sandbox.go",

View File

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

View File

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

View File

@@ -26,13 +26,13 @@ import (
) )
var ( var (
docFile string docFile string
bazelOverlayDir string bazelQueryViewDir string
) )
func init() { func init() {
flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output") 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 { func newNameResolver(config android.Config) *android.NameResolver {
@@ -113,8 +113,8 @@ func main() {
ctx = newContext(srcDir, configuration) ctx = newContext(srcDir, configuration)
bootstrap.Main(ctx.Context, configuration, extraNinjaDeps...) bootstrap.Main(ctx.Context, configuration, extraNinjaDeps...)
} }
if bazelOverlayDir != "" { if bazelQueryViewDir != "" {
if err := createBazelOverlay(ctx, bazelOverlayDir); err != nil { if err := createBazelQueryView(ctx, bazelQueryViewDir); err != nil {
fmt.Fprintf(os.Stderr, "%s", err) fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1) os.Exit(1)
} }
@@ -140,7 +140,7 @@ func main() {
} }
func shouldPrepareBuildActions() bool { 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. // collect metrics.
return docFile == "" && bazelOverlayDir == "" return docFile == "" && bazelQueryViewDir == ""
} }

View File

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

View File

@@ -28,7 +28,7 @@ var buildDir string
func setUp() { func setUp() {
var err error var err error
buildDir, err = ioutil.TempDir("", "bazel_overlay_test") buildDir, err = ioutil.TempDir("", "bazel_queryview_test")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -63,7 +63,7 @@ func customModuleFactory() android.Module {
return module return module
} }
func TestGenerateBazelOverlayFromBlueprint(t *testing.T) { func TestGenerateBazelQueryViewFromBlueprint(t *testing.T) {
testCases := []struct { testCases := []struct {
bp string bp string
expectedBazelTarget 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): def _foo_binary_impl(ctx):
return [SoongModuleInfo()] return [SoongModuleInfo()]
@@ -440,7 +440,7 @@ func TestGenerateSoongModuleBzl(t *testing.T) {
} }
actualSoongModuleBzl := generateSoongModuleBzl(ruleShims) 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 = { expectedRuleMap := `soong_module_rule_map = {
"foo_binary": foo_binary, "foo_binary": foo_binary,
"foo_library": foo_library, "foo_library": foo_library,