aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2021-05-12 23:13:22 +0100
committerPaul Duffin <paulduffin@google.com>2021-05-12 23:13:22 +0100
commit22628d50f3dbde94be96a54095557a5e99bd961a (patch)
treedaf91b4a49de66196850ffa903d1af3c94316728
parentc8aeb00a9cb273acc4b4f92beddf592642cc3e5e (diff)
downloadsoong-22628d50f3dbde94be96a54095557a5e99bd961a.tar.gz
Add support for SOONG_SDK_SNAPSHOT_USE_SRCJAR
Test: m SOONG_SDK_SNAPSHOT_USE_SRCJAR=true ipsec-module-sdk - check generated snapshot.zip file. Change-Id: I02991e2a60d7784984b308cff2c47ee809d61f01
-rw-r--r--java/sdk_library.go17
-rw-r--r--sdk/java_sdk_test.go51
2 files changed, 63 insertions, 5 deletions
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 800e93b20..7804512f3 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -2482,11 +2482,18 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
}
scopeSet.AddProperty("jars", jars)
- // Merge the stubs source jar into the snapshot zip so that when it is unpacked
- // the source files are also unpacked.
- snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
- ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
- scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
+ if ctx.SdkModuleContext().Config().IsEnvTrue("SOONG_SDK_SNAPSHOT_USE_SRCJAR") {
+ // Copy the stubs source jar into the snapshot zip as is.
+ srcJarSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".srcjar")
+ ctx.SnapshotBuilder().CopyToSnapshot(properties.StubsSrcJar, srcJarSnapshotPath)
+ scopeSet.AddProperty("stub_srcs", []string{srcJarSnapshotPath})
+ } else {
+ // Merge the stubs source jar into the snapshot zip so that when it is unpacked
+ // the source files are also unpacked.
+ snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources")
+ ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir)
+ scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir})
+ }
if properties.CurrentApiFile != nil {
currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt")
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index dc58d9309..6f769a3f1 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -1089,6 +1089,57 @@ sdk_snapshot {
)
}
+func TestSnapshotWithJavaSdkLibrary_UseSrcJar(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJavaSdkLibrary,
+ android.FixtureMergeEnv(map[string]string{
+ "SOONG_SDK_SNAPSHOT_USE_SRCJAR": "true",
+ }),
+ ).RunTestWithBp(t, `
+ sdk {
+ name: "mysdk",
+ java_sdk_libs: ["myjavalib"],
+ }
+
+ java_sdk_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ sdk_version: "current",
+ shared_library: false,
+ public: {
+ enabled: true,
+ },
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ shared_library: false,
+ public: {
+ jars: ["sdk_library/public/myjavalib-stubs.jar"],
+ stub_srcs: ["sdk_library/public/myjavalib.srcjar"],
+ current_api: "sdk_library/public/myjavalib.txt",
+ removed_api: "sdk_library/public/myjavalib-removed.txt",
+ sdk_version: "current",
+ },
+}
+ `),
+ checkAllCopyRules(`
+.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
+.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source-stubs.srcjar -> sdk_library/public/myjavalib.srcjar
+.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
+.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
+ `),
+ )
+}
+
func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) {
result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
sdk {