diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 20421defd..5d985067a 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -61,8 +61,14 @@ func (b bootclasspathFragmentContentDependencyTag) ReplaceSourceWithPrebuilt() b } // SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if -// they were specified using java_boot_libs. -func (b bootclasspathFragmentContentDependencyTag) SdkMemberType(_ android.Module) android.SdkMemberType { +// they were specified using java_boot_libs or java_sdk_libs. +func (b bootclasspathFragmentContentDependencyTag) 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_boot_libs property. + if javaSdkLibrarySdkMemberType.IsInstance(child) { + return javaSdkLibrarySdkMemberType + } + return javaBootLibsSdkMemberType } diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index f18e69783..cc9a66db0 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -165,21 +165,33 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { prepareForSdkTestWithJava, java.PrepareForTestWithJavaDefaultModules, java.PrepareForTestWithJavaSdkLibraryFiles, - java.FixtureWithLastReleaseApis("mysdklibrary", "mycoreplatform"), + java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"), android.FixtureWithRootAndroidBp(` sdk { name: "mysdk", bootclasspath_fragments: ["mybootclasspathfragment"], - java_sdk_libs: ["mysdklibrary", "mycoreplatform"], + 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 mybootclasspathfragment's + // api.stub_libs property. However, it is specified here to ensure that duplicates are + // correctly deduped. + "mysdklibrary", + ], } bootclasspath_fragment { name: "mybootclasspathfragment", - contents: ["mybootlib"], + contents: [ + // This should be automatically added to the sdk_snapshot as a java_boot_libs module. + "mybootlib", + // This should be automatically added to the sdk_snapshot as a java_sdk_libs module. + "myothersdklibrary", + ], api: { stub_libs: ["mysdklibrary"], }, core_platform_api: { + // This should be automatically added to the sdk_snapshot as a java_sdk_libs module. stub_libs: ["mycoreplatform"], }, } @@ -199,6 +211,13 @@ func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { public: {enabled: true}, } + java_sdk_library { + name: "myothersdklibrary", + srcs: ["Test.java"], + compile_dex: true, + public: {enabled: true}, + } + java_sdk_library { name: "mycoreplatform", srcs: ["Test.java"], @@ -217,7 +236,10 @@ prebuilt_bootclasspath_fragment { prefer: false, visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], - contents: ["mybootlib"], + contents: [ + "mybootlib", + "myothersdklibrary", + ], api: { stub_libs: ["mysdklibrary"], }, @@ -234,6 +256,22 @@ java_import { jars: ["java/mybootlib.jar"], } +java_sdk_library_import { + name: "myothersdklibrary", + prefer: false, + visibility: ["//visibility:public"], + apex_available: ["//apex_available:platform"], + shared_library: true, + compile_dex: true, + public: { + jars: ["sdk_library/public/myothersdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"], + current_api: "sdk_library/public/myothersdklibrary.txt", + removed_api: "sdk_library/public/myothersdklibrary-removed.txt", + sdk_version: "current", + }, +} + java_sdk_library_import { name: "mysdklibrary", prefer: false, @@ -265,7 +303,7 @@ java_sdk_library_import { sdk_version: "current", }, } -`), + `), checkVersionedAndroidBpContents(` // This is auto-generated. DO NOT EDIT. @@ -274,7 +312,10 @@ prebuilt_bootclasspath_fragment { sdk_member_name: "mybootclasspathfragment", visibility: ["//visibility:public"], apex_available: ["//apex_available:platform"], - contents: ["mysdk_mybootlib@current"], + contents: [ + "mysdk_mybootlib@current", + "mysdk_myothersdklibrary@current", + ], api: { stub_libs: ["mysdk_mysdklibrary@current"], }, @@ -291,6 +332,22 @@ java_import { jars: ["java/mybootlib.jar"], } +java_sdk_library_import { + name: "mysdk_myothersdklibrary@current", + sdk_member_name: "myothersdklibrary", + visibility: ["//visibility:public"], + apex_available: ["//apex_available:platform"], + shared_library: true, + compile_dex: true, + public: { + jars: ["sdk_library/public/myothersdklibrary-stubs.jar"], + stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"], + current_api: "sdk_library/public/myothersdklibrary.txt", + removed_api: "sdk_library/public/myothersdklibrary-removed.txt", + sdk_version: "current", + }, +} + java_sdk_library_import { name: "mysdk_mysdklibrary@current", sdk_member_name: "mysdklibrary", @@ -329,13 +386,17 @@ sdk_snapshot { bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], java_boot_libs: ["mysdk_mybootlib@current"], java_sdk_libs: [ + "mysdk_myothersdklibrary@current", "mysdk_mysdklibrary@current", "mysdk_mycoreplatform@current", ], } -`), + `), checkAllCopyRules(` .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar +.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt +.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt