Support aconfig_declarations, aconfig_values and aconfig_value_set

Bug: 297356603
Test: Unit tests
Change-Id: I2f797578a35322440db0f281b4d46b6652512e00
diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go
index 5cdf5b6..ed0961b 100644
--- a/aconfig/aconfig_declarations.go
+++ b/aconfig/aconfig_declarations.go
@@ -15,16 +15,18 @@
 package aconfig
 
 import (
-	"android/soong/android"
 	"fmt"
 	"strings"
 
+	"android/soong/android"
+	"android/soong/bazel"
 	"github.com/google/blueprint"
 )
 
 type DeclarationsModule struct {
 	android.ModuleBase
 	android.DefaultableModuleBase
+	android.BazelModuleBase
 
 	// Properties for "aconfig_declarations"
 	properties struct {
@@ -47,8 +49,7 @@
 	android.InitAndroidModule(module)
 	android.InitDefaultableModule(module)
 	module.AddProperties(&module.properties)
-	// TODO: bp2build
-	//android.InitBazelModule(module)
+	android.InitBazelModule(module)
 
 	return module
 }
@@ -73,7 +74,9 @@
 	// RELEASE_ACONFIG_VALUE_SETS, and add any aconfig_values that
 	// match our package.
 	valuesFromConfig := ctx.Config().ReleaseAconfigValueSets()
-	ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig...)
+	if valuesFromConfig != "" {
+		ctx.AddDependency(ctx.Module(), implicitValuesTag, valuesFromConfig)
+	}
 }
 
 func (module *DeclarationsModule) OutputFiles(tag string) (android.Paths, error) {
@@ -159,3 +162,26 @@
 	})
 
 }
+
+type bazelAconfigDeclarationsAttributes struct {
+	Srcs    bazel.LabelListAttribute
+	Package string
+}
+
+func (module *DeclarationsModule) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
+	if ctx.ModuleType() != "aconfig_declarations" {
+		return
+	}
+	srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs))
+
+	attrs := bazelAconfigDeclarationsAttributes{
+		Srcs:    srcs,
+		Package: module.properties.Package,
+	}
+	props := bazel.BazelTargetModuleProperties{
+		Rule_class:        "aconfig_declarations",
+		Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_declarations.bzl",
+	}
+
+	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
+}