Disable monolithic hiddenapi flags generation for non java devices.

platform-bootclasspath constructs the monotlithic hiddenapi flags by
looking at PRODUCT_BOOT_JARS which are not included in another
bootclasspath fragment. PRODUCT_BOOT_JARS is a product specific
property, and non java devices like minidroid have an empty value for
this. For such devices, the monolithic flag generation runs into an
error because there are no jars to run this on.

This CL disables the generation of monolithic specific hiddenapi flags
when there are no monolithic boot jars in the build.

Bug: 338363444
Test: lunch aosp_cf_x86_64_minidroid-trunk_staging-userdebug && mmma
frameworks/base

Change-Id: I093690786bcf85b2aa6f01d0c689fc2a35861b5c
This commit is contained in:
Spandan Das 2024-05-15 18:43:47 +00:00
parent e8cb9178ec
commit 81fe4d1d74
4 changed files with 61 additions and 6 deletions

View file

@ -5049,6 +5049,20 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
// Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
// is disabled.
android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
// Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
// file creation.
java.FixtureConfigureBootJars("platform:foo"),
android.FixtureModifyMockFS(func(fs android.MockFS) {
fs["platform/Android.bp"] = []byte(`
java_library {
name: "foo",
srcs: ["Test.java"],
compile_dex: true,
}
`)
fs["platform/Test.java"] = nil
}),
)
checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) {
@ -5143,7 +5157,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
checkHiddenAPIIndexFromFlagsInputs(t, ctx, `
my-bootclasspath-fragment/index.csv
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
@ -5221,7 +5235,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
checkHiddenAPIIndexFromFlagsInputs(t, ctx, `
my-bootclasspath-fragment/index.csv
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
@ -5410,7 +5424,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
checkHiddenAPIIndexFromFlagsInputs(t, ctx, `
my-bootclasspath-fragment/index.csv
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
@ -5507,7 +5521,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/hiddenapi-modular/encoded/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
checkHiddenAPIIndexFromFlagsInputs(t, ctx, `
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/modular-hiddenapi/index.csv
@ -5620,7 +5634,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/prebuilt_myapex.deapexer/android_common/deapexer/javalib/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)
checkHiddenAPIIndexFromClassesInputs(t, ctx, `out/soong/.intermediates/platform/foo/android_common/javac/foo.jar`)
checkHiddenAPIIndexFromFlagsInputs(t, ctx, `
my-bootclasspath-fragment/index.csv
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
@ -11238,6 +11252,20 @@ func TestBootDexJarsMultipleApexPrebuilts(t *testing.T) {
android.FixtureMergeMockFs(map[string][]byte{
"system/sepolicy/apex/com.android.foo-file_contexts": nil,
}),
// Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
// file creation.
java.FixtureConfigureBootJars("platform:foo"),
android.FixtureModifyMockFS(func(fs android.MockFS) {
fs["platform/Android.bp"] = []byte(`
java_library {
name: "foo",
srcs: ["Test.java"],
compile_dex: true,
}
`)
fs["platform/Test.java"] = nil
}),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.BuildFlags = map[string]string{
"RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": tc.selectedApexContributions,

View file

@ -198,13 +198,22 @@ func TestHiddenAPISingletonSdks(t *testing.T) {
hiddenApiFixtureFactory,
tc.preparer,
prepareForTestWithDefaultPlatformBootclasspath,
// Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
// file creation.
FixtureConfigureBootJars("platform:foo"),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(tc.unbundledBuild)
variables.BuildFlags = map[string]string{
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
}
}),
).RunTest(t)
).RunTestWithBp(t, `
java_library {
name: "foo",
srcs: ["a.java"],
compile_dex: true,
}
`)
hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common")
hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags")

View file

@ -325,6 +325,11 @@ func (b *platformBootclasspathModule) generateHiddenAPIBuildActions(ctx android.
// the fragments will have already provided the flags that are needed.
classesJars := monolithicInfo.ClassesJars
if len(classesJars) == 0 {
// This product does not include any monolithic jars. Monolithic hiddenapi flag generation is not required.
return bootDexJarByModule
}
// Create the input to pass to buildRuleToGenerateHiddenAPIStubFlagsFile
input := newHiddenAPIFlagInput()

View file

@ -281,6 +281,19 @@ func testSnapshotWithBootClasspathFragment_Contents(t *testing.T, sdk string, co
"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
}
}),
// Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
// file creation.
java.FixtureConfigureBootJars("platform:foo"),
android.FixtureModifyMockFS(func(fs android.MockFS) {
fs["platform/Android.bp"] = []byte(`
java_library {
name: "foo",
srcs: ["Test.java"],
compile_dex: true,
}
`)
fs["platform/Test.java"] = nil
}),
android.FixtureWithRootAndroidBp(sdk+`
apex {