Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package api |
| 16 | |
| 17 | import ( |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 18 | "sort" |
| 19 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 20 | "github.com/google/blueprint/proptools" |
| 21 | |
| 22 | "android/soong/android" |
| 23 | "android/soong/genrule" |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 24 | "android/soong/java" |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 25 | ) |
| 26 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 27 | const art = "art.module.public.api" |
| 28 | const conscrypt = "conscrypt.module.public.api" |
| 29 | const i18n = "i18n.module.public.api" |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 30 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 31 | var core_libraries_modules = []string{art, conscrypt, i18n} |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 32 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 33 | // The intention behind this soong plugin is to generate a number of "merged" |
| 34 | // API-related modules that would otherwise require a large amount of very |
| 35 | // similar Android.bp boilerplate to define. For example, the merged current.txt |
| 36 | // API definitions (created by merging the non-updatable current.txt with all |
| 37 | // the module current.txts). This simplifies the addition of new android |
| 38 | // modules, by reducing the number of genrules etc a new module must be added to. |
| 39 | |
| 40 | // The properties of the combined_apis module type. |
| 41 | type CombinedApisProperties struct { |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 42 | // Module libraries in the bootclasspath |
| 43 | Bootclasspath []string |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 44 | // Module libraries on the bootclasspath if include_nonpublic_framework_api is true. |
| 45 | Conditional_bootclasspath []string |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 46 | // Module libraries in system server |
| 47 | System_server_classpath []string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | type CombinedApis struct { |
| 51 | android.ModuleBase |
| 52 | |
| 53 | properties CombinedApisProperties |
| 54 | } |
| 55 | |
| 56 | func init() { |
| 57 | registerBuildComponents(android.InitRegistrationContext) |
| 58 | } |
| 59 | |
| 60 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 61 | ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory) |
| 62 | } |
| 63 | |
| 64 | var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents) |
| 65 | |
| 66 | func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 67 | } |
| 68 | |
| 69 | type genruleProps struct { |
| 70 | Name *string |
| 71 | Cmd *string |
| 72 | Dists []android.Dist |
| 73 | Out []string |
| 74 | Srcs []string |
| 75 | Tools []string |
| 76 | Visibility []string |
| 77 | } |
| 78 | |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 79 | type libraryProps struct { |
| 80 | Name *string |
| 81 | Sdk_version *string |
| 82 | Static_libs []string |
| 83 | Visibility []string |
| 84 | } |
| 85 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 86 | type fgProps struct { |
| 87 | Name *string |
| 88 | Srcs []string |
| 89 | Visibility []string |
| 90 | } |
| 91 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 92 | // Struct to pass parameters for the various merged [current|removed].txt file modules we create. |
| 93 | type MergedTxtDefinition struct { |
| 94 | // "current.txt" or "removed.txt" |
| 95 | TxtFilename string |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 96 | // Filename in the new dist dir. "android.txt" or "android-removed.txt" |
| 97 | DistFilename string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 98 | // The module for the non-updatable / non-module part of the api. |
| 99 | BaseTxt string |
| 100 | // The list of modules that are relevant for this merged txt. |
| 101 | Modules []string |
| 102 | // The output tag for each module to use.e.g. {.public.api.txt} for current.txt |
| 103 | ModuleTag string |
| 104 | // public, system, module-lib or system-server |
| 105 | Scope string |
| 106 | } |
| 107 | |
| 108 | func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { |
| 109 | metalavaCmd := "$(location metalava)" |
| 110 | // Silence reflection warnings. See b/168689341 |
| 111 | metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " |
| 112 | metalavaCmd += " --quiet --no-banner --format=v2 " |
| 113 | |
| 114 | filename := txt.TxtFilename |
| 115 | if txt.Scope != "public" { |
| 116 | filename = txt.Scope + "-" + filename |
| 117 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 118 | props := genruleProps{} |
| 119 | props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename) |
| 120 | props.Tools = []string{"metalava"} |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 121 | props.Out = []string{filename} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 122 | props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 123 | props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 124 | props.Dists = []android.Dist{ |
| 125 | { |
| 126 | Targets: []string{"droidcore"}, |
| 127 | Dir: proptools.StringPtr("api"), |
| 128 | Dest: proptools.StringPtr(filename), |
| 129 | }, |
| 130 | { |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 131 | Targets: []string{"api_txt", "sdk"}, |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 132 | Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"), |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 133 | Dest: proptools.StringPtr(txt.DistFilename), |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 134 | }, |
| 135 | } |
| 136 | props.Visibility = []string{"//visibility:public"} |
| 137 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 138 | } |
| 139 | |
| 140 | func createMergedStubsSrcjar(ctx android.LoadHookContext, modules []string) { |
| 141 | props := genruleProps{} |
| 142 | props.Name = proptools.StringPtr(ctx.ModuleName() + "-current.srcjar") |
| 143 | props.Tools = []string{"merge_zips"} |
| 144 | props.Out = []string{"current.srcjar"} |
| 145 | props.Cmd = proptools.StringPtr("$(location merge_zips) $(out) $(in)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 146 | props.Srcs = append([]string{":api-stubs-docs-non-updatable"}, createSrcs(modules, "{.public.stubs.source}")...) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 147 | props.Visibility = []string{"//visibility:private"} // Used by make module in //development, mind |
| 148 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 149 | } |
| 150 | |
Anton Hansson | 0c5d9ab | 2022-06-23 07:58:51 +0000 | [diff] [blame] | 151 | func createMergedPublicAnnotationsFilegroup(ctx android.LoadHookContext, modules []string) { |
| 152 | props := fgProps{} |
| 153 | props.Name = proptools.StringPtr("all-modules-public-annotations") |
| 154 | props.Srcs = createSrcs(modules, "{.public.annotations.zip}") |
| 155 | ctx.CreateModule(android.FileGroupFactory, &props) |
Anton Hansson | cc18e03 | 2022-01-12 14:45:22 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Anton Hansson | 74b1564 | 2022-06-23 08:27:23 +0000 | [diff] [blame^] | 158 | func createMergedSystemAnnotationsFilegroup(ctx android.LoadHookContext, modules []string) { |
| 159 | props := fgProps{} |
| 160 | props.Name = proptools.StringPtr("all-modules-system-annotations") |
| 161 | props.Srcs = createSrcs(modules, "{.system.annotations.zip}") |
| 162 | ctx.CreateModule(android.FileGroupFactory, &props) |
| 163 | } |
| 164 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 165 | func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 166 | // For the filtered api versions, we prune all APIs except art module's APIs. because |
| 167 | // 1) ART apis are available by default to all modules, while other module-to-module deps are |
| 168 | // explicit and probably receive more scrutiny anyway |
| 169 | // 2) The number of ART/libcore APIs is large, so not linting them would create a large gap |
| 170 | // 3) It's a compromise. Ideally we wouldn't be filtering out any module APIs, and have |
| 171 | // per-module lint databases that excludes just that module's APIs. Alas, that's more |
| 172 | // difficult to achieve. |
| 173 | modules = remove(modules, art) |
| 174 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 175 | props := genruleProps{} |
| 176 | props.Name = proptools.StringPtr("api-versions-xml-public-filtered") |
| 177 | props.Tools = []string{"api_versions_trimmer"} |
| 178 | props.Out = []string{"api-versions-public-filtered.xml"} |
| 179 | props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)") |
| 180 | // Note: order matters: first parameter is the full api-versions.xml |
| 181 | // after that the stubs files in any order |
| 182 | // stubs files are all modules that export API surfaces EXCEPT ART |
Anton Hansson | 247c5f2 | 2022-05-09 09:53:12 +0000 | [diff] [blame] | 183 | props.Srcs = append([]string{":api_versions_public{.api_versions.xml}"}, createSrcs(modules, ".stubs{.jar}")...) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 184 | props.Dists = []android.Dist{{Targets: []string{"sdk"}}} |
| 185 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 186 | } |
| 187 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 188 | func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) { |
| 189 | props := libraryProps{} |
| 190 | props.Name = proptools.StringPtr("all-modules-public-stubs") |
| 191 | props.Static_libs = transformArray(modules, "", ".stubs") |
| 192 | props.Sdk_version = proptools.StringPtr("module_current") |
| 193 | props.Visibility = []string{"//frameworks/base"} |
| 194 | ctx.CreateModule(java.LibraryFactory, &props) |
| 195 | } |
| 196 | |
| 197 | func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) { |
| 198 | props := libraryProps{} |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 199 | props.Name = proptools.StringPtr("all-modules-system-stubs") |
Paul Duffin | 57533b4 | 2022-01-25 16:25:35 +0000 | [diff] [blame] | 200 | props.Static_libs = transformArray(modules, "", ".stubs.system") |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 201 | props.Sdk_version = proptools.StringPtr("module_current") |
| 202 | props.Visibility = []string{"//frameworks/base"} |
| 203 | ctx.CreateModule(java.LibraryFactory, &props) |
| 204 | } |
| 205 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 206 | func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) { |
| 207 | // This module is for the "framework-all" module, which should not include the core libraries. |
| 208 | modules = removeAll(modules, core_libraries_modules) |
| 209 | // TODO(b/214988855): remove the line below when framework-bluetooth has an impl jar. |
| 210 | modules = remove(modules, "framework-bluetooth") |
| 211 | props := libraryProps{} |
| 212 | props.Name = proptools.StringPtr("all-framework-module-impl") |
| 213 | props.Static_libs = transformArray(modules, "", ".impl") |
| 214 | // Media module's impl jar is called "updatable-media" |
| 215 | for i, v := range props.Static_libs { |
| 216 | if v == "framework-media.impl" { |
| 217 | props.Static_libs[i] = "updatable-media" |
| 218 | } |
| 219 | } |
| 220 | props.Sdk_version = proptools.StringPtr("module_current") |
| 221 | props.Visibility = []string{"//frameworks/base"} |
| 222 | ctx.CreateModule(java.LibraryFactory, &props) |
| 223 | } |
| 224 | |
| 225 | func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 226 | // The user of this module compiles against the "core" SDK, so remove core libraries to avoid dupes. |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 227 | modules = removeAll(modules, core_libraries_modules) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 228 | props := libraryProps{} |
| 229 | props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 230 | props.Static_libs = transformArray(modules, "", ".stubs.module_lib") |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 231 | props.Sdk_version = proptools.StringPtr("module_current") |
| 232 | props.Visibility = []string{"//frameworks/base"} |
| 233 | ctx.CreateModule(java.LibraryFactory, &props) |
| 234 | } |
| 235 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 236 | func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) { |
| 237 | props := fgProps{} |
| 238 | props.Name = proptools.StringPtr("all-modules-public-stubs-source") |
| 239 | props.Srcs = createSrcs(modules, "{.public.stubs.source}") |
| 240 | props.Visibility = []string{"//frameworks/base"} |
| 241 | ctx.CreateModule(android.FileGroupFactory, &props) |
| 242 | } |
| 243 | |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 244 | func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 245 | var textFiles []MergedTxtDefinition |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 246 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 247 | tagSuffix := []string{".api.txt}", ".removed-api.txt}"} |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 248 | distFilename := []string{"android.txt", "android-removed.txt"} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 249 | for i, f := range []string{"current.txt", "removed.txt"} { |
| 250 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 251 | TxtFilename: f, |
| 252 | DistFilename: distFilename[i], |
| 253 | BaseTxt: ":non-updatable-" + f, |
| 254 | Modules: bootclasspath, |
| 255 | ModuleTag: "{.public" + tagSuffix[i], |
| 256 | Scope: "public", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 257 | }) |
| 258 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 259 | TxtFilename: f, |
| 260 | DistFilename: distFilename[i], |
| 261 | BaseTxt: ":non-updatable-system-" + f, |
| 262 | Modules: bootclasspath, |
| 263 | ModuleTag: "{.system" + tagSuffix[i], |
| 264 | Scope: "system", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 265 | }) |
| 266 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 267 | TxtFilename: f, |
| 268 | DistFilename: distFilename[i], |
| 269 | BaseTxt: ":non-updatable-module-lib-" + f, |
| 270 | Modules: bootclasspath, |
| 271 | ModuleTag: "{.module-lib" + tagSuffix[i], |
| 272 | Scope: "module-lib", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 273 | }) |
| 274 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 275 | TxtFilename: f, |
| 276 | DistFilename: distFilename[i], |
| 277 | BaseTxt: ":non-updatable-system-server-" + f, |
| 278 | Modules: system_server_classpath, |
| 279 | ModuleTag: "{.system-server" + tagSuffix[i], |
| 280 | Scope: "system-server", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 281 | }) |
| 282 | } |
| 283 | for _, txt := range textFiles { |
| 284 | createMergedTxt(ctx, txt) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 289 | bootclasspath := a.properties.Bootclasspath |
| 290 | if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") { |
| 291 | bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...) |
| 292 | sort.Strings(bootclasspath) |
| 293 | } |
| 294 | createMergedTxts(ctx, bootclasspath, a.properties.System_server_classpath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 295 | |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 296 | createMergedStubsSrcjar(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 297 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 298 | createMergedPublicStubs(ctx, bootclasspath) |
| 299 | createMergedSystemStubs(ctx, bootclasspath) |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 300 | createMergedFrameworkModuleLibStubs(ctx, bootclasspath) |
| 301 | createMergedFrameworkImpl(ctx, bootclasspath) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 302 | |
Anton Hansson | 0c5d9ab | 2022-06-23 07:58:51 +0000 | [diff] [blame] | 303 | createMergedPublicAnnotationsFilegroup(ctx, bootclasspath) |
Anton Hansson | 74b1564 | 2022-06-23 08:27:23 +0000 | [diff] [blame^] | 304 | createMergedSystemAnnotationsFilegroup(ctx, bootclasspath) |
Anton Hansson | cc18e03 | 2022-01-12 14:45:22 +0000 | [diff] [blame] | 305 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 306 | createFilteredApiVersions(ctx, bootclasspath) |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 307 | |
| 308 | createPublicStubsSourceFilegroup(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | func combinedApisModuleFactory() android.Module { |
| 312 | module := &CombinedApis{} |
| 313 | module.AddProperties(&module.properties) |
| 314 | android.InitAndroidModule(module) |
| 315 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) |
| 316 | return module |
| 317 | } |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 318 | |
| 319 | // Various utility methods below. |
| 320 | |
| 321 | // Creates an array of ":<m><tag>" for each m in <modules>. |
| 322 | func createSrcs(modules []string, tag string) []string { |
| 323 | return transformArray(modules, ":", tag) |
| 324 | } |
| 325 | |
| 326 | // Creates an array of "<prefix><m><suffix>", for each m in <modules>. |
| 327 | func transformArray(modules []string, prefix, suffix string) []string { |
| 328 | a := make([]string, 0, len(modules)) |
| 329 | for _, module := range modules { |
| 330 | a = append(a, prefix+module+suffix) |
| 331 | } |
| 332 | return a |
| 333 | } |
| 334 | |
| 335 | func removeAll(s []string, vs []string) []string { |
| 336 | for _, v := range vs { |
| 337 | s = remove(s, v) |
| 338 | } |
| 339 | return s |
| 340 | } |
| 341 | |
| 342 | func remove(s []string, v string) []string { |
| 343 | s2 := make([]string, 0, len(s)) |
| 344 | for _, sv := range s { |
| 345 | if sv != v { |
| 346 | s2 = append(s2, sv) |
| 347 | } |
| 348 | } |
| 349 | return s2 |
| 350 | } |