diff options
author | Paul Duffin <paulduffin@google.com> | 2021-05-14 15:03:30 +0100 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2021-05-18 07:59:29 +0100 |
commit | 78fc68695edd70a834af9163b2bf56a35cfaa385 (patch) | |
tree | 29db53a480499a49597338e75a4d80ae8839e0b8 /java/hiddenapi_singleton_test.go | |
parent | 460952c7f4baa70dbf6c91424b4389b6aded3bab (diff) |
Add a test for hidden API encoding of java_sdk_library
Fill a hole in the testing of hidden API encoding. Some comments in the
code indicate that the child implementation java_library of a
java_sdk_library should have hidden API flags encoded in its dex jar
just like the embedded java_library. However, this test proves that it
is not working. This will be fixed in a follow up change.
Bug: 179354495
Test: m nothing
Merged-In: Ia581a17f1e48dff252d17f16bf76adf039f46b60
Change-Id: Ia581a17f1e48dff252d17f16bf76adf039f46b60
(cherry picked from commit 0d586581d1c2d6d22e7f00007e50e579ca90df29)
Diffstat (limited to 'java/hiddenapi_singleton_test.go')
-rw-r--r-- | java/hiddenapi_singleton_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index e6b45ac20..dcd363c2c 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -274,3 +274,56 @@ func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) { android.AssertStringEquals(t, "hiddenapi encode dex rule flags csv", expectedFlagsCsv, actualFlagsCsv) } + +func TestHiddenAPIEncoding_JavaSdkLibrary(t *testing.T) { + + result := android.GroupFixturePreparers( + hiddenApiFixtureFactory, + FixtureConfigureBootJars("platform:foo"), + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo"), + + // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding + // is disabled. + android.FixtureAddTextFile("frameworks/base/Android.bp", ""), + ).RunTestWithBp(t, ` + java_sdk_library { + name: "foo", + srcs: ["a.java"], + shared_library: false, + compile_dex: true, + public: {enabled: true}, + } + `) + + checkDexEncoded := func(t *testing.T, name, unencodedDexJar, encodedDexJar string) { + moduleForTests := result.ModuleForTests(name, "android_common") + + encodeDexRule := moduleForTests.Rule("hiddenAPIEncodeDex") + actualUnencodedDexJar := encodeDexRule.Input + + // Make sure that the module has its dex jar encoded. + android.AssertStringEquals(t, "encode embedded java_library", unencodedDexJar, actualUnencodedDexJar.String()) + + // Make sure that the encoded dex jar is the exported one. + exportedDexJar := moduleForTests.Module().(UsesLibraryDependency).DexJarBuildPath() + android.AssertPathRelativeToTopEquals(t, "encode embedded java_library", encodedDexJar, exportedDexJar) + } + + // The java_library embedded with the java_sdk_library must be dex encoded. + t.Run("foo", func(t *testing.T) { + expectedUnencodedDexJar := "out/soong/.intermediates/foo/android_common/aligned/foo.jar" + expectedEncodedDexJar := "out/soong/.intermediates/foo/android_common/hiddenapi/foo.jar" + checkDexEncoded(t, "foo", expectedUnencodedDexJar, expectedEncodedDexJar) + }) + + // The dex jar of the child implementation java_library of the java_sdk_library is not currently + // dex encoded. + t.Run("foo.impl", func(t *testing.T) { + fooImpl := result.ModuleForTests("foo.impl", "android_common") + encodeDexRule := fooImpl.MaybeRule("hiddenAPIEncodeDex") + if encodeDexRule.Rule != nil { + t.Errorf("foo.impl is not expected to be encoded") + } + }) +} |