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
diff --git a/api/api.go b/api/api.go
index 3b0e300..e4c1b96 100644
--- a/api/api.go
+++ b/api/api.go
@@ -111,7 +111,7 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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
+}