Loading android/sdk.go +9 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,15 @@ type SnapshotBuilder interface { // will only be used if the equivalently named non-prebuilt module is not // present. AddPrebuiltModule(member SdkMember, moduleType string) BpModule // The property tag to use when adding a property to a BpModule that contains // references to other sdk members. Using this will ensure that the reference // is correctly output for both versioned and unversioned prebuilts in the // snapshot. // // e.g. // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag()) SdkMemberReferencePropertyTag() BpPropertyTag } type BpPropertyTag interface{} Loading java/java.go +10 −8 Original line number Diff line number Diff line Loading @@ -37,14 +37,7 @@ func init() { RegisterJavaBuildComponents(android.InitRegistrationContext) // Register sdk member types. android.RegisterSdkMemberType(&headerLibrarySdkMemberType{ librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_header_libs", SupportsSdk: true, }, }, }) android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) android.RegisterSdkMemberType(&implLibrarySdkMemberType{ librarySdkMemberType{ Loading Loading @@ -1849,6 +1842,15 @@ func (mt *librarySdkMemberType) buildSnapshot( module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) } var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{ librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_header_libs", SupportsSdk: true, }, }, } type headerLibrarySdkMemberType struct { librarySdkMemberType } Loading java/system_modules.go +51 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,15 @@ func init() { RegisterSystemModulesBuildComponents(android.InitRegistrationContext) pctx.SourcePathVariable("moduleInfoJavaPath", "build/soong/scripts/jars-to-module-info-java.sh") // Register sdk member types. android.RegisterSdkMemberType(&systemModulesSdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_system_modules", SupportsSdk: true, TransitiveSdkMembers: true, }, }) } func RegisterSystemModulesBuildComponents(ctx android.RegistrationContext) { Loading Loading @@ -66,6 +75,10 @@ var ( }, }, "classpath", "outDir", "workDir") // Dependency tag that causes the added dependencies to be added as java_header_libs // to the sdk/module_exports/snapshot. systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType) ) func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) { Loading Loading @@ -107,6 +120,7 @@ func SystemModulesFactory() android.Module { type SystemModules struct { android.ModuleBase android.DefaultableModuleBase android.SdkBase properties SystemModulesProperties Loading @@ -125,7 +139,7 @@ type SystemModulesProperties struct { func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { var jars android.Paths ctx.VisitDirectDepsWithTag(libTag, func(module android.Module) { ctx.VisitDirectDepsWithTag(systemModulesLibsTag, func(module android.Module) { dep, _ := module.(Dependency) jars = append(jars, dep.HeaderJars()...) }) Loading @@ -136,7 +150,7 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, libTag, system.properties.Libs...) ctx.AddVariationDependencies(nil, systemModulesLibsTag, system.properties.Libs...) } func (system *SystemModules) AndroidMk() android.AndroidMkData { Loading Loading @@ -173,6 +187,7 @@ func systemModulesImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Libs) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitSdkAwareModule(module) return module } Loading @@ -188,3 +203,37 @@ func (system *systemModulesImport) Name() string { func (system *systemModulesImport) Prebuilt() *android.Prebuilt { return &system.prebuilt } type systemModulesSdkMemberType struct { android.SdkMemberTypeBase } func (mt *systemModulesSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { mctx.AddVariationDependencies(nil, dependencyTag, names...) } func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { if _, ok := module.(*SystemModules); ok { // A prebuilt system module cannot be added as a member of an sdk because the source and // snapshot instances would conflict. _, ok := module.(*systemModulesImport) return !ok } return false } func (mt *systemModulesSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { variants := member.Variants() if len(variants) != 1 { sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) for _, variant := range variants { sdkModuleContext.ModuleErrorf(" %q", variant) } } variant := variants[0] systemModule := variant.(*SystemModules) pbm := builder.AddPrebuiltModule(member, "java_system_modules_import") // Add the references to the libraries that form the system module. pbm.AddPropertyWithTag("libs", systemModule.properties.Libs, builder.SdkMemberReferencePropertyTag()) } sdk/java_sdk_test.go +133 −0 Original line number Diff line number Diff line Loading @@ -583,3 +583,136 @@ module_exports_snapshot { checkMergeZip(".intermediates/myexports/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip"), ) } func TestSnapshotWithJavaSystemModules(t *testing.T) { result := testSdkWithJava(t, ` sdk { name: "mysdk", java_system_modules: ["my-system-modules"], } java_system_modules { name: "my-system-modules", libs: ["system-module"], } java_library { name: "system-module", srcs: ["Test.java"], sdk_version: "none", system_modules: "none", } `) result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { name: "mysdk_system-module@current", sdk_member_name: "system-module", jars: ["java/system-module.jar"], } java_import { name: "system-module", prefer: false, jars: ["java/system-module.jar"], } java_system_modules_import { name: "mysdk_my-system-modules@current", sdk_member_name: "my-system-modules", libs: ["mysdk_system-module@current"], } java_system_modules_import { name: "my-system-modules", prefer: false, libs: ["system-module"], } sdk_snapshot { name: "mysdk@current", java_system_modules: ["mysdk_my-system-modules@current"], } `), checkAllCopyRules(".intermediates/system-module/android_common/turbine-combined/system-module.jar -> java/system-module.jar"), ) } func TestHostSnapshotWithJavaSystemModules(t *testing.T) { // b/145598135 - Generating host snapshots for anything other than linux is not supported. SkipIfNotLinux(t) result := testSdkWithJava(t, ` sdk { name: "mysdk", device_supported: false, host_supported: true, java_system_modules: ["my-system-modules"], } java_system_modules { name: "my-system-modules", device_supported: false, host_supported: true, libs: ["system-module"], } java_library { name: "system-module", device_supported: false, host_supported: true, srcs: ["Test.java"], sdk_version: "none", system_modules: "none", } `) result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { name: "mysdk_system-module@current", sdk_member_name: "system-module", device_supported: false, host_supported: true, jars: ["java/system-module.jar"], } java_import { name: "system-module", prefer: false, device_supported: false, host_supported: true, jars: ["java/system-module.jar"], } java_system_modules_import { name: "mysdk_my-system-modules@current", sdk_member_name: "my-system-modules", device_supported: false, host_supported: true, libs: ["mysdk_system-module@current"], } java_system_modules_import { name: "my-system-modules", prefer: false, device_supported: false, host_supported: true, libs: ["system-module"], } sdk_snapshot { name: "mysdk@current", device_supported: false, host_supported: true, java_system_modules: ["mysdk_my-system-modules@current"], } `), checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"), ) } sdk/testing.go +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr java.RegisterJavaBuildComponents(ctx) java.RegisterAppBuildComponents(ctx) java.RegisterStubsBuildComponents(ctx) java.RegisterSystemModulesBuildComponents(ctx) // from cc package cc.RegisterRequiredBuildComponentsForTest(ctx) Loading Loading
android/sdk.go +9 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,15 @@ type SnapshotBuilder interface { // will only be used if the equivalently named non-prebuilt module is not // present. AddPrebuiltModule(member SdkMember, moduleType string) BpModule // The property tag to use when adding a property to a BpModule that contains // references to other sdk members. Using this will ensure that the reference // is correctly output for both versioned and unversioned prebuilts in the // snapshot. // // e.g. // bpPropertySet.AddPropertyWithTag("libs", []string{"member1", "member2"}, builder.SdkMemberReferencePropertyTag()) SdkMemberReferencePropertyTag() BpPropertyTag } type BpPropertyTag interface{} Loading
java/java.go +10 −8 Original line number Diff line number Diff line Loading @@ -37,14 +37,7 @@ func init() { RegisterJavaBuildComponents(android.InitRegistrationContext) // Register sdk member types. android.RegisterSdkMemberType(&headerLibrarySdkMemberType{ librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_header_libs", SupportsSdk: true, }, }, }) android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) android.RegisterSdkMemberType(&implLibrarySdkMemberType{ librarySdkMemberType{ Loading Loading @@ -1849,6 +1842,15 @@ func (mt *librarySdkMemberType) buildSnapshot( module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) } var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{ librarySdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_header_libs", SupportsSdk: true, }, }, } type headerLibrarySdkMemberType struct { librarySdkMemberType } Loading
java/system_modules.go +51 −2 Original line number Diff line number Diff line Loading @@ -31,6 +31,15 @@ func init() { RegisterSystemModulesBuildComponents(android.InitRegistrationContext) pctx.SourcePathVariable("moduleInfoJavaPath", "build/soong/scripts/jars-to-module-info-java.sh") // Register sdk member types. android.RegisterSdkMemberType(&systemModulesSdkMemberType{ android.SdkMemberTypeBase{ PropertyName: "java_system_modules", SupportsSdk: true, TransitiveSdkMembers: true, }, }) } func RegisterSystemModulesBuildComponents(ctx android.RegistrationContext) { Loading Loading @@ -66,6 +75,10 @@ var ( }, }, "classpath", "outDir", "workDir") // Dependency tag that causes the added dependencies to be added as java_header_libs // to the sdk/module_exports/snapshot. systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType) ) func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) { Loading Loading @@ -107,6 +120,7 @@ func SystemModulesFactory() android.Module { type SystemModules struct { android.ModuleBase android.DefaultableModuleBase android.SdkBase properties SystemModulesProperties Loading @@ -125,7 +139,7 @@ type SystemModulesProperties struct { func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { var jars android.Paths ctx.VisitDirectDepsWithTag(libTag, func(module android.Module) { ctx.VisitDirectDepsWithTag(systemModulesLibsTag, func(module android.Module) { dep, _ := module.(Dependency) jars = append(jars, dep.HeaderJars()...) }) Loading @@ -136,7 +150,7 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddVariationDependencies(nil, libTag, system.properties.Libs...) ctx.AddVariationDependencies(nil, systemModulesLibsTag, system.properties.Libs...) } func (system *SystemModules) AndroidMk() android.AndroidMkData { Loading Loading @@ -173,6 +187,7 @@ func systemModulesImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Libs) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) android.InitSdkAwareModule(module) return module } Loading @@ -188,3 +203,37 @@ func (system *systemModulesImport) Name() string { func (system *systemModulesImport) Prebuilt() *android.Prebuilt { return &system.prebuilt } type systemModulesSdkMemberType struct { android.SdkMemberTypeBase } func (mt *systemModulesSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { mctx.AddVariationDependencies(nil, dependencyTag, names...) } func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { if _, ok := module.(*SystemModules); ok { // A prebuilt system module cannot be added as a member of an sdk because the source and // snapshot instances would conflict. _, ok := module.(*systemModulesImport) return !ok } return false } func (mt *systemModulesSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { variants := member.Variants() if len(variants) != 1 { sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) for _, variant := range variants { sdkModuleContext.ModuleErrorf(" %q", variant) } } variant := variants[0] systemModule := variant.(*SystemModules) pbm := builder.AddPrebuiltModule(member, "java_system_modules_import") // Add the references to the libraries that form the system module. pbm.AddPropertyWithTag("libs", systemModule.properties.Libs, builder.SdkMemberReferencePropertyTag()) }
sdk/java_sdk_test.go +133 −0 Original line number Diff line number Diff line Loading @@ -583,3 +583,136 @@ module_exports_snapshot { checkMergeZip(".intermediates/myexports/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip"), ) } func TestSnapshotWithJavaSystemModules(t *testing.T) { result := testSdkWithJava(t, ` sdk { name: "mysdk", java_system_modules: ["my-system-modules"], } java_system_modules { name: "my-system-modules", libs: ["system-module"], } java_library { name: "system-module", srcs: ["Test.java"], sdk_version: "none", system_modules: "none", } `) result.CheckSnapshot("mysdk", "android_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { name: "mysdk_system-module@current", sdk_member_name: "system-module", jars: ["java/system-module.jar"], } java_import { name: "system-module", prefer: false, jars: ["java/system-module.jar"], } java_system_modules_import { name: "mysdk_my-system-modules@current", sdk_member_name: "my-system-modules", libs: ["mysdk_system-module@current"], } java_system_modules_import { name: "my-system-modules", prefer: false, libs: ["system-module"], } sdk_snapshot { name: "mysdk@current", java_system_modules: ["mysdk_my-system-modules@current"], } `), checkAllCopyRules(".intermediates/system-module/android_common/turbine-combined/system-module.jar -> java/system-module.jar"), ) } func TestHostSnapshotWithJavaSystemModules(t *testing.T) { // b/145598135 - Generating host snapshots for anything other than linux is not supported. SkipIfNotLinux(t) result := testSdkWithJava(t, ` sdk { name: "mysdk", device_supported: false, host_supported: true, java_system_modules: ["my-system-modules"], } java_system_modules { name: "my-system-modules", device_supported: false, host_supported: true, libs: ["system-module"], } java_library { name: "system-module", device_supported: false, host_supported: true, srcs: ["Test.java"], sdk_version: "none", system_modules: "none", } `) result.CheckSnapshot("mysdk", "linux_glibc_common", "", checkAndroidBpContents(` // This is auto-generated. DO NOT EDIT. java_import { name: "mysdk_system-module@current", sdk_member_name: "system-module", device_supported: false, host_supported: true, jars: ["java/system-module.jar"], } java_import { name: "system-module", prefer: false, device_supported: false, host_supported: true, jars: ["java/system-module.jar"], } java_system_modules_import { name: "mysdk_my-system-modules@current", sdk_member_name: "my-system-modules", device_supported: false, host_supported: true, libs: ["mysdk_system-module@current"], } java_system_modules_import { name: "my-system-modules", prefer: false, device_supported: false, host_supported: true, libs: ["system-module"], } sdk_snapshot { name: "mysdk@current", device_supported: false, host_supported: true, java_system_modules: ["mysdk_my-system-modules@current"], } `), checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"), ) }
sdk/testing.go +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ func testSdkContext(bp string, fs map[string][]byte) (*android.TestContext, andr java.RegisterJavaBuildComponents(ctx) java.RegisterAppBuildComponents(ctx) java.RegisterStubsBuildComponents(ctx) java.RegisterSystemModulesBuildComponents(ctx) // from cc package cc.RegisterRequiredBuildComponentsForTest(ctx) Loading