Merge "Remove bp2build from wayland-protocols" into main am: d7176e3a29

Original change: https://android-review.googlesource.com/c/platform/external/wayland-protocols/+/2865265

Change-Id: I2d51fce10a6b38d95eeb0272d62109eee35fa84c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/wayland_protocol_codegen.go b/wayland_protocol_codegen.go
index 0711ac7..e507e61 100644
--- a/wayland_protocol_codegen.go
+++ b/wayland_protocol_codegen.go
@@ -26,12 +26,6 @@
 been recently restructured so that it can be kept in sync with a tool like
 "vimdiff" to keep things in sync as needed.
 
-However this build system plugin will not be needed in the future, as
-evidenced by some of the other files that have been added as part of the
-last big sync-up. In the future, Android will be built with Bazel, and it
-is much simpler there to define our own local version of "gensrcs" that
-implements the functionality we need See bazel/gensrcs.bzl for it.
-
 Notable differences:
 
   - This package implements a more powerful template mechanism for specifying
@@ -82,10 +76,7 @@
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
-	"android/soong/bazel"
-	"android/soong/bazel/cquery"
 	"android/soong/genrule"
-	"path/filepath"
 )
 
 func init() {
@@ -188,7 +179,6 @@
 type Module struct {
 	android.ModuleBase
 	android.DefaultableModuleBase
-	android.BazelModuleBase
 	android.ApexModuleBase
 
 	android.ImageInterface
@@ -211,9 +201,6 @@
 	modulePaths []string
 }
 
-// Ensure Module implements the android.MixedBuildBuildable interface.
-var _ android.MixedBuildBuildable = (*Module)(nil)
-
 type taskFunc func(ctx android.ModuleContext, rawCommand string, srcFiles android.Paths) []generateTask
 
 type generateTask struct {
@@ -289,41 +276,6 @@
 	}
 }
 
-// Part of android.MixedBuildBuildable.
-// Allow this module to be a bridge between Bazel and Soong. Fills in Soong
-// properties for the module from the Bazel cquery, so that other Soong
-// modules can depend on the module when it was actually built by Bazel.
-func (g *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
-	g.generateCommonBuildActions(ctx)
-
-	// Get the list of output files that Bazel generates for the target.
-	label := g.GetBazelLabel(ctx, g)
-	bazelCtx := ctx.Config().BazelContext
-	filePaths, err := bazelCtx.GetOutputFiles(label, android.GetConfigKey(ctx))
-	if err != nil {
-		ctx.ModuleErrorf(err.Error())
-		return
-	}
-
-	// Convert to android.Paths, and also form the set of include directories
-	// that might be needed for those paths.
-	var bazelOutputFiles android.Paths
-	exportIncludeDirs := map[string]bool{}
-	for _, bazelOutputFile := range filePaths {
-		bazelOutputFiles = append(bazelOutputFiles,
-			android.PathForBazelOutRelative(ctx, ctx.ModuleDir(), bazelOutputFile))
-		exportIncludeDirs[filepath.Dir(bazelOutputFile)] = true
-	}
-
-	// Set the Soong module properties to refer to the Bazel files
-	g.outputFiles = bazelOutputFiles
-	g.outputDeps = bazelOutputFiles
-	for includePath, _ := range exportIncludeDirs {
-		g.exportedIncludeDirs = append(g.exportedIncludeDirs,
-			android.PathForBazelOut(ctx, includePath))
-	}
-}
-
 // Part of android.Module.
 // Generates all the rules and builds commands used by this module instance.
 func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) {
@@ -641,20 +593,6 @@
 	}
 }
 
-// Part of android.MixedBuildBuildable.
-// Queues up Bazel cquery requests related to this module.
-func (g *Module) QueueBazelCall(ctx android.BaseModuleContext) {
-	bazelCtx := ctx.Config().BazelContext
-	bazelCtx.QueueBazelRequest(g.GetBazelLabel(ctx, g), cquery.GetOutputFiles,
-		android.GetConfigKey(ctx))
-}
-
-// Part of android.MixedBuildBuildable.
-// Returns true if Bazel can and should build this module in a mixed build.
-func (g *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
-	return true
-}
-
 // Part of android.IDEInfo.
 // Collect information for opening IDE project files in java/jdeps.go.
 func (g *Module) IDEInfo(dpInfo *android.IdeInfo) {
@@ -823,7 +761,6 @@
 func codegenFactory() android.Module {
 	m := newCodegen()
 	android.InitAndroidModule(m)
-	android.InitBazelModule(m)
 	android.InitDefaultableModule(m)
 	return m
 }
@@ -910,108 +847,6 @@
 	return path
 }
 
