Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 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 java |
| 16 | |
| 17 | import ( |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 18 | "fmt" |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 19 | "path" |
Anton Hansson | 370fd0b | 2021-01-22 15:05:04 +0000 | [diff] [blame] | 20 | "strconv" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 21 | "strings" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 26 | "android/soong/genrule" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 29 | func init() { |
Paul Duffin | a48f758 | 2019-12-19 11:25:19 +0000 | [diff] [blame] | 30 | RegisterPrebuiltApisBuildComponents(android.InitRegistrationContext) |
| 31 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 32 | |
Paul Duffin | a48f758 | 2019-12-19 11:25:19 +0000 | [diff] [blame] | 33 | func RegisterPrebuiltApisBuildComponents(ctx android.RegistrationContext) { |
| 34 | ctx.RegisterModuleType("prebuilt_apis", PrebuiltApisFactory) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 35 | } |
| 36 | |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 37 | type prebuiltApisProperties struct { |
| 38 | // list of api version directories |
| 39 | Api_dirs []string |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 40 | |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 41 | // The next API directory can optionally point to a directory where |
| 42 | // files incompatibility-tracking files are stored for the current |
| 43 | // "in progress" API. Each module present in one of the api_dirs will have |
| 44 | // a <module>-incompatibilities.api.<scope>.latest module created. |
| 45 | Next_api_dir *string |
| 46 | |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 47 | // The sdk_version of java_import modules generated based on jar files. |
| 48 | // Defaults to "current" |
| 49 | Imports_sdk_version *string |
Liz Kammer | 4e7f260 | 2020-09-02 08:37:49 -0700 | [diff] [blame] | 50 | |
| 51 | // If set to true, compile dex for java_import modules. Defaults to false. |
| 52 | Imports_compile_dex *bool |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 53 | } |
| 54 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 55 | type prebuiltApis struct { |
| 56 | android.ModuleBase |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 57 | properties prebuiltApisProperties |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 58 | } |
| 59 | |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 60 | func (module *prebuiltApis) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 61 | // no need to implement |
| 62 | } |
| 63 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 64 | // parsePrebuiltPath parses the relevant variables out of a variety of paths, e.g. |
| 65 | // <version>/<scope>/<module>.jar |
| 66 | // <version>/<scope>/api/<module>.txt |
| 67 | // extensions/<version>/<scope>/<module>.jar |
| 68 | // extensions/<version>/<scope>/api/<module>.txt |
| 69 | func parsePrebuiltPath(ctx android.LoadHookContext, p string) (module string, version string, scope string) { |
| 70 | elements := strings.Split(p, "/") |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 71 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 72 | scopeIdx := len(elements) - 2 |
| 73 | if elements[scopeIdx] == "api" { |
| 74 | scopeIdx-- |
| 75 | } |
| 76 | scope = elements[scopeIdx] |
| 77 | if scope != "core" && scope != "public" && scope != "system" && scope != "test" && scope != "module-lib" && scope != "system-server" { |
| 78 | ctx.ModuleErrorf("invalid scope %q found in path: %q", scope, p) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 79 | return |
| 80 | } |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 81 | version = elements[scopeIdx-1] |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 82 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 83 | module = strings.TrimSuffix(path.Base(p), path.Ext(p)) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 84 | return |
| 85 | } |
| 86 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 87 | // parseFinalizedPrebuiltPath is like parsePrebuiltPath, but verifies the version is numeric (a finalized version). |
| 88 | func parseFinalizedPrebuiltPath(ctx android.LoadHookContext, p string) (module string, version int, scope string) { |
| 89 | module, v, scope := parsePrebuiltPath(ctx, p) |
| 90 | version, err := strconv.Atoi(v) |
| 91 | if err != nil { |
| 92 | ctx.ModuleErrorf("Found finalized API files in non-numeric dir '%v'", v) |
| 93 | return |
| 94 | } |
| 95 | return |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 98 | func prebuiltApiModuleName(mctx android.LoadHookContext, module, scope, version string) string { |
| 99 | return fmt.Sprintf("%s_%s_%s_%s", mctx.ModuleName(), scope, version, module) |
| 100 | } |
| 101 | |
| 102 | func createImport(mctx android.LoadHookContext, module, scope, version, path, sdkVersion string, compileDex bool) { |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 103 | props := struct { |
| 104 | Name *string |
| 105 | Jars []string |
| 106 | Sdk_version *string |
| 107 | Installable *bool |
Liz Kammer | 4e7f260 | 2020-09-02 08:37:49 -0700 | [diff] [blame] | 108 | Compile_dex *bool |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 109 | }{} |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 110 | props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, module, scope, version)) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 111 | props.Jars = append(props.Jars, path) |
Liz Kammer | 4e7f260 | 2020-09-02 08:37:49 -0700 | [diff] [blame] | 112 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 113 | props.Installable = proptools.BoolPtr(false) |
Liz Kammer | 4e7f260 | 2020-09-02 08:37:49 -0700 | [diff] [blame] | 114 | props.Compile_dex = proptools.BoolPtr(compileDex) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 115 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 116 | mctx.CreateModule(ImportFactory, &props) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 119 | func createApiModule(mctx android.LoadHookContext, name string, path string) { |
| 120 | genruleProps := struct { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 121 | Name *string |
| 122 | Srcs []string |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 123 | Out []string |
| 124 | Cmd *string |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 125 | }{} |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 126 | genruleProps.Name = proptools.StringPtr(name) |
| 127 | genruleProps.Srcs = []string{path} |
| 128 | genruleProps.Out = []string{name} |
| 129 | genruleProps.Cmd = proptools.StringPtr("cp $(in) $(out)") |
| 130 | mctx.CreateModule(genrule.GenRuleFactory, &genruleProps) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 131 | } |
| 132 | |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 133 | func createEmptyFile(mctx android.LoadHookContext, name string) { |
| 134 | props := struct { |
| 135 | Name *string |
| 136 | Cmd *string |
| 137 | Out []string |
| 138 | }{} |
| 139 | props.Name = proptools.StringPtr(name) |
| 140 | props.Out = []string{name} |
| 141 | props.Cmd = proptools.StringPtr("touch $(genDir)/" + name) |
| 142 | mctx.CreateModule(genrule.GenRuleFactory, &props) |
| 143 | } |
| 144 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 145 | // globApiDirs collects all the files in all api_dirs and all scopes that match the given glob, e.g. '*.jar' or 'api/*.txt'. |
| 146 | // <api-dir>/<scope>/<glob> for all api-dir and scope. |
| 147 | func globApiDirs(mctx android.LoadHookContext, p *prebuiltApis, api_dir_glob string) []string { |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 148 | var files []string |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 149 | for _, apiver := range p.properties.Api_dirs { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 150 | files = append(files, globScopeDir(mctx, apiver, api_dir_glob)...) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 151 | } |
| 152 | return files |
| 153 | } |
| 154 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 155 | // globScopeDir collects all the files in the given subdir across all scopes that match the given glob, e.g. '*.jar' or 'api/*.txt'. |
| 156 | // <subdir>/<scope>/<glob> for all scope. |
| 157 | func globScopeDir(mctx android.LoadHookContext, subdir string, subdir_glob string) []string { |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 158 | var files []string |
| 159 | dir := mctx.ModuleDir() + "/" + subdir |
| 160 | for _, scope := range []string{"public", "system", "test", "core", "module-lib", "system-server"} { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 161 | glob := fmt.Sprintf("%s/%s/%s", dir, scope, subdir_glob) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 162 | vfiles, err := mctx.GlobWithDeps(glob, nil) |
| 163 | if err != nil { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 164 | mctx.ModuleErrorf("failed to glob %s files under %q: %s", subdir_glob, dir+"/"+scope, err) |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 165 | } |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 166 | files = append(files, vfiles...) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 167 | } |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 168 | for i, f := range files { |
| 169 | files[i] = strings.TrimPrefix(f, mctx.ModuleDir()+"/") |
| 170 | } |
Sundong Ahn | 8faab8a | 2019-02-14 11:49:24 +0900 | [diff] [blame] | 171 | return files |
| 172 | } |
| 173 | |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 174 | func prebuiltSdkStubs(mctx android.LoadHookContext, p *prebuiltApis) { |
Sundong Ahn | 8faab8a | 2019-02-14 11:49:24 +0900 | [diff] [blame] | 175 | // <apiver>/<scope>/<module>.jar |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 176 | files := globApiDirs(mctx, p, "*.jar") |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 177 | |
Liz Kammer | 4e7f260 | 2020-09-02 08:37:49 -0700 | [diff] [blame] | 178 | sdkVersion := proptools.StringDefault(p.properties.Imports_sdk_version, "current") |
| 179 | compileDex := proptools.BoolDefault(p.properties.Imports_compile_dex, false) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 180 | |
| 181 | for _, f := range files { |
| 182 | // create a Import module for each jar file |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 183 | module, version, scope := parsePrebuiltPath(mctx, f) |
| 184 | createImport(mctx, module, scope, version, f, sdkVersion, compileDex) |
Paul Duffin | b077bcc | 2021-10-28 13:27:37 +0100 | [diff] [blame] | 185 | |
| 186 | if module == "core-for-system-modules" { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 187 | createSystemModules(mctx, version, scope) |
Paul Duffin | b077bcc | 2021-10-28 13:27:37 +0100 | [diff] [blame] | 188 | } |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 192 | func createSystemModules(mctx android.LoadHookContext, version, scope string) { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 193 | props := struct { |
| 194 | Name *string |
| 195 | Libs []string |
| 196 | }{} |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 197 | props.Name = proptools.StringPtr(prebuiltApiModuleName(mctx, "system_modules", scope, version)) |
| 198 | props.Libs = append(props.Libs, prebuiltApiModuleName(mctx, "core-for-system-modules", scope, version)) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 199 | |
Paul Duffin | d6c2a65 | 2021-03-11 07:56:22 +0000 | [diff] [blame] | 200 | mctx.CreateModule(systemModulesImportFactory, &props) |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 203 | func prebuiltApiFiles(mctx android.LoadHookContext, p *prebuiltApis) { |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 204 | // <apiver>/<scope>/api/<module>.txt |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 205 | apiLevelFiles := globApiDirs(mctx, p, "api/*.txt") |
| 206 | if len(apiLevelFiles) == 0 { |
| 207 | mctx.ModuleErrorf("no api file found under %q", mctx.ModuleDir()) |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 208 | } |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 209 | |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 210 | // Create modules for all (<module>, <scope, <version>) triplets, |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 211 | apiModuleName := func(module, scope, version string) string { |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 212 | return module + ".api." + scope + "." + version |
| 213 | } |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 214 | for _, f := range apiLevelFiles { |
| 215 | module, version, scope := parseFinalizedPrebuiltPath(mctx, f) |
| 216 | createApiModule(mctx, apiModuleName(module, scope, strconv.Itoa(version)), f) |
| 217 | } |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 218 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 219 | // Figure out the latest version of each module/scope |
| 220 | type latestApiInfo struct { |
| 221 | module, scope, path string |
| 222 | version int |
| 223 | } |
| 224 | |
| 225 | latest := make(map[string]latestApiInfo) |
| 226 | for _, f := range apiLevelFiles { |
| 227 | module, version, scope := parseFinalizedPrebuiltPath(mctx, f) |
| 228 | if strings.HasSuffix(module, "incompatibilities") { |
| 229 | continue |
Anton Hansson | 370fd0b | 2021-01-22 15:05:04 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 232 | key := module + "." + scope |
| 233 | info, exists := latest[key] |
| 234 | if !exists || version > info.version { |
| 235 | latest[key] = latestApiInfo{module, scope, f, version} |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 236 | } |
| 237 | } |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 238 | |
Anton Hansson | 370fd0b | 2021-01-22 15:05:04 +0000 | [diff] [blame] | 239 | // Sort the keys in order to make build.ninja stable |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 240 | for _, k := range android.SortedStringKeys(latest) { |
| 241 | info := latest[k] |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 242 | name := apiModuleName(info.module, info.scope, "latest") |
| 243 | createApiModule(mctx, name, info.path) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Create incompatibilities tracking files for all modules, if we have a "next" api. |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 247 | incompatibilities := make(map[string]bool) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 248 | if nextApiDir := String(p.properties.Next_api_dir); nextApiDir != "" { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 249 | files := globScopeDir(mctx, nextApiDir, "api/*incompatibilities.txt") |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 250 | for _, f := range files { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 251 | filename, _, scope := parsePrebuiltPath(mctx, f) |
Anton Hansson | fa5e6b5 | 2021-04-13 19:09:48 +0100 | [diff] [blame] | 252 | referencedModule := strings.TrimSuffix(filename, "-incompatibilities") |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 253 | |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 254 | createApiModule(mctx, apiModuleName(referencedModule+"-incompatibilities", scope, "latest"), f) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 255 | |
| 256 | incompatibilities[referencedModule+"."+scope] = true |
| 257 | } |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 258 | } |
| 259 | // Create empty incompatibilities files for remaining modules |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 260 | for _, k := range android.SortedStringKeys(latest) { |
Jaewoong Jung | 1a97ee0 | 2021-03-09 13:25:02 -0800 | [diff] [blame] | 261 | if _, ok := incompatibilities[k]; !ok { |
Anton Hansson | 377318b | 2022-02-15 12:55:11 +0000 | [diff] [blame^] | 262 | createEmptyFile(mctx, apiModuleName(latest[k].module+"-incompatibilities", latest[k].scope, "latest")) |
Anton Hansson | 20ce41d | 2021-01-22 15:05:32 +0000 | [diff] [blame] | 263 | } |
Sundong Ahn | a01c2a5 | 2018-06-07 21:42:16 +0900 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Paul Duffin | d4c0356 | 2020-04-09 17:15:44 +0100 | [diff] [blame] | 267 | func createPrebuiltApiModules(mctx android.LoadHookContext) { |
Liz Kammer | 2d2fd85 | 2020-08-12 14:42:30 -0700 | [diff] [blame] | 268 | if p, ok := mctx.Module().(*prebuiltApis); ok { |
| 269 | prebuiltApiFiles(mctx, p) |
| 270 | prebuiltSdkStubs(mctx, p) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 274 | // prebuilt_apis is a meta-module that generates modules for all API txt files |
| 275 | // found under the directory where the Android.bp is located. |
Jaewoong Jung | 5fb5b2a | 2019-03-21 10:48:25 -0700 | [diff] [blame] | 276 | // Specifically, an API file located at ./<ver>/<scope>/api/<module>.txt |
Anton Hansson | c79d412 | 2021-02-17 14:21:33 +0000 | [diff] [blame] | 277 | // generates a module named <module>-api.<scope>.<ver>. |
Jaewoong Jung | 5fb5b2a | 2019-03-21 10:48:25 -0700 | [diff] [blame] | 278 | // |
| 279 | // It also creates <module>-api.<scope>.latest for the latest <ver>. |
Paul Duffin | d4c0356 | 2020-04-09 17:15:44 +0100 | [diff] [blame] | 280 | // |
| 281 | // Similarly, it generates a java_import for all API .jar files found under the |
| 282 | // directory where the Android.bp is located. Specifically, an API file located |
| 283 | // at ./<ver>/<scope>/api/<module>.jar generates a java_import module named |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 284 | // <prebuilt-api-module>_<scope>_<ver>_<module>, and for SDK versions >= 30 |
| 285 | // a java_system_modules module named |
| 286 | // <prebuilt-api-module>_public_<ver>_system_modules |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 287 | func PrebuiltApisFactory() android.Module { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 288 | module := &prebuiltApis{} |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 289 | module.AddProperties(&module.properties) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 290 | android.InitAndroidModule(module) |
Paul Duffin | d4c0356 | 2020-04-09 17:15:44 +0100 | [diff] [blame] | 291 | android.AddLoadHook(module, createPrebuiltApiModules) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 292 | return module |
| 293 | } |