From 748a24dd6e2fea894a8130604771ae9757434ec8 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Wed, 20 Mar 2024 21:29:39 +0000 Subject: [PATCH] droidstubs depend on the combined last api filegroup modules This change creates a "combined" filegroup module, which will contain all api files of the subset api scopes in the followup change. In this change, the "combined" filegroup is identical to the currently existing last api filegroup module in that it only contains the api file / removed api file of the specific api scope. This change also passes the "combined" filegroup to the droidstubs module generated from the sdk_library modules, but this currently does not lead to any functional changes as the "combined" filegroup is identical to the currently existing last api filegroup. Test: m nothing --no-skip-soong-tests Bug: 321827591 Change-Id: If73a7229f2f970f7e74cd010a8b4808dc9018344 --- java/prebuilt_apis.go | 39 +++++++++++++++++++++++++++++++++++++-- java/sdk_library.go | 8 ++++++-- java/sdk_library_test.go | 20 ++++++++++---------- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/java/prebuilt_apis.go b/java/prebuilt_apis.go index 94e9c6c57..6a79e5883 100644 --- a/java/prebuilt_apis.go +++ b/java/prebuilt_apis.go @@ -158,6 +158,21 @@ func createApiModule(mctx android.LoadHookContext, name string, path string) { mctx.CreateModule(genrule.GenRuleFactory, &genruleProps) } +func createCombinedApiFilegroupModule(mctx android.LoadHookContext, name string, srcs []string) { + filegroupProps := struct { + Name *string + Srcs []string + }{} + filegroupProps.Name = proptools.StringPtr(name) + + var transformedSrcs []string + for _, src := range srcs { + transformedSrcs = append(transformedSrcs, ":"+src) + } + filegroupProps.Srcs = transformedSrcs + mctx.CreateModule(android.FileGroupFactory, &filegroupProps) +} + func createLatestApiModuleExtensionVersionFile(mctx android.LoadHookContext, name string, version string) { genruleProps := struct { Name *string @@ -252,6 +267,10 @@ func PrebuiltApiModuleName(module, scope, version string) string { return module + ".api." + scope + "." + version } +func PrebuiltApiCombinedModuleName(module, scope, version string) string { + return module + ".api.combined." + scope + "." + version +} + func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { // //api/.txt apiLevelFiles := globApiDirs(mctx, p, "api/*.txt") @@ -307,7 +326,9 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { } // Sort the keys in order to make build.ninja stable - for _, k := range android.SortedKeys(latest) { + sortedLatestKeys := android.SortedKeys(latest) + + for _, k := range sortedLatestKeys { info := latest[k] name := PrebuiltApiModuleName(info.module, info.scope, "latest") latestExtensionVersionModuleName := PrebuiltApiModuleName(info.module, info.scope, "latest.extension_version") @@ -333,11 +354,25 @@ func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { } } // Create empty incompatibilities files for remaining modules - for _, k := range android.SortedKeys(latest) { + // If the incompatibility module has been created, create a corresponding combined module + for _, k := range sortedLatestKeys { if _, ok := incompatibilities[k]; !ok { createEmptyFile(mctx, PrebuiltApiModuleName(latest[k].module+"-incompatibilities", latest[k].scope, "latest")) } } + + // Create combined latest api and removed api files modules. + // The combined modules list all api files of the api scope and its subset api scopes. + for _, k := range sortedLatestKeys { + info := latest[k] + name := PrebuiltApiCombinedModuleName(info.module, info.scope, "latest") + + var srcs []string + currentApiScope := scopeByName[info.scope] + srcs = append(srcs, PrebuiltApiModuleName(info.module, currentApiScope.name, "latest")) + + createCombinedApiFilegroupModule(mctx, name, srcs) + } } func createPrebuiltApiModules(mctx android.LoadHookContext) { diff --git a/java/sdk_library.go b/java/sdk_library.go index bde5e7de3..7f49871e9 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1672,12 +1672,16 @@ func latestPrebuiltApiModuleName(name string, apiScope *apiScope) string { return PrebuiltApiModuleName(name, apiScope.name, "latest") } +func latestPrebuiltApiCombinedModuleName(name string, apiScope *apiScope) string { + return PrebuiltApiCombinedModuleName(name, apiScope.name, "latest") +} + func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { return ":" + module.latestApiModuleName(apiScope) } func (module *SdkLibrary) latestApiModuleName(apiScope *apiScope) string { - return latestPrebuiltApiModuleName(module.distStem(), apiScope) + return latestPrebuiltApiCombinedModuleName(module.distStem(), apiScope) } func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { @@ -1685,7 +1689,7 @@ func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) stri } func (module *SdkLibrary) latestRemovedApiModuleName(apiScope *apiScope) string { - return latestPrebuiltApiModuleName(module.distStem()+"-removed", apiScope) + return latestPrebuiltApiCombinedModuleName(module.distStem()+"-removed", apiScope) } func (module *SdkLibrary) latestIncompatibilitiesFilegroupName(apiScope *apiScope) string { diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index b622f98d0..fb584c5c7 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -139,10 +139,10 @@ func TestJavaSdkLibrary(t *testing.T) { exportedComponentsInfo, _ := android.SingletonModuleProvider(result, foo.Module(), android.ExportedComponentsInfoProvider) expectedFooExportedComponents := []string{ - "foo-removed.api.public.latest", - "foo-removed.api.system.latest", - "foo.api.public.latest", - "foo.api.system.latest", + "foo-removed.api.combined.public.latest", + "foo-removed.api.combined.system.latest", + "foo.api.combined.public.latest", + "foo.api.combined.system.latest", "foo.stubs", "foo.stubs.exportable", "foo.stubs.exportable.system", @@ -556,8 +556,8 @@ func TestJavaSdkLibrary_Deps(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `dex2oatd`, - `sdklib-removed.api.public.latest`, - `sdklib.api.public.latest`, + `sdklib-removed.api.combined.public.latest`, + `sdklib.api.combined.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.exportable`, @@ -960,8 +960,8 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) { CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `dex2oatd`, `prebuilt_sdklib`, - `sdklib-removed.api.public.latest`, - `sdklib.api.public.latest`, + `sdklib-removed.api.combined.public.latest`, + `sdklib.api.combined.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.exportable`, @@ -1039,8 +1039,8 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ `prebuilt_sdklib`, - `sdklib-removed.api.public.latest`, - `sdklib.api.public.latest`, + `sdklib-removed.api.combined.public.latest`, + `sdklib.api.combined.public.latest`, `sdklib.impl`, `sdklib.stubs`, `sdklib.stubs.exportable`,