summaryrefslogtreecommitdiff
path: root/api/api.go
diff options
context:
space:
mode:
author Anton Hansson <hansson@google.com> 2022-01-14 11:15:52 +0000
committer Anton Hansson <hansson@google.com> 2022-01-17 19:07:10 +0000
commitfd31645f856fe55872ea6379ce59dc62557d4a96 (patch)
treec79f368e781d02950621a5433e64fd6181f15a95 /api/api.go
parentcb00f945962f9e6a18496de9897c6f81a5c41256 (diff)
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
Diffstat (limited to 'api/api.go')
-rw-r--r--api/api.go77
1 files changed, 38 insertions, 39 deletions
diff --git a/api/api.go b/api/api.go
index 3b0e300c88f3..e4c1b969226f 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 ":<m><tag>" for each m in <modules>.
+func createSrcs(modules []string, tag string) []string {
+ return transformArray(modules, ":", tag)
+}
+
+// Creates an array of "<prefix><m><suffix>", for each m in <modules>.
+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
+}