Generate prebuilt_systemserverclasspath_fragment.

Bug: 194150908
Test: m nothing
Test: manual - 1. Patch aosp/1835087.
  2. m out/soong/.intermediates/art/build/sdk/art-module-sdk/common_os/snapshot/Android.bp
  3. See prebuilt_systemserverclasspath_fragment modules and
     systemserverclasspath_fragments in an sdk_snapshot module.
Change-Id: I7876b077b0b4ed190f01dbfa9533de04ea32d524
This commit is contained in:
Jiakai Zhang 2021-09-26 09:02:17 +00:00
parent ea18033f31
commit a8d8660ab1
3 changed files with 246 additions and 1 deletions

View file

@ -23,6 +23,13 @@ import (
func init() {
registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
android.RegisterSdkMemberType(&systemServerClasspathFragmentMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
PropertyName: "systemserverclasspath_fragments",
SupportsSdk: true,
},
})
}
func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
@ -62,6 +69,7 @@ func (p *platformSystemServerClasspathModule) configuredJars(ctx android.ModuleC
type SystemServerClasspathModule struct {
android.ModuleBase
android.ApexModuleBase
android.SdkBase
ClasspathFragmentBase
@ -86,6 +94,7 @@ func systemServerClasspathFactory() android.Module {
m := &SystemServerClasspathModule{}
m.AddProperties(&m.properties)
android.InitApexModule(m)
android.InitSdkAwareModule(m)
initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
return m
@ -113,7 +122,7 @@ func (s *SystemServerClasspathModule) configuredJars(ctx android.ModuleContext)
_, unknown = android.RemoveFromList("geotz", unknown)
// For non test apexes, make sure that all contents are actually declared in make.
if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS", unknown)
}
@ -129,6 +138,22 @@ func (systemServerClasspathFragmentContentDependencyTag) ReplaceSourceWithPrebui
return false
}
// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
// they were specified using java_systemserver_libs or java_sdk_libs.
func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
// If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
// property, otherwise treat if it was specified in the java_systemserver_libs property.
if javaSdkLibrarySdkMemberType.IsInstance(child) {
return javaSdkLibrarySdkMemberType
}
return javaSystemserverLibsSdkMemberType
}
func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
return true
}
// Contents of system server fragments in an apex are considered to be directly in the apex, as if
// they were listed in java_libs.
func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
@ -137,6 +162,7 @@ func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex()
func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
@ -167,6 +193,51 @@ func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) {
dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
}
type systemServerClasspathFragmentMemberType struct {
android.SdkMemberTypeBase
}
func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
ctx.AddVariationDependencies(nil, dependencyTag, names...)
}
func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
_, ok := module.(*SystemServerClasspathModule)
return ok
}
func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
}
func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
return &systemServerClasspathFragmentSdkMemberProperties{}
}
type systemServerClasspathFragmentSdkMemberProperties struct {
android.SdkMemberPropertiesBase
// Contents of the systemserverclasspath fragment
Contents []string
}
func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
module := variant.(*SystemServerClasspathModule)
s.Contents = module.properties.Contents
}
func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
builder := ctx.SnapshotBuilder()
requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
if len(s.Contents) > 0 {
propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
}
}
var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
// A prebuilt version of the systemserverclasspath_fragment module.
type prebuiltSystemServerClasspathModule struct {
SystemServerClasspathModule
@ -194,6 +265,7 @@ func prebuiltSystemServerClasspathModuleFactory() android.Module {
// array.
android.InitPrebuiltModule(m, &[]string{"placeholder"})
android.InitApexModule(m)
android.InitSdkAwareModule(m)
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
return m
}

View file

@ -11,6 +11,7 @@ bootstrap_go_package {
"soong-android",
"soong-apex",
"soong-cc",
"soong-dexpreopt",
"soong-java",
],
srcs: [
@ -31,6 +32,7 @@ bootstrap_go_package {
"license_sdk_test.go",
"member_trait_test.go",
"sdk_test.go",
"systemserverclasspath_fragment_sdk_test.go",
"testing.go",
],
pluginFor: ["soong_build"],

View file

@ -0,0 +1,171 @@
// Copyright (C) 2021 The Android Open Source Project
//
// 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 sdk
import (
"testing"
"android/soong/android"
"android/soong/dexpreopt"
"android/soong/java"
)
func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
java.PrepareForTestWithJavaDefaultModules,
java.PrepareForTestWithJavaSdkLibraryFiles,
java.FixtureWithLastReleaseApis("mysdklibrary"),
dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
prepareForSdkTestWithApex,
android.FixtureWithRootAndroidBp(`
sdk {
name: "mysdk",
systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
java_sdk_libs: [
// This is not strictly needed as it should be automatically added to the sdk_snapshot as
// a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's
// contents property. However, it is specified here to ensure that duplicates are
// correctly deduped.
"mysdklibrary",
],
}
apex {
name: "myapex",
key: "myapex.key",
min_sdk_version: "2",
systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
}
systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
apex_available: ["myapex"],
contents: [
"mylib",
"mysdklibrary",
],
}
java_library {
name: "mylib",
apex_available: ["myapex"],
srcs: ["Test.java"],
system_modules: "none",
sdk_version: "none",
min_sdk_version: "2",
compile_dex: true,
permitted_packages: ["mylib"],
}
java_sdk_library {
name: "mysdklibrary",
apex_available: ["myapex"],
srcs: ["Test.java"],
shared_library: false,
public: {enabled: true},
min_sdk_version: "2",
}
`),
).RunTest(t)
CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
name: "mysdklibrary",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
shared_library: false,
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
current_api: "sdk_library/public/mysdklibrary.txt",
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
sdk_version: "current",
},
}
java_import {
name: "mylib",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
permitted_packages: ["mylib"],
}
prebuilt_systemserverclasspath_fragment {
name: "mysystemserverclasspathfragment",
prefer: false,
visibility: ["//visibility:public"],
apex_available: ["myapex"],
contents: [
"mylib",
"mysdklibrary",
],
}
`),
checkVersionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
name: "mysdk_mysdklibrary@current",
sdk_member_name: "mysdklibrary",
visibility: ["//visibility:public"],
apex_available: ["myapex"],
shared_library: false,
public: {
jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
current_api: "sdk_library/public/mysdklibrary.txt",
removed_api: "sdk_library/public/mysdklibrary-removed.txt",
sdk_version: "current",
},
}
java_import {
name: "mysdk_mylib@current",
sdk_member_name: "mylib",
visibility: ["//visibility:public"],
apex_available: ["myapex"],
jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
permitted_packages: ["mylib"],
}
prebuilt_systemserverclasspath_fragment {
name: "mysdk_mysystemserverclasspathfragment@current",
sdk_member_name: "mysystemserverclasspathfragment",
visibility: ["//visibility:public"],
apex_available: ["myapex"],
contents: [
"mysdk_mylib@current",
"mysdk_mysdklibrary@current",
],
}
sdk_snapshot {
name: "mysdk@current",
visibility: ["//visibility:public"],
java_sdk_libs: ["mysdk_mysdklibrary@current"],
java_systemserver_libs: ["mysdk_mylib@current"],
systemserverclasspath_fragments: ["mysdk_mysystemserverclasspathfragment@current"],
}
`),
)
}