Add limited bp2build converter of java_sdk_library

Only public, system, test, module_lib and system_server are
converted in order to generate api_fingerprint.txt in Bazel.

Test: java_sdk_library_conversion_test.go and TH

Bug: 266973526
Change-Id: I67a00806165e5afad3876b6cd5cdbc6b0dd65d8b
This commit is contained in:
Zi Wang
2023-01-31 15:53:30 -08:00
parent 0620c7c56a
commit b2179e397a
3 changed files with 196 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/bazel"
"android/soong/dexpreopt"
)
@@ -546,14 +547,14 @@ type sdkLibraryProperties struct {
// The properties specific to the module-lib api scope
//
// Unless explicitly specified by using test.enabled the module-lib api scope is
// disabled by default.
// Unless explicitly specified by using module_lib.enabled the module_lib api
// scope is disabled by default.
Module_lib ApiScopeProperties
// The properties specific to the system-server api scope
//
// Unless explicitly specified by using test.enabled the module-lib api scope is
// disabled by default.
// Unless explicitly specified by using system_server.enabled the
// system_server api scope is disabled by default.
System_server ApiScopeProperties
// Determines if the stubs are preferred over the implementation library
@@ -1163,6 +1164,8 @@ type SdkLibraryDependency interface {
type SdkLibrary struct {
Library
android.BazelModuleBase
sdkLibraryProperties sdkLibraryProperties
// Map from api scope to the scope specific property structure.
@@ -2081,9 +2084,48 @@ func SdkLibraryFactory() android.Module {
module.CreateInternalModules(ctx)
}
})
android.InitBazelModule(module)
return module
}
type bazelSdkLibraryAttributes struct {
Public bazel.StringAttribute
System bazel.StringAttribute
Test bazel.StringAttribute
Module_lib bazel.StringAttribute
System_server bazel.StringAttribute
}
// java_sdk_library bp2build converter
func (module *SdkLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
if ctx.ModuleType() != "java_sdk_library" {
return
}
nameToAttr := make(map[string]bazel.StringAttribute)
for _, scope := range module.getGeneratedApiScopes(ctx) {
apiSurfaceFile := path.Join(module.getApiDir(), scope.apiFilePrefix+"current.txt")
var scopeStringAttribute bazel.StringAttribute
scopeStringAttribute.SetValue(apiSurfaceFile)
nameToAttr[scope.name] = scopeStringAttribute
}
attrs := bazelSdkLibraryAttributes{
Public: nameToAttr["public"],
System: nameToAttr["system"],
Test: nameToAttr["test"],
Module_lib: nameToAttr["module-lib"],
System_server: nameToAttr["system-server"],
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_sdk_library",
Bzl_load_location: "//build/bazel/rules/java:sdk_library.bzl",
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs)
}
//
// SDK library prebuilts
//