From 062eb663c5144f8d9e4ab273558633a15bb75abd Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Thu, 29 Feb 2024 21:51:12 +0000 Subject: Enable from-text stub generation in non-sdk java_sdk_library This change allows from-text stubs to be generated for all java_sdk_library modules, unlike how it is currently limited to the modules that contribute to the api surfaces (i.e. the SDK). This change accomplish this by modifying the dependency of the from-text stubs generation, so that the sdk_library generated from-text stubs generating java_api_library modules no longer depend on the full api surface stubs, but generate the stubs in the module level, and combined later to generate the full api surface stubs. This change also removes the java_api_library modules defined in core-libraries/Android.bp, which are passed to generate the system modules. Given that the from-text vs from-source toggle is done within the java_sdk_library stubs level, these modules no longer need to exist. Implementation details: - Allow sdk_version to be specified in java_api_library modules. For java_sdk_library-generated java_api_library modules, they inherit that of the sdk_library module. Some java_sdk_library modules that do not contribute to the api surface are allowed to set sdk_version to something other than "none" or "core". - Implement java_api_library to implement `SdkContext`. This allows java_api_library to collect required deps from sdk_version (classpath, bootclasspath, system modules), and pass the collected jars when generating the stubs srcjar in metalava and compiling the stubs srcjar in javac. - Remove hardcoded list of sdk_library modules that are allowed to genereate stubs from the api signature files, and allow from-text stubs generation by default. Modules that are not able to generate stubs from the api signature files are specified by setting the newly introduced `Build_from_text_stubs` property to `false`. Test: ENABLE_HIDDENAPI_FLAGS=true m Bug: 327507877 Change-Id: Ia35d2f3cf9fae48fc8c4bd99a84ae18d7c0e7bee --- java/java_test.go | 76 ++++--------------------------------------------------- 1 file changed, 5 insertions(+), 71 deletions(-) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index 33079f381..2d4fca240 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1342,12 +1342,12 @@ func TestJavaLibraryWithSystemModules(t *testing.T) { } `) - checkBootClasspathForSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar") + checkBootClasspathForLibWithSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar") - checkBootClasspathForSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar") + checkBootClasspathForLibWithSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar") } -func checkBootClasspathForSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { +func checkBootClasspathForLibWithSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac") bootClasspath := javacRule.Args["bootClasspath"] if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) { @@ -2256,61 +2256,6 @@ func TestJavaApiLibraryStaticLibsLink(t *testing.T) { } } -func TestJavaApiLibraryFullApiSurfaceStub(t *testing.T) { - provider_bp_a := ` - java_api_contribution { - name: "foo1", - api_file: "current.txt", - api_surface: "public", - } - ` - provider_bp_b := ` - java_api_contribution { - name: "foo2", - api_file: "current.txt", - api_surface: "public", - } - ` - lib_bp_a := ` - java_api_library { - name: "lib1", - api_surface: "public", - api_contributions: ["foo1", "foo2"], - stubs_type: "everything", - } - ` - - ctx := android.GroupFixturePreparers( - prepareForJavaTest, - android.FixtureMergeMockFs( - map[string][]byte{ - "a/Android.bp": []byte(provider_bp_a), - "b/Android.bp": []byte(provider_bp_b), - "c/Android.bp": []byte(lib_bp_a), - }, - ), - android.FixtureMergeEnv( - map[string]string{ - "DISABLE_STUB_VALIDATION": "true", - }, - ), - ).RunTestWithBp(t, ` - java_api_library { - name: "bar1", - api_surface: "public", - api_contributions: ["foo1"], - full_api_surface_stub: "lib1", - stubs_type: "everything", - } - `) - - m := ctx.ModuleForTests("bar1", "android_common") - manifest := m.Output("metalava.sbox.textproto") - sboxProto := android.RuleBuilderSboxProtoForTests(t, ctx.TestContext, manifest) - manifestCommand := sboxProto.Commands[0].GetCommand() - android.AssertStringDoesContain(t, "Command expected to contain full_api_surface_stub output jar", manifestCommand, "lib1.jar") -} - func TestTransitiveSrcFiles(t *testing.T) { ctx, _ := testJava(t, ` java_library { @@ -2511,9 +2456,6 @@ func TestSdkLibraryProvidesSystemModulesToApiLibrary(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), - android.FixtureModifyConfig(func(config android.Config) { - config.SetApiLibraries([]string{"foo"}) - }), android.FixtureMergeMockFs( map[string][]byte{ "A.java": nil, @@ -2534,12 +2476,8 @@ func TestSdkLibraryProvidesSystemModulesToApiLibrary(t *testing.T) { system_modules: "baz", } `) - m := result.ModuleForTests(apiScopePublic.apiLibraryModuleName("foo"), "android_common") - manifest := m.Output("metalava.sbox.textproto") - sboxProto := android.RuleBuilderSboxProtoForTests(t, result.TestContext, manifest) - manifestCommand := sboxProto.Commands[0].GetCommand() - classPathFlag := "--classpath __SBOX_SANDBOX_DIR__/out/soong/.intermediates/bar/android_common/turbine-combined/bar.jar" - android.AssertStringDoesContain(t, "command expected to contain classpath flag", manifestCommand, classPathFlag) + + checkBootClasspathForLibWithSystemModule(t, result.TestContext, apiScopePublic.apiLibraryModuleName("foo"), "/bar.jar") } func TestApiLibraryDroidstubsDependency(t *testing.T) { @@ -2547,9 +2485,6 @@ func TestApiLibraryDroidstubsDependency(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), - android.FixtureModifyConfig(func(config android.Config) { - config.SetApiLibraries([]string{"foo"}) - }), android.FixtureMergeMockFs( map[string][]byte{ "A.java": nil, @@ -2598,7 +2533,6 @@ func TestDisableFromTextStubForCoverageBuild(t *testing.T) { PrepareForTestWithJacocoInstrumentation, FixtureWithLastReleaseApis("foo"), android.FixtureModifyConfig(func(config android.Config) { - config.SetApiLibraries([]string{"foo"}) config.SetBuildFromTextStub(true) }), android.FixtureModifyEnv(func(env map[string]string) { -- cgit v1.2.3-59-g8ed1b