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" |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 30 | const virtualization = "framework-virtualization" |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 31 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 32 | var core_libraries_modules = []string{art, conscrypt, i18n} |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 33 | // List of modules that are not yet updatable, and hence they can still compile |
| 34 | // against hidden APIs. These modules are filtered out when building the |
| 35 | // updatable-framework-module-impl (because updatable-framework-module-impl is |
| 36 | // built against module_current SDK). Instead they are directly statically |
| 37 | // linked into the all-framework-module-lib, which is building against hidden |
| 38 | // APIs. |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame^] | 39 | // In addition, the modules in this list are allowed to contribute to test APIs |
| 40 | // stubs. |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 41 | var non_updatable_modules = []string{virtualization} |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 42 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 43 | // The intention behind this soong plugin is to generate a number of "merged" |
| 44 | // API-related modules that would otherwise require a large amount of very |
| 45 | // similar Android.bp boilerplate to define. For example, the merged current.txt |
| 46 | // API definitions (created by merging the non-updatable current.txt with all |
| 47 | // the module current.txts). This simplifies the addition of new android |
| 48 | // modules, by reducing the number of genrules etc a new module must be added to. |
| 49 | |
| 50 | // The properties of the combined_apis module type. |
| 51 | type CombinedApisProperties struct { |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 52 | // Module libraries in the bootclasspath |
| 53 | Bootclasspath []string |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 54 | // Module libraries on the bootclasspath if include_nonpublic_framework_api is true. |
| 55 | Conditional_bootclasspath []string |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 56 | // Module libraries in system server |
| 57 | System_server_classpath []string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | type CombinedApis struct { |
| 61 | android.ModuleBase |
| 62 | |
| 63 | properties CombinedApisProperties |
| 64 | } |
| 65 | |
| 66 | func init() { |
| 67 | registerBuildComponents(android.InitRegistrationContext) |
| 68 | } |
| 69 | |
| 70 | func registerBuildComponents(ctx android.RegistrationContext) { |
| 71 | ctx.RegisterModuleType("combined_apis", combinedApisModuleFactory) |
| 72 | } |
| 73 | |
| 74 | var PrepareForCombinedApisTest = android.FixtureRegisterWithContext(registerBuildComponents) |
| 75 | |
| 76 | func (a *CombinedApis) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 77 | } |
| 78 | |
| 79 | type genruleProps struct { |
| 80 | Name *string |
| 81 | Cmd *string |
| 82 | Dists []android.Dist |
| 83 | Out []string |
| 84 | Srcs []string |
| 85 | Tools []string |
| 86 | Visibility []string |
| 87 | } |
| 88 | |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 89 | type libraryProps struct { |
| 90 | Name *string |
| 91 | Sdk_version *string |
| 92 | Static_libs []string |
| 93 | Visibility []string |
| 94 | } |
| 95 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 96 | type fgProps struct { |
| 97 | Name *string |
| 98 | Srcs []string |
| 99 | Visibility []string |
| 100 | } |
| 101 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 102 | // Struct to pass parameters for the various merged [current|removed].txt file modules we create. |
| 103 | type MergedTxtDefinition struct { |
| 104 | // "current.txt" or "removed.txt" |
| 105 | TxtFilename string |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 106 | // Filename in the new dist dir. "android.txt" or "android-removed.txt" |
| 107 | DistFilename string |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 108 | // The module for the non-updatable / non-module part of the api. |
| 109 | BaseTxt string |
| 110 | // The list of modules that are relevant for this merged txt. |
| 111 | Modules []string |
| 112 | // The output tag for each module to use.e.g. {.public.api.txt} for current.txt |
| 113 | ModuleTag string |
| 114 | // public, system, module-lib or system-server |
| 115 | Scope string |
| 116 | } |
| 117 | |
| 118 | func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { |
| 119 | metalavaCmd := "$(location metalava)" |
| 120 | // Silence reflection warnings. See b/168689341 |
| 121 | metalavaCmd += " -J--add-opens=java.base/java.util=ALL-UNNAMED " |
| 122 | metalavaCmd += " --quiet --no-banner --format=v2 " |
| 123 | |
| 124 | filename := txt.TxtFilename |
| 125 | if txt.Scope != "public" { |
| 126 | filename = txt.Scope + "-" + filename |
| 127 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 128 | props := genruleProps{} |
| 129 | props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename) |
| 130 | props.Tools = []string{"metalava"} |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 131 | props.Out = []string{filename} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 132 | props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --api $(out)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 133 | props.Srcs = append([]string{txt.BaseTxt}, createSrcs(txt.Modules, txt.ModuleTag)...) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 134 | props.Dists = []android.Dist{ |
| 135 | { |
| 136 | Targets: []string{"droidcore"}, |
| 137 | Dir: proptools.StringPtr("api"), |
| 138 | Dest: proptools.StringPtr(filename), |
| 139 | }, |
| 140 | { |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 141 | Targets: []string{"api_txt", "sdk"}, |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 142 | Dir: proptools.StringPtr("apistubs/android/" + txt.Scope + "/api"), |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 143 | Dest: proptools.StringPtr(txt.DistFilename), |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 144 | }, |
| 145 | } |
| 146 | props.Visibility = []string{"//visibility:public"} |
| 147 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 148 | } |
| 149 | |
| 150 | func createMergedStubsSrcjar(ctx android.LoadHookContext, modules []string) { |
| 151 | props := genruleProps{} |
| 152 | props.Name = proptools.StringPtr(ctx.ModuleName() + "-current.srcjar") |
| 153 | props.Tools = []string{"merge_zips"} |
| 154 | props.Out = []string{"current.srcjar"} |
| 155 | props.Cmd = proptools.StringPtr("$(location merge_zips) $(out) $(in)") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 156 | 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] | 157 | props.Visibility = []string{"//visibility:private"} // Used by make module in //development, mind |
| 158 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 159 | } |
| 160 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 161 | func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { |
| 162 | for _, i := range []struct{ |
| 163 | name string |
| 164 | tag string |
| 165 | modules []string |
| 166 | }{ |
| 167 | { |
| 168 | name: "all-modules-public-annotations", |
| 169 | tag: "{.public.annotations.zip}", |
| 170 | modules: modules, |
| 171 | }, { |
| 172 | name: "all-modules-system-annotations", |
| 173 | tag: "{.system.annotations.zip}", |
| 174 | modules: modules, |
| 175 | }, { |
| 176 | name: "all-modules-module-lib-annotations", |
| 177 | tag: "{.module-lib.annotations.zip}", |
| 178 | modules: modules, |
| 179 | }, { |
| 180 | name: "all-modules-system-server-annotations", |
| 181 | tag: "{.system-server.annotations.zip}", |
| 182 | modules: system_server_modules, |
| 183 | }, |
| 184 | } { |
| 185 | props := fgProps{} |
| 186 | props.Name = proptools.StringPtr(i.name) |
| 187 | props.Srcs = createSrcs(i.modules, i.tag) |
| 188 | ctx.CreateModule(android.FileGroupFactory, &props) |
| 189 | } |
Anton Hansson | 74b1564 | 2022-06-23 08:27:23 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 192 | func createFilteredApiVersions(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 193 | // For the filtered api versions, we prune all APIs except art module's APIs. because |
| 194 | // 1) ART apis are available by default to all modules, while other module-to-module deps are |
| 195 | // explicit and probably receive more scrutiny anyway |
| 196 | // 2) The number of ART/libcore APIs is large, so not linting them would create a large gap |
| 197 | // 3) It's a compromise. Ideally we wouldn't be filtering out any module APIs, and have |
| 198 | // per-module lint databases that excludes just that module's APIs. Alas, that's more |
| 199 | // difficult to achieve. |
| 200 | modules = remove(modules, art) |
| 201 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 202 | for _, i := range []struct{ |
| 203 | name string |
| 204 | out string |
| 205 | in string |
| 206 | }{ |
| 207 | { |
| 208 | // We shouldn't need public-filtered or system-filtered. |
| 209 | // public-filtered is currently used to lint things that |
| 210 | // use the module sdk or the system server sdk, but those |
| 211 | // should be switched over to module-filtered and |
| 212 | // system-server-filtered, and then public-filtered can |
| 213 | // be removed. |
| 214 | name: "api-versions-xml-public-filtered", |
| 215 | out: "api-versions-public-filtered.xml", |
| 216 | in: ":api_versions_public{.api_versions.xml}", |
| 217 | }, { |
| 218 | name: "api-versions-xml-module-lib-filtered", |
| 219 | out: "api-versions-module-lib-filtered.xml", |
| 220 | in: ":api_versions_module_lib{.api_versions.xml}", |
| 221 | }, { |
| 222 | name: "api-versions-xml-system-server-filtered", |
| 223 | out: "api-versions-system-server-filtered.xml", |
| 224 | in: ":api_versions_system_server{.api_versions.xml}", |
| 225 | }, |
| 226 | } { |
| 227 | props := genruleProps{} |
| 228 | props.Name = proptools.StringPtr(i.name) |
| 229 | props.Out = []string{i.out} |
| 230 | // Note: order matters: first parameter is the full api-versions.xml |
| 231 | // after that the stubs files in any order |
| 232 | // stubs files are all modules that export API surfaces EXCEPT ART |
| 233 | props.Srcs = append([]string{i.in}, createSrcs(modules, ".stubs{.jar}")...) |
| 234 | props.Tools = []string{"api_versions_trimmer"} |
| 235 | props.Cmd = proptools.StringPtr("$(location api_versions_trimmer) $(out) $(in)") |
| 236 | props.Dists = []android.Dist{{Targets: []string{"sdk"}}} |
| 237 | ctx.CreateModule(genrule.GenRuleFactory, &props) |
| 238 | } |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 241 | func createMergedPublicStubs(ctx android.LoadHookContext, modules []string) { |
| 242 | props := libraryProps{} |
| 243 | props.Name = proptools.StringPtr("all-modules-public-stubs") |
| 244 | props.Static_libs = transformArray(modules, "", ".stubs") |
| 245 | props.Sdk_version = proptools.StringPtr("module_current") |
| 246 | props.Visibility = []string{"//frameworks/base"} |
| 247 | ctx.CreateModule(java.LibraryFactory, &props) |
| 248 | } |
| 249 | |
| 250 | func createMergedSystemStubs(ctx android.LoadHookContext, modules []string) { |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame^] | 251 | // First create the all-updatable-modules-system-stubs |
| 252 | { |
| 253 | updatable_modules := removeAll(modules, non_updatable_modules) |
| 254 | props := libraryProps{} |
| 255 | props.Name = proptools.StringPtr("all-updatable-modules-system-stubs") |
| 256 | props.Static_libs = transformArray(updatable_modules, "", ".stubs.system") |
| 257 | props.Sdk_version = proptools.StringPtr("module_current") |
| 258 | props.Visibility = []string{"//frameworks/base"} |
| 259 | ctx.CreateModule(java.LibraryFactory, &props) |
| 260 | } |
| 261 | // Now merge all-updatable-modules-system-stubs and stubs from non-updatable modules |
| 262 | // into all-modules-system-stubs. |
| 263 | { |
| 264 | props := libraryProps{} |
| 265 | props.Name = proptools.StringPtr("all-modules-system-stubs") |
| 266 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.system") |
| 267 | props.Static_libs = append(props.Static_libs, "all-updatable-modules-system-stubs") |
| 268 | props.Sdk_version = proptools.StringPtr("module_current") |
| 269 | props.Visibility = []string{"//frameworks/base"} |
| 270 | ctx.CreateModule(java.LibraryFactory, &props) |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | func createMergedTestStubsForNonUpdatableModules(ctx android.LoadHookContext) { |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 275 | props := libraryProps{} |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame^] | 276 | props.Name = proptools.StringPtr("all-non-updatable-modules-test-stubs") |
| 277 | props.Static_libs = transformArray(non_updatable_modules, "", ".stubs.test") |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 278 | props.Sdk_version = proptools.StringPtr("module_current") |
| 279 | props.Visibility = []string{"//frameworks/base"} |
| 280 | ctx.CreateModule(java.LibraryFactory, &props) |
| 281 | } |
| 282 | |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 283 | func createMergedFrameworkImpl(ctx android.LoadHookContext, modules []string) { |
| 284 | // This module is for the "framework-all" module, which should not include the core libraries. |
| 285 | modules = removeAll(modules, core_libraries_modules) |
Nikita Ioffe | d3f0a6f | 2022-11-15 11:26:53 +0000 | [diff] [blame] | 286 | // Remove the modules that belong to non-updatable APEXes since those are allowed to compile |
| 287 | // against unstable APIs. |
| 288 | modules = removeAll(modules, non_updatable_modules) |
| 289 | // First create updatable-framework-module-impl, which contains all updatable modules. |
| 290 | // This module compiles against module_lib SDK. |
| 291 | { |
| 292 | props := libraryProps{} |
| 293 | props.Name = proptools.StringPtr("updatable-framework-module-impl") |
| 294 | props.Static_libs = transformArray(modules, "", ".impl") |
| 295 | props.Sdk_version = proptools.StringPtr("module_current") |
| 296 | props.Visibility = []string{"//frameworks/base"} |
| 297 | ctx.CreateModule(java.LibraryFactory, &props) |
| 298 | } |
| 299 | |
| 300 | // Now create all-framework-module-impl, which contains updatable-framework-module-impl |
| 301 | // and all non-updatable modules. This module compiles against hidden APIs. |
| 302 | { |
| 303 | props := libraryProps{} |
| 304 | props.Name = proptools.StringPtr("all-framework-module-impl") |
| 305 | props.Static_libs = transformArray(non_updatable_modules, "", ".impl") |
| 306 | props.Static_libs = append(props.Static_libs, "updatable-framework-module-impl") |
| 307 | props.Sdk_version = proptools.StringPtr("core_platform") |
| 308 | props.Visibility = []string{"//frameworks/base"} |
| 309 | ctx.CreateModule(java.LibraryFactory, &props) |
| 310 | } |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | func createMergedFrameworkModuleLibStubs(ctx android.LoadHookContext, modules []string) { |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 314 | // 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] | 315 | modules = removeAll(modules, core_libraries_modules) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 316 | props := libraryProps{} |
| 317 | props.Name = proptools.StringPtr("framework-updatable-stubs-module_libs_api") |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 318 | props.Static_libs = transformArray(modules, "", ".stubs.module_lib") |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 319 | props.Sdk_version = proptools.StringPtr("module_current") |
| 320 | props.Visibility = []string{"//frameworks/base"} |
| 321 | ctx.CreateModule(java.LibraryFactory, &props) |
| 322 | } |
| 323 | |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 324 | func createPublicStubsSourceFilegroup(ctx android.LoadHookContext, modules []string) { |
| 325 | props := fgProps{} |
| 326 | props.Name = proptools.StringPtr("all-modules-public-stubs-source") |
| 327 | props.Srcs = createSrcs(modules, "{.public.stubs.source}") |
| 328 | props.Visibility = []string{"//frameworks/base"} |
| 329 | ctx.CreateModule(android.FileGroupFactory, &props) |
| 330 | } |
| 331 | |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 332 | func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_classpath []string) { |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 333 | var textFiles []MergedTxtDefinition |
Anton Hansson | 16ff357 | 2022-01-11 18:36:35 +0000 | [diff] [blame] | 334 | |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 335 | tagSuffix := []string{".api.txt}", ".removed-api.txt}"} |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 336 | distFilename := []string{"android.txt", "android-removed.txt"} |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 337 | for i, f := range []string{"current.txt", "removed.txt"} { |
| 338 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 339 | TxtFilename: f, |
| 340 | DistFilename: distFilename[i], |
| 341 | BaseTxt: ":non-updatable-" + f, |
| 342 | Modules: bootclasspath, |
| 343 | ModuleTag: "{.public" + tagSuffix[i], |
| 344 | Scope: "public", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 345 | }) |
| 346 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 347 | TxtFilename: f, |
| 348 | DistFilename: distFilename[i], |
| 349 | BaseTxt: ":non-updatable-system-" + f, |
| 350 | Modules: bootclasspath, |
| 351 | ModuleTag: "{.system" + tagSuffix[i], |
| 352 | Scope: "system", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 353 | }) |
| 354 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 355 | TxtFilename: f, |
| 356 | DistFilename: distFilename[i], |
| 357 | BaseTxt: ":non-updatable-module-lib-" + f, |
| 358 | Modules: bootclasspath, |
| 359 | ModuleTag: "{.module-lib" + tagSuffix[i], |
| 360 | Scope: "module-lib", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 361 | }) |
| 362 | textFiles = append(textFiles, MergedTxtDefinition{ |
Anton Hansson | 09a9c4e | 2022-04-08 10:59:46 +0100 | [diff] [blame] | 363 | TxtFilename: f, |
| 364 | DistFilename: distFilename[i], |
| 365 | BaseTxt: ":non-updatable-system-server-" + f, |
| 366 | Modules: system_server_classpath, |
| 367 | ModuleTag: "{.system-server" + tagSuffix[i], |
| 368 | Scope: "system-server", |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 369 | }) |
| 370 | } |
| 371 | for _, txt := range textFiles { |
| 372 | createMergedTxt(ctx, txt) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | func (a *CombinedApis) createInternalModules(ctx android.LoadHookContext) { |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 377 | bootclasspath := a.properties.Bootclasspath |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 378 | system_server_classpath := a.properties.System_server_classpath |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 379 | if ctx.Config().VendorConfig("ANDROID").Bool("include_nonpublic_framework_api") { |
| 380 | bootclasspath = append(bootclasspath, a.properties.Conditional_bootclasspath...) |
| 381 | sort.Strings(bootclasspath) |
| 382 | } |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 383 | createMergedTxts(ctx, bootclasspath, system_server_classpath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 384 | |
Anton Hansson | 07a1295 | 2022-01-12 17:28:39 +0000 | [diff] [blame] | 385 | createMergedStubsSrcjar(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 386 | |
Anton Hansson | c6e9d2f | 2022-01-25 15:53:43 +0000 | [diff] [blame] | 387 | createMergedPublicStubs(ctx, bootclasspath) |
| 388 | createMergedSystemStubs(ctx, bootclasspath) |
Nikita Ioffe | 5593fbb | 2022-12-01 14:52:34 +0000 | [diff] [blame^] | 389 | createMergedTestStubsForNonUpdatableModules(ctx) |
Anton Hansson | 95e89a8 | 2022-01-28 11:31:50 +0000 | [diff] [blame] | 390 | createMergedFrameworkModuleLibStubs(ctx, bootclasspath) |
| 391 | createMergedFrameworkImpl(ctx, bootclasspath) |
Anton Hansson | cb00f94 | 2022-01-13 09:45:12 +0000 | [diff] [blame] | 392 | |
Cole Faust | dcda370 | 2022-10-04 14:46:35 -0700 | [diff] [blame] | 393 | createMergedAnnotationsFilegroups(ctx, bootclasspath, system_server_classpath) |
Anton Hansson | cc18e03 | 2022-01-12 14:45:22 +0000 | [diff] [blame] | 394 | |
Anton Hansson | 05e944d | 2022-01-13 12:26:30 +0000 | [diff] [blame] | 395 | createFilteredApiVersions(ctx, bootclasspath) |
Anton Hansson | 4468d7c | 2022-01-14 12:10:01 +0000 | [diff] [blame] | 396 | |
| 397 | createPublicStubsSourceFilegroup(ctx, bootclasspath) |
Anton Hansson | 0860aaf | 2021-10-08 16:48:03 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | func combinedApisModuleFactory() android.Module { |
| 401 | module := &CombinedApis{} |
| 402 | module.AddProperties(&module.properties) |
| 403 | android.InitAndroidModule(module) |
| 404 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.createInternalModules(ctx) }) |
| 405 | return module |
| 406 | } |
Anton Hansson | fd31645 | 2022-01-14 11:15:52 +0000 | [diff] [blame] | 407 | |
| 408 | // Various utility methods below. |
| 409 | |
| 410 | // Creates an array of ":<m><tag>" for each m in <modules>. |
| 411 | func createSrcs(modules []string, tag string) []string { |
| 412 | return transformArray(modules, ":", tag) |
| 413 | } |
| 414 | |
| 415 | // Creates an array of "<prefix><m><suffix>", for each m in <modules>. |
| 416 | func transformArray(modules []string, prefix, suffix string) []string { |
| 417 | a := make([]string, 0, len(modules)) |
| 418 | for _, module := range modules { |
| 419 | a = append(a, prefix+module+suffix) |
| 420 | } |
| 421 | return a |
| 422 | } |
| 423 | |
| 424 | func removeAll(s []string, vs []string) []string { |
| 425 | for _, v := range vs { |
| 426 | s = remove(s, v) |
| 427 | } |
| 428 | return s |
| 429 | } |
| 430 | |
| 431 | func remove(s []string, v string) []string { |
| 432 | s2 := make([]string, 0, len(s)) |
| 433 | for _, sv := range s { |
| 434 | if sv != v { |
| 435 | s2 = append(s2, sv) |
| 436 | } |
| 437 | } |
| 438 | return s2 |
| 439 | } |