From 780c5f4715d402b4faddef336d456e39cfae9db1 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 12 May 2020 15:52:55 +0100 Subject: [PATCH] java_sdk_library: Preserve sdk_version: "none" in snapshot Test: m nothing Bug: 156354511 Change-Id: Icf7c20dc109a773430768c1a2d91c674551dbc1b --- java/sdk_library.go | 4 +-- sdk/java_sdk_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/java/sdk_library.go b/java/sdk_library.go index 2c85c8c09..59ff1254b 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -561,7 +561,7 @@ func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { } // Get the sdk version for use when compiling the stubs library. -func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) string { +func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) if sdkDep.hasStandardLibs() { // If building against a standard sdk then use the sdk version appropriate for the scope. @@ -1412,7 +1412,7 @@ func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMembe if len(jars) > 0 { properties := scopeProperties{} properties.Jars = jars - properties.SdkVersion = apiScope.sdkVersion + properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) properties.StubsSrcJar = paths.stubsSrcJar properties.CurrentApiFile = paths.currentApiFilePath properties.RemovedApiFile = paths.removedApiFilePath diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go index 560a6b856..bb5cbbe92 100644 --- a/sdk/java_sdk_test.go +++ b/sdk/java_sdk_test.go @@ -1075,6 +1075,65 @@ sdk_snapshot { ) } +func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) { + result := testSdkWithJava(t, ` + sdk { + name: "mysdk", + java_sdk_libs: ["myjavalib"], + } + + java_sdk_library { + name: "myjavalib", + srcs: ["Test.java"], + sdk_version: "none", + system_modules: "none", + } + `) + + result.CheckSnapshot("mysdk", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +java_sdk_library_import { + name: "mysdk_myjavalib@current", + sdk_member_name: "myjavalib", + public: { + jars: ["sdk_library/public/myjavalib-stubs.jar"], + stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], + current_api: "sdk_library/public/myjavalib.txt", + removed_api: "sdk_library/public/myjavalib-removed.txt", + sdk_version: "none", + }, +} + +java_sdk_library_import { + name: "myjavalib", + prefer: false, + public: { + jars: ["sdk_library/public/myjavalib-stubs.jar"], + stub_srcs: ["sdk_library/public/myjavalib_stub_sources"], + current_api: "sdk_library/public/myjavalib.txt", + removed_api: "sdk_library/public/myjavalib-removed.txt", + sdk_version: "none", + }, +} + +sdk_snapshot { + name: "mysdk@current", + java_sdk_libs: ["mysdk_myjavalib@current"], +} +`), + checkAllCopyRules(` +.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar +.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt +.intermediates/myjavalib.stubs.source/android_common/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib-removed.txt +`), + checkMergeZips( + ".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip", + ), + ) +} + func TestSnapshotWithJavaSdkLibrary_ApiSurfaces(t *testing.T) { result := testSdkWithJava(t, ` sdk {