From b108f75b9d7d71bdd6c9dd28f82d0ad55389e186 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 13 Jan 2022 12:26:30 +0000 Subject: [PATCH 1/2] Some minor tweaks for api.go - Make constants for re-used hardcoded module names - Add a removeAll function - Move filtering into individual "create" methods. Bug: 169103987 Test: mmm frameworks/base/api Change-Id: Id81c93eafdbdbbd0f55a4a906150b58a001392f6 --- api/api.go | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/api/api.go b/api/api.go index 6cc129a360fd5..14fe09ee36dab 100644 --- a/api/api.go +++ b/api/api.go @@ -23,6 +23,10 @@ import ( "android/soong/genrule" ) +const art = "art.module.public.api" +const conscrypt = "conscrypt.module.public.api" +const i18n = "i18n.module.public.api" + // The intention behind this soong plugin is to generate a number of "merged" // API-related modules that would otherwise require a large amount of very // similar Android.bp boilerplate to define. For example, the merged current.txt @@ -130,6 +134,8 @@ func createMergedStubsSrcjar(ctx android.LoadHookContext, modules []string) { // This produces the same annotations.zip as framework-doc-stubs, but by using // outputs from individual modules instead of all the source code. func createMergedAnnotations(ctx android.LoadHookContext, modules []string) { + // Conscrypt and i18n currently do not enable annotations + modules = removeAll(modules, []string{conscrypt, i18n}) props := genruleProps{} props.Name = proptools.StringPtr("sdk-annotations.zip") props.Tools = []string{"merge_annotation_zips", "soong_zip"} @@ -141,6 +147,15 @@ func createMergedAnnotations(ctx android.LoadHookContext, modules []string) { } func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { + // For the filtered api versions, we prune all APIs except art module's APIs. because + // 1) ART apis are available by default to all modules, while other module-to-module deps are + // explicit and probably receive more scrutiny anyway + // 2) The number of ART/libcore APIs is large, so not linting them would create a large gap + // 3) It's a compromise. Ideally we wouldn't be filtering out any module APIs, and have + // per-module lint databases that excludes just that module's APIs. Alas, that's more + // difficult to achieve. + modules = remove(modules, art) + props := genruleProps{} props.Name = proptools.StringPtr("api-versions-xml-public-filtered") props.Tools = []string{"api_versions_trimmer"} @@ -163,6 +178,13 @@ func createSrcs(base string, modules []string, tag string) []string { return a } +func removeAll(s []string, vs []string) []string { + for _, v := range vs { + s = remove(s, v) + } + return s +} + func remove(s []string, v string) []string { s2 := make([]string, 0, len(s)) for _, sv := range s { @@ -176,9 +198,7 @@ func remove(s []string, v string) []string { func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { var textFiles []MergedTxtDefinition // Two module libraries currently do not support @SystemApi so only have the public scope. - bcpWithSystemApi := bootclasspath - bcpWithSystemApi = remove(bcpWithSystemApi, "conscrypt.module.public.api") - bcpWithSystemApi = remove(bcpWithSystemApi, "i18n.module.public.api") + bcpWithSystemApi := removeAll(bootclasspath, []string{conscrypt, i18n}) tagSuffix := []string{".api.txt}", ".removed-api.txt}"} for i, f := range []string{"current.txt", "removed.txt"} { @@ -226,22 +246,9 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { createMergedStubsSrcjar(ctx, bootclasspath) - // Conscrypt and i18n currently do not enable annotations - annotationModules := bootclasspath - annotationModules = remove(annotationModules, "conscrypt.module.public.api") - annotationModules = remove(annotationModules, "i18n.module.public.api") - createMergedAnnotations(ctx, annotationModules) + createMergedAnnotations(ctx, bootclasspath) - // For the filtered api versions, we prune all APIs except art module's APIs. because - // 1) ART apis are available by default to all modules, while other module-to-module deps are - // explicit and probably receive more scrutiny anyway - // 2) The number of ART/libcore APIs is large, so not linting them would create a large gap - // 3) It's a compromise. Ideally we wouldn't be filtering out any module APIs, and have - // per-module lint databases that excludes just that module's APIs. Alas, that's more - // difficult to achieve. - filteredModules := bootclasspath - filteredModules = remove(filteredModules, "art.module.public.api") - createFilteredApiVersions(ctx, filteredModules) + createFilteredApiVersions(ctx, bootclasspath) } func combinedApisModuleFactory() android.Module { From 47ff71a9020c80faa8caa15639854a24f6fddc55 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 13 Jan 2022 09:45:12 +0000 Subject: [PATCH 2/2] Convert merged module lib stub to api.go Bug: 169103987 Test: m framework-updatable-stubs-module_libs_api and diff intermediates folder before and after. Change-Id: I6018791ae136bc764a6e846078c6bce59bcc123b --- Android.bp | 32 -------------------------------- api/Android.bp | 1 + api/api.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Android.bp b/Android.bp index d64951c3d98f2..f61cdad8ba0fd 100644 --- a/Android.bp +++ b/Android.bp @@ -154,38 +154,6 @@ filegroup { ], } -java_library_with_nonpublic_deps { - name: "framework-updatable-stubs-module_libs_api", - static_libs: [ - "android.net.ipsec.ike.stubs.module_lib", - "framework-appsearch.stubs.module_lib", - "framework-connectivity.stubs.module_lib", - "framework-connectivity-tiramisu.stubs.module_lib", - "framework-graphics.stubs.module_lib", - "framework-media.stubs.module_lib", - "framework-mediaprovider.stubs.module_lib", - "framework-permission.stubs.module_lib", - "framework-permission-s.stubs.module_lib", - "framework-scheduling.stubs.module_lib", - "framework-sdkextensions.stubs.module_lib", - "framework-statsd.stubs.module_lib", - "framework-supplementalprocess.stubs.module_lib", - "framework-tethering.stubs.module_lib", - "framework-uwb.stubs.module_lib", - "framework-nearby.stubs.module_lib", - "framework-wifi.stubs.module_lib", - ], - soong_config_variables: { - include_nonpublic_framework_api: { - static_libs: [ - "framework-supplementalapi.stubs.module_lib", - ], - }, - }, - sdk_version: "module_current", - visibility: ["//visibility:private"], -} - java_library_with_nonpublic_deps { name: "framework-all", installable: false, diff --git a/api/Android.bp b/api/Android.bp index 7aa68f85bf294..362f39f2beaf4 100644 --- a/api/Android.bp +++ b/api/Android.bp @@ -32,6 +32,7 @@ bootstrap_go_package { "soong", "soong-android", "soong-genrule", + "soong-java", ], srcs: ["api.go"], pluginFor: ["soong_build"], diff --git a/api/api.go b/api/api.go index 14fe09ee36dab..3b0e300c88f3c 100644 --- a/api/api.go +++ b/api/api.go @@ -21,6 +21,7 @@ import ( "android/soong/android" "android/soong/genrule" + "android/soong/java" ) const art = "art.module.public.api" @@ -73,6 +74,13 @@ type genruleProps struct { Visibility []string } +type libraryProps struct { + Name *string + Sdk_version *string + Static_libs []string + Visibility []string +} + // Struct to pass parameters for the various merged [current|removed].txt file modules we create. type MergedTxtDefinition struct { // "current.txt" or "removed.txt" @@ -169,6 +177,25 @@ func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { ctx.CreateModule(genrule.GenRuleFactory, &props) } +func createMergedModuleLibStubs(ctx android.LoadHookContext, modules []string) { + // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes. + modules = removeAll(modules, []string{art, conscrypt, i18n}) + props := libraryProps{} + props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api") + props.Static_libs = appendStr(modules, ".stubs.module_lib") + props.Sdk_version = proptools.StringPtr("module_current") + props.Visibility = []string{"//frameworks/base"} + ctx.CreateModule(java.LibraryFactory, &props) +} + +func appendStr(modules []string, s string) []string { + a := make([]string, 0, len(modules)) + for _, module := range modules { + a = append(a, module+s) + } + return a +} + func createSrcs(base string, modules []string, tag string) []string { a := make([]string, 0, len(modules)+1) a = append(a, base) @@ -246,6 +273,8 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { createMergedStubsSrcjar(ctx, bootclasspath) + createMergedModuleLibStubs(ctx, bootclasspath) + createMergedAnnotations(ctx, bootclasspath) createFilteredApiVersions(ctx, bootclasspath)