From 81fe4d1d74185a5c1f6859bd07ad4cc02ca501f4 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Wed, 15 May 2024 18:43:47 +0000 Subject: [PATCH] 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 --- apex/apex_test.go | 38 ++++++++++++++++++++++---- java/hiddenapi_singleton_test.go | 11 +++++++- java/platform_bootclasspath.go | 5 ++++ sdk/bootclasspath_fragment_sdk_test.go | 13 +++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 9a5c2b49b..d4a22121a 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -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, diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 330013ee4..62297978c 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -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") diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index b3c9ce50f..0f87b2745 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -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() diff --git a/sdk/bootclasspath_fragment_sdk_test.go b/sdk/bootclasspath_fragment_sdk_test.go index 6e2512262..7048a15b7 100644 --- a/sdk/bootclasspath_fragment_sdk_test.go +++ b/sdk/bootclasspath_fragment_sdk_test.go @@ -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 {