-// The attributes for the custom local ./bazel/gensrcs.bzl. See the .bzl file
-// for attribute documentation.
-type bazelGensrcsAttributes struct {
-	Srcs   bazel.LabelListAttribute
-	Output string
-	Tools  bazel.LabelListAttribute
-	Cmd    string
-}
-
-// ConvertWithBp2build converts a Soong module -> Bazel target.
-func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
-	// Bazel only has the "tools" attribute.
-	tools_prop := android.BazelLabelForModuleDeps(ctx, m.properties.Tools)
-	tool_files_prop := android.BazelLabelForModuleSrc(ctx, m.properties.Tool_files)
-	tools_prop.Append(tool_files_prop)
-
-	tools := bazel.MakeLabelListAttribute(tools_prop)
-	srcs := bazel.LabelListAttribute{}
-	srcs_labels := bazel.LabelList{}
-	srcs_labels = android.BazelLabelForModuleSrcExcludes(
-		ctx, m.properties.Srcs, m.properties.Exclude_srcs)
-	srcs = bazel.MakeLabelListAttribute(srcs_labels)
-
-	var allReplacements bazel.LabelList
-	allReplacements.Append(tools.Value)
-	allReplacements.Append(bazel.FirstUniqueBazelLabelList(srcs_labels))
-
-	// Convert the command line template.
-	var cmd string
-	if m.properties.Cmd != nil {
-		// $(in) becomes $(SRC) in our custom gensrcs.bzl
-		cmd = strings.ReplaceAll(*m.properties.Cmd, "$(in)", "$(SRC)")
-		// $(out) becomes $(OUT) in our custom gensrcs.bzl
-		cmd = strings.ReplaceAll(cmd, "$(out)", "$(OUT)")
-		// $(gendir) becomes $(RULEDIR) in our custom gensrcs.bzl
-		cmd = strings.Replace(cmd, "$(genDir)", "$(RULEDIR)", -1)
-
-		// $(location) or $(locations) becomes the more explicit
-		// $(location <default-tool-label>) in Bazel.
-		if len(tools.Value.Includes) > 0 {
-			cmd = strings.Replace(cmd, "$(location)",
-				fmt.Sprintf("$(location %s)", tools.Value.Includes[0].Label), -1)
-			cmd = strings.Replace(cmd, "$(locations)",
-				fmt.Sprintf("$(locations %s)", tools.Value.Includes[0].Label), -1)
-		}
-
-		// Translate all the other $(location <name>) and $(locations <name>)
-		// expansion placeholders.
-		for _, l := range allReplacements.Includes {
-			bpLoc := fmt.Sprintf("$(location %s)", l.OriginalModuleName)
-			bpLocs := fmt.Sprintf("$(locations %s)", l.OriginalModuleName)
-			bazelLoc := fmt.Sprintf("$(location %s)", l.Label)
-			bazelLocs := fmt.Sprintf("$(locations %s)", l.Label)
-			cmd = strings.Replace(cmd, bpLoc, bazelLoc, -1)
-			cmd = strings.Replace(cmd, bpLocs, bazelLocs, -1)
-		}
-	}
-
-	tags := android.ApexAvailableTags(m)
-
-	// The Output_extension prop is not in an immediately accessible field
-	// in the Module struct, so use GetProperties and cast it
-	// to the known struct prop.
-	var outputFileTemplate string
-	for _, propIntf := range m.GetProperties() {
-		if props, ok := propIntf.(*codegenProperties); ok {
-			// Convert the output path template.
-			outputFileTemplate = proptools.String(props.Output)
-			if len(outputFileTemplate) > 0 {
-				outputFileTemplate = strings.Replace(
-					outputFileTemplate, "$(in)", "$(SRC:BASE)", -1)
-				outputFileTemplate = strings.Replace(
-					outputFileTemplate, "$(in:path/base.ext)", "$(SRC:PATH/BASE.EXT)", -1)
-				outputFileTemplate = strings.Replace(
-					outputFileTemplate, "$(in:path/base)", "$(SRC:PATH/BASE)", -1)
-				outputFileTemplate = strings.Replace(
-					outputFileTemplate, "$(in:base.ext)", "$(SRC:BASE.EXT)", -1)
-				outputFileTemplate = strings.Replace(
-					outputFileTemplate, "$(in:base)", "$(SRC:BASE)", -1)
-			} else {
-				outputFileTemplate = proptools.String(props.Prefix) + "$(SRC:BASE)" +
-					proptools.String(props.Suffix)
-			}
-			break
-		}
-	}
-	props := bazel.BazelTargetModuleProperties{
-		Rule_class:        "gensrcs",
-		Bzl_load_location: "//external/wayland-protocols/bazel:gensrcs.bzl",
-	}
-	attrs := &bazelGensrcsAttributes{
-		Srcs:   srcs,
-		Output: outputFileTemplate,
-		Cmd:    cmd,
-		Tools:  tools,
-	}
-	ctx.CreateBazelTargetModule(props, android.CommonAttributes{
-		Name: m.Name(),
-		Tags: tags,
-	}, attrs)
-}
-
 // Defaults module.
 type Defaults struct {
 	android.ModuleBase
diff --git a/wayland_protocol_codegen_test.go b/wayland_protocol_codegen_test.go
index 90f1200..5285d86 100644
--- a/wayland_protocol_codegen_test.go
+++ b/wayland_protocol_codegen_test.go
@@ -408,31 +408,6 @@
 	}
 }
 
-func TestGenruleWithBazel(t *testing.T) {
-	bp := `
-	    wayland_protocol_codegen {
-				name: "mixed_codegen",
-				srcs: ["src_file"],
-				bazel_module: { label: "//example:bazel_codegen" },
-		}
-	`
-
-	result := android.GroupFixturePreparers(
-		prepareForCodeGenTest, android.FixtureModifyConfig(func(config android.Config) {
-			config.BazelContext = android.MockBazelContext{
-				OutputBaseDir: "outputbase",
-				LabelToOutputFiles: map[string][]string{
-					"//example:bazel_codegen": {"bazelone.txt", "bazeltwo.txt"}}}
-		})).RunTestWithBp(t, testCodeGenBp()+bp)
-
-	gen := result.Module("mixed_codegen", "").(*Module)
-
-	expectedOutputFiles := []string{"outputbase/execroot/__main__/bazelone.txt",
-		"outputbase/execroot/__main__/bazeltwo.txt"}
-	android.AssertDeepEquals(t, "output files", expectedOutputFiles, gen.outputFiles.Strings())
-	android.AssertDeepEquals(t, "output deps", expectedOutputFiles, gen.outputDeps.Strings())
-}
-
 func TestDefaults(t *testing.T) {
 	bp := `
 		wayland_protocol_codegen_defaults {