From ec450c058e4a2e3d8085f528b627759d5084d76f Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Tue, 11 Jan 2022 16:37:05 +0000 Subject: [PATCH 1/7] Replace manual genrule modules with combined_apis This simplifies the addition of new modules by cutting down the number of lists that the new module must be added to. The combined_apis module generates equivalent genrules in a programmatic fashion. Bug: 169103987 Test: `mmm frameworks/base/api` before and after and compare the soong intermediates of that folder. Merged-In: Ia718f9374042e5fbb2168476f5bad3b1867b8a05 Change-Id: Ia718f9374042e5fbb2168476f5bad3b1867b8a05 --- api/Android.bp | 351 ++++--------------------------------------------- 1 file changed, 22 insertions(+), 329 deletions(-) diff --git a/api/Android.bp b/api/Android.bp index f89c55705adaf..663f9027ddc4d 100644 --- a/api/Android.bp +++ b/api/Android.bp @@ -102,43 +102,30 @@ genrule { visibility: ["//visibility:public"], } -genrule { - name: "frameworks-base-api-current.txt", - srcs: [ - ":android.net.ipsec.ike{.public.api.txt}", - ":art.module.public.api{.public.api.txt}", - ":conscrypt.module.public.api{.public.api.txt}", - ":framework-appsearch{.public.api.txt}", - ":framework-connectivity{.public.api.txt}", - ":framework-graphics{.public.api.txt}", - ":framework-media{.public.api.txt}", - ":framework-mediaprovider{.public.api.txt}", - ":framework-permission{.public.api.txt}", - ":framework-permission-s{.public.api.txt}", - ":framework-scheduling{.public.api.txt}", - ":framework-sdkextensions{.public.api.txt}", - ":framework-statsd{.public.api.txt}", - ":framework-tethering{.public.api.txt}", - ":framework-wifi{.public.api.txt}", - ":i18n.module.public.api{.public.api.txt}", - ":non-updatable-current.txt", +combined_apis { + name: "frameworks-base-api", + bootclasspath: [ + "android.net.ipsec.ike", + "art.module.public.api", + "conscrypt.module.public.api", + "framework-appsearch", + "framework-connectivity", + "framework-graphics", + "framework-media", + "framework-mediaprovider", + "framework-permission", + "framework-permission-s", + "framework-scheduling", + "framework-sdkextensions", + "framework-statsd", + "framework-tethering", + "framework-wifi", + "i18n.module.public.api", ], - out: ["current.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "current.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/public/api", - dest: "android.txt", - }, + system_server_classpath: [ + "service-media-s", + "service-permission", ], - visibility: ["//visibility:public"], } genrule { @@ -157,108 +144,6 @@ genrule { "$(location :frameworks-base-api-current.txt)", } -genrule { - name: "frameworks-base-api-current.srcjar", - srcs: [ - ":android.net.ipsec.ike{.public.stubs.source}", - ":api-stubs-docs-non-updatable", - ":art.module.public.api{.public.stubs.source}", - ":conscrypt.module.public.api{.public.stubs.source}", - ":framework-appsearch{.public.stubs.source}", - ":framework-connectivity{.public.stubs.source}", - ":framework-graphics{.public.stubs.source}", - ":framework-media{.public.stubs.source}", - ":framework-mediaprovider{.public.stubs.source}", - ":framework-permission{.public.stubs.source}", - ":framework-permission-s{.public.stubs.source}", - ":framework-scheduling{.public.stubs.source}", - ":framework-sdkextensions{.public.stubs.source}", - ":framework-statsd{.public.stubs.source}", - ":framework-tethering{.public.stubs.source}", - ":framework-wifi{.public.stubs.source}", - ":i18n.module.public.api{.public.stubs.source}", - ], - out: ["current.srcjar"], - tools: ["merge_zips"], - cmd: "$(location merge_zips) $(out) $(in)", - visibility: ["//visibility:private"], // Used by make module in //development, mind. -} - -genrule { - name: "frameworks-base-api-removed.txt", - srcs: [ - ":android.net.ipsec.ike{.public.removed-api.txt}", - ":art.module.public.api{.public.removed-api.txt}", - ":conscrypt.module.public.api{.public.removed-api.txt}", - ":framework-appsearch{.public.removed-api.txt}", - ":framework-connectivity{.public.removed-api.txt}", - ":framework-graphics{.public.removed-api.txt}", - ":framework-media{.public.removed-api.txt}", - ":framework-mediaprovider{.public.removed-api.txt}", - ":framework-permission{.public.removed-api.txt}", - ":framework-permission-s{.public.removed-api.txt}", - ":framework-scheduling{.public.removed-api.txt}", - ":framework-sdkextensions{.public.removed-api.txt}", - ":framework-statsd{.public.removed-api.txt}", - ":framework-tethering{.public.removed-api.txt}", - ":framework-wifi{.public.removed-api.txt}", - ":i18n.module.public.api{.public.removed-api.txt}", - ":non-updatable-removed.txt", - ], - out: ["removed.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "removed.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/public/api", - dest: "removed.txt", - }, - ], -} - -genrule { - name: "frameworks-base-api-system-current.txt", - srcs: [ - ":art.module.public.api{.system.api.txt}", - ":android.net.ipsec.ike{.system.api.txt}", - ":framework-appsearch{.system.api.txt}", - ":framework-connectivity{.system.api.txt}", - ":framework-graphics{.system.api.txt}", - ":framework-media{.system.api.txt}", - ":framework-mediaprovider{.system.api.txt}", - ":framework-permission{.system.api.txt}", - ":framework-permission-s{.system.api.txt}", - ":framework-scheduling{.system.api.txt}", - ":framework-sdkextensions{.system.api.txt}", - ":framework-statsd{.system.api.txt}", - ":framework-tethering{.system.api.txt}", - ":framework-wifi{.system.api.txt}", - ":non-updatable-system-current.txt", - ], - out: ["system-current.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "system-current.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/system/api", - dest: "android.txt", - }, - ], - visibility: ["//visibility:public"], -} - genrule { name: "frameworks-base-api-system-current-compat", srcs: [ @@ -277,79 +162,6 @@ genrule { "$(location :frameworks-base-api-system-current.txt)", } -genrule { - name: "frameworks-base-api-system-removed.txt", - srcs: [ - ":art.module.public.api{.system.removed-api.txt}", - ":android.net.ipsec.ike{.system.removed-api.txt}", - ":framework-appsearch{.system.removed-api.txt}", - ":framework-connectivity{.system.removed-api.txt}", - ":framework-graphics{.system.removed-api.txt}", - ":framework-media{.system.removed-api.txt}", - ":framework-mediaprovider{.system.removed-api.txt}", - ":framework-permission{.system.removed-api.txt}", - ":framework-permission-s{.system.removed-api.txt}", - ":framework-scheduling{.system.removed-api.txt}", - ":framework-sdkextensions{.system.removed-api.txt}", - ":framework-statsd{.system.removed-api.txt}", - ":framework-tethering{.system.removed-api.txt}", - ":framework-wifi{.system.removed-api.txt}", - ":non-updatable-system-removed.txt", - ], - out: ["system-removed.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "system-removed.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/system/api", - dest: "removed.txt", - }, - ], - visibility: ["//visibility:public"], -} - -genrule { - name: "frameworks-base-api-module-lib-current.txt", - srcs: [ - ":art.module.public.api{.module-lib.api.txt}", - ":android.net.ipsec.ike{.module-lib.api.txt}", - ":framework-appsearch{.module-lib.api.txt}", - ":framework-connectivity{.module-lib.api.txt}", - ":framework-graphics{.module-lib.api.txt}", - ":framework-media{.module-lib.api.txt}", - ":framework-mediaprovider{.module-lib.api.txt}", - ":framework-permission{.module-lib.api.txt}", - ":framework-permission-s{.module-lib.api.txt}", - ":framework-scheduling{.module-lib.api.txt}", - ":framework-sdkextensions{.module-lib.api.txt}", - ":framework-statsd{.module-lib.api.txt}", - ":framework-tethering{.module-lib.api.txt}", - ":framework-wifi{.module-lib.api.txt}", - ":non-updatable-module-lib-current.txt", - ], - out: ["module-lib-current.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "module-lib-current.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/module-lib/api", - dest: "android.txt", - }, - ], -} - genrule { name: "frameworks-base-api-module-lib-current-compat", srcs: [ @@ -371,42 +183,6 @@ genrule { "$(location :frameworks-base-api-module-lib-current.txt)", } -genrule { - name: "frameworks-base-api-module-lib-removed.txt", - srcs: [ - ":art.module.public.api{.module-lib.removed-api.txt}", - ":android.net.ipsec.ike{.module-lib.removed-api.txt}", - ":framework-appsearch{.module-lib.removed-api.txt}", - ":framework-connectivity{.module-lib.removed-api.txt}", - ":framework-graphics{.module-lib.removed-api.txt}", - ":framework-media{.module-lib.removed-api.txt}", - ":framework-mediaprovider{.module-lib.removed-api.txt}", - ":framework-permission{.module-lib.removed-api.txt}", - ":framework-permission-s{.module-lib.removed-api.txt}", - ":framework-scheduling{.module-lib.removed-api.txt}", - ":framework-sdkextensions{.module-lib.removed-api.txt}", - ":framework-statsd{.module-lib.removed-api.txt}", - ":framework-tethering{.module-lib.removed-api.txt}", - ":framework-wifi{.module-lib.removed-api.txt}", - ":non-updatable-module-lib-removed.txt", - ], - out: ["module-lib-removed.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "module-lib-removed.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/module-lib/api", - dest: "removed.txt", - }, - ], -} - genrule { name: "combined-removed-dex", visibility: [ @@ -423,86 +199,3 @@ genrule { out: ["combined-removed-dex.txt"], cmd: "$(location gen_combined_removed_dex.sh) $(location metalava) $(genDir) $(in) > $(out)", } - -genrule { - name: "frameworks-base-api-system-server-current.txt", - srcs: [ - ":service-media-s{.system-server.api.txt}", - ":service-permission{.system-server.api.txt}", - ":non-updatable-system-server-current.txt", - ], - out: ["system-server-current.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "system-server-current.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/system-server/api", - dest: "android.txt", - }, - ], -} - -genrule { - name: "frameworks-base-api-system-server-removed.txt", - srcs: [ - ":service-media-s{.system-server.removed-api.txt}", - ":service-permission{.system-server.removed-api.txt}", - ":non-updatable-system-server-removed.txt", - ], - out: ["system-server-removed.txt"], - tools: ["metalava"], - cmd: metalava_cmd + "$(in) --api $(out)", - dists: [ - { - targets: ["droidcore"], - dir: "api", - dest: "system-server-removed.txt", - }, - { - targets: ["sdk"], - dir: "apistubs/android/system-server/api", - dest: "removed.txt", - }, - ], -} - -// This rule will filter classes present in the jar files of mainline modules -// from the lint database in api-versions.xml. -// This is done to reduce the number of false positive NewApi findings in -// java libraries that compile against the module SDK -genrule { - name: "api-versions-xml-public-filtered", - srcs: [ - // Note: order matters: first parameter is the full api-versions.xml - // after that the stubs files in any order - // stubs files are all modules that export API surfaces EXCEPT ART - ":framework-doc-stubs{.api_versions.xml}", - ":android.net.ipsec.ike.stubs{.jar}", - ":conscrypt.module.public.api.stubs{.jar}", - ":framework-appsearch.stubs{.jar}", - ":framework-connectivity.stubs{.jar}", - ":framework-graphics.stubs{.jar}", - ":framework-media.stubs{.jar}", - ":framework-mediaprovider.stubs{.jar}", - ":framework-permission.stubs{.jar}", - ":framework-permission-s.stubs{.jar}", - ":framework-scheduling.stubs{.jar}", - ":framework-sdkextensions.stubs{.jar}", - ":framework-statsd.stubs{.jar}", - ":framework-tethering.stubs{.jar}", - ":framework-wifi.stubs{.jar}", - ":i18n.module.public.api.stubs{.jar}", - ], - out: ["api-versions-public-filtered.xml"], - tools: ["api_versions_trimmer"], - cmd: "$(location api_versions_trimmer) $(out) $(in)", - dist: { - targets: ["sdk"], - }, -} From cc18e03e440124cc084f72ce7217b631d034333b Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 12 Jan 2022 14:45:22 +0000 Subject: [PATCH 2/7] Construct sdk-annotations.zip programmatically Avoid hardcoding the list of modules in yet another place. Bug: 169103987 Test: diff zip before & after (identical) Merged-In: Id3983bf5f4b96b23b1da09fd3617870ac3926ea1 Change-Id: Id3983bf5f4b96b23b1da09fd3617870ac3926ea1 --- ApiDocs.bp | 36 ------------------------------------ api/api.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/ApiDocs.bp b/ApiDocs.bp index 8af2e02f8d087..4a46a8222c27d 100644 --- a/ApiDocs.bp +++ b/ApiDocs.bp @@ -182,42 +182,6 @@ droidstubs { }, } -// This produces the same annotations.zip as framework-doc-stubs, but by using -// outputs from individual modules instead of all the source code. -genrule { - name: "sdk-annotations.zip", - srcs: [ - ":android-non-updatable-doc-stubs{.annotations.zip}", - - // Conscrypt and i18n currently do not enable annotations - // ":conscrypt.module.public.api{.public.annotations.zip}", - // ":i18n.module.public.api{.public.annotations.zip}", - - // Modules that enable annotations below - ":android.net.ipsec.ike{.public.annotations.zip}", - ":art.module.public.api{.public.annotations.zip}", - ":framework-appsearch{.public.annotations.zip}", - ":framework-connectivity{.public.annotations.zip}", - ":framework-graphics{.public.annotations.zip}", - ":framework-media{.public.annotations.zip}", - ":framework-mediaprovider{.public.annotations.zip}", - ":framework-permission{.public.annotations.zip}", - ":framework-permission-s{.public.annotations.zip}", - ":framework-scheduling{.public.annotations.zip}", - ":framework-sdkextensions{.public.annotations.zip}", - ":framework-statsd{.public.annotations.zip}", - ":framework-tethering{.public.annotations.zip}", - ":framework-wifi{.public.annotations.zip}", - ], - out: ["annotations.zip"], - tools: [ - "merge_annotation_zips", - "soong_zip", - ], - cmd: "$(location merge_annotation_zips) $(genDir)/out $(in) && " + - "$(location soong_zip) -o $(out) -C $(genDir)/out -D $(genDir)/out", -} - ///////////////////////////////////////////////////////////////////// // API docs are created from the generated stub source files // using droiddoc diff --git a/api/api.go b/api/api.go index 74cbece7ebf57..a61d5c2c34976 100644 --- a/api/api.go +++ b/api/api.go @@ -123,6 +123,19 @@ func createMergedStubsSrcjar(ctx android.LoadHookContext, modules []string) { ctx.CreateModule(genrule.GenRuleFactory, &props) } +// 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) { + props := genruleProps{} + props.Name = proptools.StringPtr("sdk-annotations.zip") + props.Tools = []string{"merge_annotation_zips", "soong_zip"} + props.Out = []string{"annotations.zip"} + props.Cmd = proptools.StringPtr("$(location merge_annotation_zips) $(genDir)/out $(in) && " + + "$(location soong_zip) -o $(out) -C $(genDir)/out -D $(genDir)/out") + props.Srcs = createSrcs(":android-non-updatable-doc-stubs{.annotations.zip}", modules, "{.public.annotations.zip}") + ctx.CreateModule(genrule.GenRuleFactory, &props) +} + func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { props := genruleProps{} props.Name = proptools.StringPtr("api-versions-xml-public-filtered") @@ -204,6 +217,12 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { createMergedStubsSrcjar(ctx, a.properties.Bootclasspath) + // Conscrypt and i18n currently do not enable annotations + annotationModules := a.properties.Bootclasspath + annotationModules = remove(annotationModules, "conscrypt.module.public.api") + annotationModules = remove(annotationModules, "i18n.module.public.api") + createMergedAnnotations(ctx, annotationModules) + // 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 From 07a1295cfa31271803e7e57b465b5a5178a9b093 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 12 Jan 2022 17:28:39 +0000 Subject: [PATCH 3/7] Temporarily add support for conditional modules Some bootclasspath libraries are currently conditionally included in the SDK. Add support for that in api.go. Bug: 169103987 Test: mmm frameworks/base/api Merged-In: I7704a884675eb58c429a59f99a663cf09807ecec Change-Id: I7704a884675eb58c429a59f99a663cf09807ecec --- api/api.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/api/api.go b/api/api.go index a61d5c2c34976..6cc129a360fd5 100644 --- a/api/api.go +++ b/api/api.go @@ -15,6 +15,8 @@ package api import ( + "sort" + "github.com/google/blueprint/proptools" "android/soong/android" @@ -32,6 +34,8 @@ import ( type CombinedApisProperties struct { // Module libraries in the bootclasspath Bootclasspath []string + // Module libraries on the bootclasspath if include_nonpublic_framework_api is true. + Conditional_bootclasspath []string // Module libraries in system server System_server_classpath []string } @@ -169,10 +173,10 @@ func remove(s []string, v string) []string { return s2 } -func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) { +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 := props.Bootclasspath + bcpWithSystemApi := bootclasspath bcpWithSystemApi = remove(bcpWithSystemApi, "conscrypt.module.public.api") bcpWithSystemApi = remove(bcpWithSystemApi, "i18n.module.public.api") @@ -181,7 +185,7 @@ func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) textFiles = append(textFiles, MergedTxtDefinition{ TxtFilename: f, BaseTxt: ":non-updatable-" + f, - Modules: props.Bootclasspath, + Modules: bootclasspath, ModuleTag: "{.public" + tagSuffix[i], Scope: "public", }) @@ -202,7 +206,7 @@ func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) textFiles = append(textFiles, MergedTxtDefinition{ TxtFilename: f, BaseTxt: ":non-updatable-system-server-" + f, - Modules: props.System_server_classpath, + Modules: system_server_classpath, ModuleTag: "{.system-server" + tagSuffix[i], Scope: "system-server", }) @@ -213,12 +217,17 @@ func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) } func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { - createMergedTxts(ctx, a.properties) + bootclasspath := a.properties.Bootclasspath + if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") { + bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...) + sort.Strings(bootclasspath) + } + createMergedTxts(ctx, bootclasspath, a.properties.System_server_classpath) - createMergedStubsSrcjar(ctx, a.properties.Bootclasspath) + createMergedStubsSrcjar(ctx, bootclasspath) // Conscrypt and i18n currently do not enable annotations - annotationModules := a.properties.Bootclasspath + annotationModules := bootclasspath annotationModules = remove(annotationModules, "conscrypt.module.public.api") annotationModules = remove(annotationModules, "i18n.module.public.api") createMergedAnnotations(ctx, annotationModules) @@ -230,7 +239,7 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { // 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 := a.properties.Bootclasspath + filteredModules := bootclasspath filteredModules = remove(filteredModules, "art.module.public.api") createFilteredApiVersions(ctx, filteredModules) } From 05e944d8df7da63f2921266d92e6e650d64160e7 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 13 Jan 2022 12:26:30 +0000 Subject: [PATCH 4/7] 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 Merged-In: Id81c93eafdbdbbd0f55a4a906150b58a001392f6 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 cb00f945962f9e6a18496de9897c6f81a5c41256 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 13 Jan 2022 09:45:12 +0000 Subject: [PATCH 5/7] 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. Merged-In: I6018791ae136bc764a6e846078c6bce59bcc123b Change-Id: I6018791ae136bc764a6e846078c6bce59bcc123b --- Android.bp | 21 --------------------- api/Android.bp | 1 + api/api.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Android.bp b/Android.bp index 79930abb4887e..457752c7b2bdb 100644 --- a/Android.bp +++ b/Android.bp @@ -140,27 +140,6 @@ filegroup { ], } -java_library { - 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-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-tethering.stubs.module_lib", - "framework-wifi.stubs.module_lib", - ], - sdk_version: "module_current", - visibility: ["//visibility:private"], -} - java_library { name: "framework-all", installable: false, diff --git a/api/Android.bp b/api/Android.bp index 663f9027ddc4d..d5d21052c3fee 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) From fd31645f856fe55872ea6379ce59dc62557d4a96 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Fri, 14 Jan 2022 11:15:52 +0000 Subject: [PATCH 6/7] Minor refactorings in api.go - Make a more generically useful "expandArray" function that can handle all the various transforms needed here (another one in the next cl). - Move all the utility functions to the bottom of the file. Test: presubmit Merged-In: If0362c6dd90635831ac2cb2f7da336212f4c23fd Change-Id: If0362c6dd90635831ac2cb2f7da336212f4c23fd --- api/api.go | 77 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/api/api.go b/api/api.go index 3b0e300c88f3c..e4c1b969226f2 100644 --- a/api/api.go +++ b/api/api.go @@ -111,7 +111,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { props.Tools = []string{"metalava"} props.Out = []string{filename} props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") - props.Srcs = createSrcs(txt.BaseTxt, txt.Modules, txt.ModuleTag) + props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...) props.Dists = []android.Dist{ { Targets: []string{"droidcore"}, @@ -134,7 +134,7 @@ func createMergedStubsSrcjar(ctx android.LoadHookContext, modules []string) { props.Tools = []string{"merge_zips"} props.Out = []string{"current.srcjar"} props.Cmd = proptools.StringPtr("$(location merge_zips) $(out) $(in)") - props.Srcs = createSrcs(":api-stubs-docs-non-updatable", modules, "{.public.stubs.source}") + props.Srcs = append([]string{":api-stubs-docs-non-updatable"}, createSrcs(modules, "{.public.stubs.source}")...) props.Visibility = []string{"//visibility:private"} // Used by make module in //development, mind ctx.CreateModule(genrule.GenRuleFactory, &props) } @@ -150,7 +150,7 @@ func createMergedAnnotations(ctx android.LoadHookContext, modules []string) { props.Out = []string{"annotations.zip"} props.Cmd = proptools.StringPtr("$(location merge_annotation_zips) $(genDir)/out $(in) && " + "$(location soong_zip) -o $(out) -C $(genDir)/out -D $(genDir)/out") - props.Srcs = createSrcs(":android-non-updatable-doc-stubs{.annotations.zip}", modules, "{.public.annotations.zip}") + props.Srcs = append([]string{":android-non-updatable-doc-stubs{.annotations.zip}"}, createSrcs(modules, "{.public.annotations.zip}")...) ctx.CreateModule(genrule.GenRuleFactory, &props) } @@ -172,7 +172,7 @@ func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { // Note: order matters: first parameter is the full api-versions.xml // after that the stubs files in any order // stubs files are all modules that export API surfaces EXCEPT ART - props.Srcs = createSrcs(":framework-doc-stubs{.api_versions.xml}", modules, ".stubs{.jar}") + props.Srcs = append([]string{":framework-doc-stubs{.api_versions.xml}"}, createSrcs(modules, ".stubs{.jar}")...) props.Dists = []android.Dist{{Targets: []string{"sdk"}}} ctx.CreateModule(genrule.GenRuleFactory, &props) } @@ -182,46 +182,12 @@ func createMergedModuleLibStubs(ctx android.LoadHookContext, modules []string) { 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.Static_libs = transformArray(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) - for _, module := range modules { - a = append(a, ":"+module+tag) - } - 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 { - if sv != v { - s2 = append(s2, sv) - } - } - return s2 -} - 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. @@ -287,3 +253,36 @@ func combinedApisModuleFactory() android.Module { android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) return module } + +// Various utility methods below. + +// Creates an array of ":" for each m in . +func createSrcs(modules []string, tag string) []string { + return transformArray(modules, ":", tag) +} + +// Creates an array of "", for each m in . +func transformArray(modules []string, prefix, suffix string) []string { + a := make([]string, 0, len(modules)) + for _, module := range modules { + a = append(a, prefix+module+suffix) + } + 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 { + if sv != v { + s2 = append(s2, sv) + } + } + return s2 +} From 4468d7c6bf2d83612909fb78ab5b90b13bb08443 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Fri, 14 Jan 2022 12:10:01 +0000 Subject: [PATCH 7/7] Create a filegroup for public stub sources For use by framework-doc-stubs, to avoid duplicating the list of modules there. Bug: 169103987 Test: m framework-doc-stubs ; diff intermediates before & after Merged-In: Ib1a1d1bb9fcf866278c6ddd057712a9c92716dbf Change-Id: Ib1a1d1bb9fcf866278c6ddd057712a9c92716dbf --- ApiDocs.bp | 25 +++++-------------------- api/api.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/ApiDocs.bp b/ApiDocs.bp index 4a46a8222c27d..b768093aac0bf 100644 --- a/ApiDocs.bp +++ b/ApiDocs.bp @@ -74,11 +74,6 @@ stubs_defaults { srcs: [ ":android-non-updatable-stub-sources", - // Module sources - ":art.module.public.api{.public.stubs.source}", - ":conscrypt.module.public.api{.public.stubs.source}", - ":i18n.module.public.api{.public.stubs.source}", - // No longer part of the stubs, but are included in the docs. ":android-test-base-sources", ":android-test-mock-sources", @@ -116,6 +111,10 @@ stubs_defaults { name: "framework-doc-stubs-sources-default", defaults: ["framework-doc-stubs-default"], srcs: [ + ":art.module.public.api{.public.stubs.source}", + ":conscrypt.module.public.api{.public.stubs.source}", + ":i18n.module.public.api{.public.stubs.source}", + ":framework-appsearch-sources", ":framework-connectivity-sources", ":framework-graphics-srcs", @@ -156,22 +155,8 @@ droidstubs { droidstubs { name: "framework-doc-stubs", defaults: ["framework-doc-stubs-default"], + srcs: [":all-modules-public-stubs-source"], args: metalava_framework_docs_args, - srcs: [ - ":android.net.ipsec.ike{.public.stubs.source}", - ":framework-appsearch{.public.stubs.source}", - ":framework-connectivity{.public.stubs.source}", - ":framework-graphics{.public.stubs.source}", - ":framework-media{.public.stubs.source}", - ":framework-mediaprovider{.public.stubs.source}", - ":framework-permission{.public.stubs.source}", - ":framework-permission-s{.public.stubs.source}", - ":framework-scheduling{.public.stubs.source}", - ":framework-sdkextensions{.public.stubs.source}", - ":framework-statsd{.public.stubs.source}", - ":framework-tethering{.public.stubs.source}", - ":framework-wifi{.public.stubs.source}", - ], aidl: { local_include_dirs: [ "apex/media/aidl/stable", diff --git a/api/api.go b/api/api.go index e4c1b969226f2..4b6ebc1947e9d 100644 --- a/api/api.go +++ b/api/api.go @@ -81,6 +81,12 @@ type libraryProps struct { Visibility []string } +type fgProps struct { + Name *string + Srcs []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" @@ -188,6 +194,14 @@ func createMergedModuleLibStubs(ctx android.LoadHookContext, modules []string) { ctx.CreateModule(java.LibraryFactory, &props) } +func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) { + props := fgProps{} + props.Name = proptools.StringPtr("all-modules-public-stubs-source") + props.Srcs = createSrcs(modules, "{.public.stubs.source}") + props.Visibility = []string{"//frameworks/base"} + ctx.CreateModule(android.FileGroupFactory, &props) +} + 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. @@ -244,6 +258,8 @@ func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { createMergedAnnotations(ctx, bootclasspath) createFilteredApiVersions(ctx, bootclasspath) + + createPublicStubsSourceFilegroup(ctx, bootclasspath) } func combinedApisModuleFactory() android.Module {