Add minimal bp2build converter for combined apis

4 merged_txts targets will be generated for a combined_api target

Test: api_conversion_test.go and TH

Bug: 267600251
Change-Id: I8ec4a1073538c394a7eef896d8f6e354986fa2cd
diff --git a/api/api.go b/api/api.go
index 077ab96..25d9728 100644
--- a/api/api.go
+++ b/api/api.go
@@ -20,6 +20,7 @@
 	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
+	"android/soong/bazel"
 	"android/soong/genrule"
 	"android/soong/java"
 )
@@ -30,6 +31,7 @@
 const virtualization = "framework-virtualization"
 
 var core_libraries_modules = []string{art, conscrypt, i18n}
+
 // List of modules that are not yet updatable, and hence they can still compile
 // against hidden APIs. These modules are filtered out when building the
 // updatable-framework-module-impl (because updatable-framework-module-impl is
@@ -59,6 +61,7 @@
 
 type CombinedApis struct {
 	android.ModuleBase
+	android.BazelModuleBase
 
 	properties CombinedApisProperties
 }
@@ -99,6 +102,19 @@
 	Visibility []string
 }
 
+type Bazel_module struct {
+	Bp2build_available *bool
+}
+type bazelProperties struct {
+	*Bazel_module
+}
+
+var bp2buildNotAvailable = bazelProperties{
+	&Bazel_module{
+		Bp2build_available: proptools.BoolPtr(false),
+	},
+}
+
 // Struct to pass parameters for the various merged [current|removed].txt file modules we create.
 type MergedTxtDefinition struct {
 	// "current.txt" or "removed.txt"
@@ -144,7 +160,7 @@
 		},
 	}
 	props.Visibility = []string{"//visibility:public"}
-	ctx.CreateModule(genrule.GenRuleFactory, &props)
+	ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable)
 }
 
 func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) {
@@ -174,7 +190,7 @@
 		props := fgProps{}
 		props.Name = proptools.StringPtr(i.name)
 		props.Srcs = createSrcs(i.modules, i.tag)
-		ctx.CreateModule(android.FileGroupFactory, &props)
+		ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
 	}
 }
 
@@ -223,7 +239,7 @@
 		props.Tools = []string{"api_versions_trimmer"}
 		props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)")
 		props.Dists = []android.Dist{{Targets: []string{"sdk"}}}
-		ctx.CreateModule(genrule.GenRuleFactory, &props)
+		ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable)
 	}
 }
 
@@ -315,7 +331,7 @@
 	props.Name = proptools.StringPtr("all-modules-public-stubs-source")
 	props.Srcs = createSrcs(modules, "{.public.stubs.source}")
 	props.Visibility = []string{"//frameworks/base"}
-	ctx.CreateModule(android.FileGroupFactory, &props)
+	ctx.CreateModule(android.FileGroupFactory, &props, &bp2buildNotAvailable)
 }
 
 func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) {
@@ -389,9 +405,57 @@
 	module.AddProperties(&module.properties)
 	android.InitAndroidModule(module)
 	android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) })
+	android.InitBazelModule(module)
 	return module
 }
 
+type bazelCombinedApisAttributes struct {
+	Scope bazel.StringAttribute
+	Base  bazel.LabelAttribute
+	Deps  bazel.LabelListAttribute
+}
+
+// combined_apis bp2build converter
+func (a *CombinedApis) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+	basePrefix := "non-updatable"
+	scopeNames := []string{"public", "system", "module-lib", "system-server"}
+	scopeToSuffix := map[string]string{
+		"public":        "-current.txt",
+		"system":        "-system-current.txt",
+		"module-lib":    "-module-lib-current.txt",
+		"system-server": "-system-server-current.txt",
+	}
+
+	for _, scopeName := range scopeNames{
+		suffix := scopeToSuffix[scopeName]
+		name := a.Name() + suffix
+
+		var scope bazel.StringAttribute
+		scope.SetValue(scopeName)
+
+		var base bazel.LabelAttribute
+		base.SetValue(android.BazelLabelForModuleDepSingle(ctx, basePrefix+suffix))
+
+		var deps bazel.LabelListAttribute
+		classpath := a.properties.Bootclasspath
+		if scopeName == "system-server" {
+			classpath = a.properties.System_server_classpath
+		}
+		deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, classpath))
+
+		attrs := bazelCombinedApisAttributes{
+			Scope: scope,
+			Base:  base,
+			Deps:  deps,
+		}
+		props := bazel.BazelTargetModuleProperties{
+			Rule_class:        "merged_txts",
+			Bzl_load_location: "//build/bazel/rules/java:merged_txts.bzl",
+		}
+		ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, &attrs)
+	}
+}
+
 // Various utility methods below.
 
 // Creates an array of ":<m><tag>" for each m in <modules>.