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
Change-Id: Ia581a17f1e48dff252d17f16bf76adf039f46b60
This commit is contained in:
Paul Duffin 2021-05-14 15:03:30 +01:00
parent e8b0169bb4
commit 0d586581d1

View file

@ -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")
}
})
}