From fa4a90d4341c5f54a03022e626b817acbee8bf78 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Wed, 20 Dec 2023 02:53:38 +0000 Subject: Generate "exportable" stubs library in java_sdk_library Given that now the droidstubs module generates the "exportable" stubs, this change modifies java_sdk_library to generate the java_library modules that compiles the "exportable" stubs per api scope. The detailed naming scheme of the generated modules are available in the bug linked in the footer. Similar to the from-text java_api_library vs from-source java_library static lib selection for the "everything" stubs, the "exportable" stubs module can also toggle between the stubs java_api_library and the java_library module. However, given that the "exportable" stubs generation has not been implemented for from-text stubs, the module always default to depend on the from-source "exportable" stubs compiling java_library module. Test: go test ./java Bug: 315495926 Change-Id: I5798312c1338c55625b2030da728b056385171a4 --- java/sdk_library_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'java/sdk_library_test.go') diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 63419d6b1..c14f3e611 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -1423,7 +1423,7 @@ func TestJavaSdkLibraryDist(t *testing.T) { for _, tt := range testCases { t.Run(tt.module, func(t *testing.T) { - m := result.ModuleForTests(tt.module+".stubs", "android_common").Module().(*Library) + m := result.ModuleForTests(apiScopePublic.exportableStubsLibraryModuleName(tt.module), "android_common").Module().(*Library) dists := m.Dists() if len(dists) != 1 { t.Fatalf("expected exactly 1 dist entry, got %d", len(dists)) @@ -1693,3 +1693,56 @@ func TestSdkLibraryDependency(t *testing.T) { android.AssertStringDoesContain(t, "bar.xml java_sdk_xml command", barPermissions.RuleParams.Command, `dependency=\"foo\"`) } + +func TestSdkLibraryExportableStubsLibrary(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo"), + android.FixtureModifyConfig(func(config android.Config) { + config.SetApiLibraries([]string{"foo"}) + }), + ).RunTestWithBp(t, ` + aconfig_declarations { + name: "bar", + package: "com.example.package", + srcs: [ + "bar.aconfig", + ], + } + java_sdk_library { + name: "foo", + srcs: ["a.java", "b.java"], + api_packages: ["foo"], + system: { + enabled: true, + }, + module_lib: { + enabled: true, + }, + test: { + enabled: true, + }, + aconfig_declarations: [ + "bar", + ], + } + `) + + exportableStubsLibraryModuleName := apiScopePublic.exportableStubsLibraryModuleName("foo") + exportableSourceStubsLibraryModuleName := apiScopePublic.exportableSourceStubsLibraryModuleName("foo") + + // Check modules generation + topLevelModule := result.ModuleForTests(exportableStubsLibraryModuleName, "android_common") + result.ModuleForTests(exportableSourceStubsLibraryModuleName, "android_common") + + // Check static lib dependency + android.AssertBoolEquals(t, "exportable top level stubs library module depends on the"+ + "exportable source stubs library module", true, + CheckModuleHasDependency(t, result.TestContext, exportableStubsLibraryModuleName, + "android_common", exportableSourceStubsLibraryModuleName), + ) + android.AssertArrayString(t, "exportable source stub library is a static lib of the"+ + "top level exportable stubs library", []string{exportableSourceStubsLibraryModuleName}, + topLevelModule.Module().(*Library).properties.Static_libs) +} -- cgit v1.2.3-59-g8ed1b