Merge "Refactor api.go to simplify Android.bp further" am: aa2823a482

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1947111

Change-Id: If361fe19ce2c69454dae92f8149631dcce35419a
This commit is contained in:
Treehugger Robot
2022-01-13 11:25:07 +00:00
committed by Automerger Merge Worker

View File

@@ -30,22 +30,10 @@ import (
// The properties of the combined_apis module type. // The properties of the combined_apis module type.
type CombinedApisProperties struct { type CombinedApisProperties struct {
// Module libraries that have public APIs // Module libraries in the bootclasspath
Public []string Bootclasspath []string
// Module libraries that have system APIs // Module libraries in system server
System []string System_server_classpath []string
// Module libraries that have module_library APIs
Module_lib []string
// Module libraries that have system_server APIs
System_server []string
// ART module library. The only API library not removed from the filtered api database, 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.
Art_module string
} }
type CombinedApis struct { type CombinedApis struct {
@@ -105,7 +93,7 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) {
props := genruleProps{} props := genruleProps{}
props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename) props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename)
props.Tools = []string{"metalava"} props.Tools = []string{"metalava"}
props.Out = []string{txt.TxtFilename} props.Out = []string{filename}
props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)")
props.Srcs = createSrcs(txt.BaseTxt, txt.Modules, txt.ModuleTag) props.Srcs = createSrcs(txt.BaseTxt, txt.Modules, txt.ModuleTag)
props.Dists = []android.Dist{ props.Dists = []android.Dist{
@@ -170,33 +158,38 @@ func remove(s []string, v string) []string {
func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) { func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties) {
var textFiles []MergedTxtDefinition var textFiles []MergedTxtDefinition
// Two module libraries currently do not support @SystemApi so only have the public scope.
bcpWithSystemApi := props.Bootclasspath
bcpWithSystemApi = remove(bcpWithSystemApi, "conscrypt.module.public.api")
bcpWithSystemApi = remove(bcpWithSystemApi, "i18n.module.public.api")
tagSuffix := []string{".api.txt}", ".removed-api.txt}"} tagSuffix := []string{".api.txt}", ".removed-api.txt}"}
for i, f := range []string{"current.txt", "removed.txt"} { for i, f := range []string{"current.txt", "removed.txt"} {
textFiles = append(textFiles, MergedTxtDefinition{ textFiles = append(textFiles, MergedTxtDefinition{
TxtFilename: f, TxtFilename: f,
BaseTxt: ":non-updatable-" + f, BaseTxt: ":non-updatable-" + f,
Modules: props.Public, Modules: props.Bootclasspath,
ModuleTag: "{.public" + tagSuffix[i], ModuleTag: "{.public" + tagSuffix[i],
Scope: "public", Scope: "public",
}) })
textFiles = append(textFiles, MergedTxtDefinition{ textFiles = append(textFiles, MergedTxtDefinition{
TxtFilename: f, TxtFilename: f,
BaseTxt: ":non-updatable-system-" + f, BaseTxt: ":non-updatable-system-" + f,
Modules: props.System, Modules: bcpWithSystemApi,
ModuleTag: "{.system" + tagSuffix[i], ModuleTag: "{.system" + tagSuffix[i],
Scope: "system", Scope: "system",
}) })
textFiles = append(textFiles, MergedTxtDefinition{ textFiles = append(textFiles, MergedTxtDefinition{
TxtFilename: f, TxtFilename: f,
BaseTxt: ":non-updatable-module-lib-" + f, BaseTxt: ":non-updatable-module-lib-" + f,
Modules: props.Module_lib, Modules: bcpWithSystemApi,
ModuleTag: "{.module-lib" + tagSuffix[i], ModuleTag: "{.module-lib" + tagSuffix[i],
Scope: "module-lib", Scope: "module-lib",
}) })
textFiles = append(textFiles, MergedTxtDefinition{ textFiles = append(textFiles, MergedTxtDefinition{
TxtFilename: f, TxtFilename: f,
BaseTxt: ":non-updatable-system-server-" + f, BaseTxt: ":non-updatable-system-server-" + f,
Modules: props.System_server, Modules: props.System_server_classpath,
ModuleTag: "{.system-server" + tagSuffix[i], ModuleTag: "{.system-server" + tagSuffix[i],
Scope: "system-server", Scope: "system-server",
}) })
@@ -209,10 +202,18 @@ func createMergedTxts(ctx android.LoadHookContext, props CombinedApisProperties)
func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) {
createMergedTxts(ctx, a.properties) createMergedTxts(ctx, a.properties)
createMergedStubsSrcjar(ctx, a.properties.Public) createMergedStubsSrcjar(ctx, a.properties.Bootclasspath)
// For the filtered api versions, we prune all APIs except art module's APIs. // For the filtered api versions, we prune all APIs except art module's APIs. because
createFilteredApiVersions(ctx, remove(a.properties.Public, a.properties.Art_module)) // 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 := a.properties.Bootclasspath
filteredModules = remove(filteredModules, "art.module.public.api")
createFilteredApiVersions(ctx, filteredModules)
} }
func combinedApisModuleFactory() android.Module { func combinedApisModuleFactory() android.Module {