Add "exported" mode to xx_aconfig_library build rules

Test: added unit tests and CI

Bug: 309990433
Change-Id: Iae1b85265d9780bde7d41ec2ec6e8e441c2b3814
This commit is contained in:
Zi Wang
2023-11-09 14:59:31 -08:00
parent 3a35d64915
commit 275f654a2e
6 changed files with 238 additions and 19 deletions

View File

@@ -30,12 +30,21 @@ type declarationsTagType struct {
var declarationsTag = declarationsTagType{}
var aconfigSupportedModes = []string{"production", "test", "exported"}
type JavaAconfigDeclarationsLibraryProperties struct {
// name of the aconfig_declarations module to generate a library for
Aconfig_declarations string
// whether to generate test mode version of the library
// TODO: remove "Test" property when "Mode" can be used in all the branches
Test *bool
// default mode is "production", the other accepted modes are:
// "test": to generate test mode version of the library
// "exported": to generate exported mode version of the library
// an error will be thrown if the mode is not supported
Mode *string
}
type JavaAconfigDeclarationsLibraryCallbacks struct {
@@ -72,12 +81,19 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild
// Generate the action to build the srcjar
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
var mode string
if callbacks.properties.Mode != nil && callbacks.properties.Test != nil {
ctx.PropertyErrorf("test", "test prop should not be specified when mode prop is set")
}
mode := proptools.StringDefault(callbacks.properties.Mode, "production")
if !isModeSupported(mode) {
ctx.PropertyErrorf("mode", "%q is not a supported mode", mode)
}
// TODO: remove "Test" property
if proptools.Bool(callbacks.properties.Test) {
mode = "test"
} else {
mode = "production"
}
ctx.Build(pctx, android.BuildParams{
Rule: javaRule,
Input: declarations.IntermediatePath,
@@ -95,9 +111,12 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild
return srcJarPath
}
func isModeSupported(mode string) bool {
return android.InList(mode, aconfigSupportedModes)
}
type bazelJavaAconfigLibraryAttributes struct {
Aconfig_declarations bazel.LabelAttribute
Test *bool
Sdk_version *string
Libs bazel.LabelListAttribute
}
@@ -138,7 +157,6 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) Bp2build(ctx android.B
attrs := bazelJavaAconfigLibraryAttributes{
Aconfig_declarations: *bazel.MakeLabelAttribute(android.BazelLabelForModuleDepSingle(ctx, callbacks.properties.Aconfig_declarations).Label),
Test: callbacks.properties.Test,
Sdk_version: &sdkVersion,
Libs: libs,
}