Merge "Add limited bp2build converter of java_sdk_library" am: c451830446
am: 2da9f46ee8
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2411046 Change-Id: I0a3260a2708993aa56b3823dae5d474155a05759 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -686,12 +686,13 @@ var (
|
|||||||
|
|
||||||
Bp2buildModuleTypeAlwaysConvertList = []string{
|
Bp2buildModuleTypeAlwaysConvertList = []string{
|
||||||
"aidl_interface_headers",
|
"aidl_interface_headers",
|
||||||
|
"bpf",
|
||||||
"license",
|
"license",
|
||||||
"linker_config",
|
"linker_config",
|
||||||
"java_import",
|
"java_import",
|
||||||
"java_import_host",
|
"java_import_host",
|
||||||
|
"java_sdk_library",
|
||||||
"sysprop_library",
|
"sysprop_library",
|
||||||
"bpf",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the names of modules that bp2build should never convert, if it is
|
// Add the names of modules that bp2build should never convert, if it is
|
||||||
|
148
bp2build/java_sdk_library_conversion_test.go
Normal file
148
bp2build/java_sdk_library_conversion_test.go
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
// Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/java"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t *testing.T, tc Bp2buildTestCase, registrationCtxFunc func(ctx android.RegistrationContext)) {
|
||||||
|
t.Helper()
|
||||||
|
(&tc).ModuleTypeUnderTest = "java_sdk_library"
|
||||||
|
(&tc).ModuleTypeUnderTestFactory = java.SdkLibraryFactory
|
||||||
|
RunBp2BuildTestCase(t, registrationCtxFunc, tc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runJavaSdkLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||||
|
t.Helper()
|
||||||
|
runJavaSdkLibraryTestCaseWithRegistrationCtxFunc(t, tc, func(ctx android.RegistrationContext) {})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibraryApiSurfaceGeneral(t *testing.T) {
|
||||||
|
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "limited java_sdk_library for api surfaces, general conversion",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||||
|
"api/current.txt": "",
|
||||||
|
"api/system-current.txt": "",
|
||||||
|
"api/test-current.txt": "",
|
||||||
|
"api/module-lib-current.txt": "",
|
||||||
|
"api/system-server-current.txt": "",
|
||||||
|
"api/removed.txt": "",
|
||||||
|
"api/system-removed.txt": "",
|
||||||
|
"api/test-removed.txt": "",
|
||||||
|
"api/module-lib-removed.txt": "",
|
||||||
|
"api/system-server-removed.txt": "",
|
||||||
|
},
|
||||||
|
Blueprint: `java_sdk_library {
|
||||||
|
name: "java-sdk-lib",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
public: {enabled: true},
|
||||||
|
system: {enabled: true},
|
||||||
|
test: {enabled: true},
|
||||||
|
module_lib: {enabled: true},
|
||||||
|
system_server: {enabled: true},
|
||||||
|
}`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||||
|
"public": `"api/current.txt"`,
|
||||||
|
"system": `"api/system-current.txt"`,
|
||||||
|
"test": `"api/test-current.txt"`,
|
||||||
|
"module_lib": `"api/module-lib-current.txt"`,
|
||||||
|
"system_server": `"api/system-server-current.txt"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibraryApiSurfacePublicDefault(t *testing.T) {
|
||||||
|
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "limited java_sdk_library for api surfaces, public prop uses default value",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||||
|
"api/current.txt": "",
|
||||||
|
"api/system-current.txt": "",
|
||||||
|
"api/test-current.txt": "",
|
||||||
|
"api/module-lib-current.txt": "",
|
||||||
|
"api/system-server-current.txt": "",
|
||||||
|
"api/removed.txt": "",
|
||||||
|
"api/system-removed.txt": "",
|
||||||
|
"api/test-removed.txt": "",
|
||||||
|
"api/module-lib-removed.txt": "",
|
||||||
|
"api/system-server-removed.txt": "",
|
||||||
|
},
|
||||||
|
Blueprint: `java_sdk_library {
|
||||||
|
name: "java-sdk-lib",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
system: {enabled: false},
|
||||||
|
test: {enabled: false},
|
||||||
|
module_lib: {enabled: false},
|
||||||
|
system_server: {enabled: false},
|
||||||
|
}`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||||
|
"public": `"api/current.txt"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibraryApiSurfacePublicNotEnabled(t *testing.T) {
|
||||||
|
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "limited java_sdk_library for api surfaces, public enable is false",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||||
|
"api/current.txt": "",
|
||||||
|
"api/removed.txt": "",
|
||||||
|
},
|
||||||
|
Blueprint: `java_sdk_library {
|
||||||
|
name: "java-sdk-lib",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
public: {enabled: false},
|
||||||
|
}`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaSdkLibraryApiSurfaceNoScopeIsSet(t *testing.T) {
|
||||||
|
runJavaSdkLibraryTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "limited java_sdk_library for api surfaces, none of the api scopes is set",
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"build/soong/scripts/gen-java-current-api-files.sh": "",
|
||||||
|
"api/current.txt": "",
|
||||||
|
"api/system-current.txt": "",
|
||||||
|
"api/test-current.txt": "",
|
||||||
|
"api/removed.txt": "",
|
||||||
|
"api/system-removed.txt": "",
|
||||||
|
"api/test-removed.txt": "",
|
||||||
|
},
|
||||||
|
Blueprint: `java_sdk_library {
|
||||||
|
name: "java-sdk-lib",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
}`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
MakeBazelTarget("java_sdk_library", "java-sdk-lib", AttrNameToString{
|
||||||
|
"public": `"api/current.txt"`,
|
||||||
|
"system": `"api/system-current.txt"`,
|
||||||
|
"test": `"api/test-current.txt"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"android/soong/bazel"
|
||||||
"android/soong/dexpreopt"
|
"android/soong/dexpreopt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -546,14 +547,14 @@ type sdkLibraryProperties struct {
|
|||||||
|
|
||||||
// The properties specific to the module-lib api scope
|
// The properties specific to the module-lib api scope
|
||||||
//
|
//
|
||||||
// Unless explicitly specified by using test.enabled the module-lib api scope is
|
// Unless explicitly specified by using module_lib.enabled the module_lib api
|
||||||
// disabled by default.
|
// scope is disabled by default.
|
||||||
Module_lib ApiScopeProperties
|
Module_lib ApiScopeProperties
|
||||||
|
|
||||||
// The properties specific to the system-server api scope
|
// The properties specific to the system-server api scope
|
||||||
//
|
//
|
||||||
// Unless explicitly specified by using test.enabled the module-lib api scope is
|
// Unless explicitly specified by using system_server.enabled the
|
||||||
// disabled by default.
|
// system_server api scope is disabled by default.
|
||||||
System_server ApiScopeProperties
|
System_server ApiScopeProperties
|
||||||
|
|
||||||
// Determines if the stubs are preferred over the implementation library
|
// Determines if the stubs are preferred over the implementation library
|
||||||
@@ -1163,6 +1164,8 @@ type SdkLibraryDependency interface {
|
|||||||
type SdkLibrary struct {
|
type SdkLibrary struct {
|
||||||
Library
|
Library
|
||||||
|
|
||||||
|
android.BazelModuleBase
|
||||||
|
|
||||||
sdkLibraryProperties sdkLibraryProperties
|
sdkLibraryProperties sdkLibraryProperties
|
||||||
|
|
||||||
// Map from api scope to the scope specific property structure.
|
// Map from api scope to the scope specific property structure.
|
||||||
@@ -2081,9 +2084,48 @@ func SdkLibraryFactory() android.Module {
|
|||||||
module.CreateInternalModules(ctx)
|
module.CreateInternalModules(ctx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
android.InitBazelModule(module)
|
||||||
return 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
|
// SDK library prebuilts
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user