Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +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 ( |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 18 | "fmt" |
| 19 | "path" |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 20 | "path/filepath" |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 21 | "reflect" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 22 | "sort" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 23 | "strings" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 24 | "sync" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 25 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 30 | ) |
| 31 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 32 | const ( |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 33 | sdkXmlFileSuffix = ".xml" |
| 34 | permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 35 | `<!-- Copyright (C) 2018 The Android Open Source Project\n` + |
| 36 | `\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 37 | ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 38 | ` you may not use this file except in compliance with the License.\n` + |
| 39 | ` You may obtain a copy of the License at\n` + |
| 40 | `\n` + |
| 41 | ` http://www.apache.org/licenses/LICENSE-2.0\n` + |
| 42 | `\n` + |
| 43 | ` Unless required by applicable law or agreed to in writing, software\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 44 | ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 45 | ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` + |
| 46 | ` See the License for the specific language governing permissions and\n` + |
| 47 | ` limitations under the License.\n` + |
| 48 | `-->\n` + |
| 49 | `<permissions>\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 50 | ` <library name=\"%s\" file=\"%s\"/>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 51 | `</permissions>\n` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 52 | ) |
| 53 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 54 | // A tag to associated a dependency with a specific api scope. |
| 55 | type scopeDependencyTag struct { |
| 56 | blueprint.BaseDependencyTag |
| 57 | name string |
| 58 | apiScope *apiScope |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 59 | |
| 60 | // Function for extracting appropriate path information from the dependency. |
| 61 | depInfoExtractor func(paths *scopePaths, dep android.Module) error |
| 62 | } |
| 63 | |
| 64 | // Extract tag specific information from the dependency. |
| 65 | func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { |
| 66 | err := tag.depInfoExtractor(paths, dep) |
| 67 | if err != nil { |
| 68 | ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) |
| 69 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | // Provides information about an api scope, e.g. public, system, test. |
| 73 | type apiScope struct { |
| 74 | // The name of the api scope, e.g. public, system, test |
| 75 | name string |
| 76 | |
Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 77 | // The api scope that this scope extends. |
| 78 | extends *apiScope |
| 79 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 80 | // The legacy enabled status for a specific scope can be dependent on other |
| 81 | // properties that have been specified on the library so it is provided by |
| 82 | // a function that can determine the status by examining those properties. |
| 83 | legacyEnabledStatus func(module *SdkLibrary) bool |
| 84 | |
| 85 | // The default enabled status for non-legacy behavior, which is triggered by |
| 86 | // explicitly enabling at least one api scope. |
| 87 | defaultEnabledStatus bool |
| 88 | |
| 89 | // Gets a pointer to the scope specific properties. |
| 90 | scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties |
| 91 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 92 | // The name of the field in the dynamically created structure. |
| 93 | fieldName string |
| 94 | |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 95 | // The name of the property in the java_sdk_library_import |
| 96 | propertyName string |
| 97 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 98 | // The tag to use to depend on the stubs library module. |
| 99 | stubsTag scopeDependencyTag |
| 100 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 101 | // The tag to use to depend on the stubs source module (if separate from the API module). |
| 102 | stubsSourceTag scopeDependencyTag |
| 103 | |
| 104 | // The tag to use to depend on the API file generating module (if separate from the stubs source module). |
| 105 | apiFileTag scopeDependencyTag |
| 106 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 107 | // The tag to use to depend on the stubs source and API module. |
| 108 | stubsSourceAndApiTag scopeDependencyTag |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 109 | |
| 110 | // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". |
| 111 | apiFilePrefix string |
| 112 | |
| 113 | // The scope specific prefix to add to the sdk library module name to construct a scope specific |
| 114 | // module name. |
| 115 | moduleSuffix string |
| 116 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 117 | // SDK version that the stubs library is built against. Note that this is always |
| 118 | // *current. Older stubs library built with a numbered SDK version is created from |
| 119 | // the prebuilt jar. |
| 120 | sdkVersion string |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 121 | |
| 122 | // Extra arguments to pass to droidstubs for this scope. |
| 123 | droidstubsArgs []string |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 124 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 125 | // The args that must be passed to droidstubs to generate the stubs source |
| 126 | // for this scope. |
| 127 | // |
| 128 | // The stubs source must include the definitions of everything that is in this |
| 129 | // api scope and all the scopes that this one extends. |
| 130 | droidstubsArgsForGeneratingStubsSource []string |
| 131 | |
| 132 | // The args that must be passed to droidstubs to generate the API for this scope. |
| 133 | // |
| 134 | // The API only includes the additional members that this scope adds over the scope |
| 135 | // that it extends. |
| 136 | droidstubsArgsForGeneratingApi []string |
| 137 | |
| 138 | // True if the stubs source and api can be created by the same metalava invocation. |
| 139 | createStubsSourceAndApiTogether bool |
| 140 | |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 141 | // Whether the api scope can be treated as unstable, and should skip compat checks. |
| 142 | unstable bool |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | // Initialize a scope, creating and adding appropriate dependency tags |
| 146 | func initApiScope(scope *apiScope) *apiScope { |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 147 | name := scope.name |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 148 | scope.propertyName = strings.ReplaceAll(name, "-", "_") |
| 149 | scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 150 | scope.stubsTag = scopeDependencyTag{ |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 151 | name: name + "-stubs", |
| 152 | apiScope: scope, |
| 153 | depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 154 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 155 | scope.stubsSourceTag = scopeDependencyTag{ |
| 156 | name: name + "-stubs-source", |
| 157 | apiScope: scope, |
| 158 | depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, |
| 159 | } |
| 160 | scope.apiFileTag = scopeDependencyTag{ |
| 161 | name: name + "-api", |
| 162 | apiScope: scope, |
| 163 | depInfoExtractor: (*scopePaths).extractApiInfoFromDep, |
| 164 | } |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 165 | scope.stubsSourceAndApiTag = scopeDependencyTag{ |
| 166 | name: name + "-stubs-source-and-api", |
| 167 | apiScope: scope, |
| 168 | depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 169 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 170 | |
| 171 | // To get the args needed to generate the stubs source append all the args from |
| 172 | // this scope and all the scopes it extends as each set of args adds additional |
| 173 | // members to the stubs. |
| 174 | var stubsSourceArgs []string |
| 175 | for s := scope; s != nil; s = s.extends { |
| 176 | stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...) |
| 177 | } |
| 178 | scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs |
| 179 | |
| 180 | // Currently the args needed to generate the API are the same as the args |
| 181 | // needed to add additional members. |
| 182 | apiArgs := scope.droidstubsArgs |
| 183 | scope.droidstubsArgsForGeneratingApi = apiArgs |
| 184 | |
| 185 | // If the args needed to generate the stubs and API are the same then they |
| 186 | // can be generated in a single invocation of metalava, otherwise they will |
| 187 | // need separate invocations. |
| 188 | scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs) |
| 189 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 190 | return scope |
| 191 | } |
| 192 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 193 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 194 | return baseName + ".stubs" + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 197 | func (scope *apiScope) stubsSourceModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 198 | return baseName + ".stubs.source" + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 201 | func (scope *apiScope) apiModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 202 | return baseName + ".api" + scope.moduleSuffix |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 205 | func (scope *apiScope) String() string { |
| 206 | return scope.name |
| 207 | } |
| 208 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 209 | type apiScopes []*apiScope |
| 210 | |
| 211 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { |
| 212 | var list []string |
| 213 | for _, scope := range scopes { |
| 214 | list = append(list, accessor(scope)) |
| 215 | } |
| 216 | return list |
| 217 | } |
| 218 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 219 | var ( |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 220 | apiScopePublic = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 221 | name: "public", |
| 222 | |
| 223 | // Public scope is enabled by default for both legacy and non-legacy modes. |
| 224 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 225 | return true |
| 226 | }, |
| 227 | defaultEnabledStatus: true, |
| 228 | |
| 229 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 230 | return &module.sdkLibraryProperties.Public |
| 231 | }, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 232 | sdkVersion: "current", |
| 233 | }) |
| 234 | apiScopeSystem = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 235 | name: "system", |
| 236 | extends: apiScopePublic, |
| 237 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 238 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 239 | return &module.sdkLibraryProperties.System |
| 240 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 241 | apiFilePrefix: "system-", |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 242 | moduleSuffix: ".system", |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 243 | sdkVersion: "system_current", |
Paul Duffin | 0d54364 | 2020-04-29 22:18:41 +0100 | [diff] [blame] | 244 | droidstubsArgs: []string{"-showAnnotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.PRIVILEGED_APPS\\)"}, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 245 | }) |
| 246 | apiScopeTest = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 247 | name: "test", |
| 248 | extends: apiScopePublic, |
| 249 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 250 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 251 | return &module.sdkLibraryProperties.Test |
| 252 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 253 | apiFilePrefix: "test-", |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 254 | moduleSuffix: ".test", |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 255 | sdkVersion: "test_current", |
| 256 | droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"}, |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 257 | unstable: true, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 258 | }) |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 259 | apiScopeModuleLib = initApiScope(&apiScope{ |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 260 | name: "module-lib", |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 261 | extends: apiScopeSystem, |
| 262 | // Module_lib scope is disabled by default in legacy mode. |
| 263 | // |
| 264 | // Enabling this would break existing usages. |
| 265 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 266 | return false |
| 267 | }, |
| 268 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 269 | return &module.sdkLibraryProperties.Module_lib |
| 270 | }, |
| 271 | apiFilePrefix: "module-lib-", |
| 272 | moduleSuffix: ".module_lib", |
| 273 | sdkVersion: "module_current", |
| 274 | droidstubsArgs: []string{ |
| 275 | "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)", |
| 276 | }, |
| 277 | }) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 278 | allApiScopes = apiScopes{ |
| 279 | apiScopePublic, |
| 280 | apiScopeSystem, |
| 281 | apiScopeTest, |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 282 | apiScopeModuleLib, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 283 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 284 | ) |
| 285 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 286 | var ( |
| 287 | javaSdkLibrariesLock sync.Mutex |
| 288 | ) |
| 289 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 290 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 291 | // 1) disallowing linking to the runtime shared lib |
| 292 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 293 | |
| 294 | func init() { |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 295 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 296 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 297 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 298 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 299 | sort.Strings(*javaSdkLibraries) |
| 300 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 301 | }) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 302 | |
| 303 | // Register sdk member types. |
| 304 | android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{ |
| 305 | android.SdkMemberTypeBase{ |
| 306 | PropertyName: "java_sdk_libs", |
| 307 | SupportsSdk: true, |
| 308 | }, |
| 309 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 312 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { |
| 313 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
| 314 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) |
| 315 | } |
| 316 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 317 | // Properties associated with each api scope. |
| 318 | type ApiScopeProperties struct { |
| 319 | // Indicates whether the api surface is generated. |
| 320 | // |
| 321 | // If this is set for any scope then all scopes must explicitly specify if they |
| 322 | // are enabled. This is to prevent new usages from depending on legacy behavior. |
| 323 | // |
| 324 | // Otherwise, if this is not set for any scope then the default behavior is |
| 325 | // scope specific so please refer to the scope specific property documentation. |
| 326 | Enabled *bool |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 327 | |
| 328 | // The sdk_version to use for building the stubs. |
| 329 | // |
| 330 | // If not specified then it will use an sdk_version determined as follows: |
| 331 | // 1) If the sdk_version specified on the java_sdk_library is none then this |
| 332 | // will be none. This is used for java_sdk_library instances that are used |
| 333 | // to create stubs that contribute to the core_current sdk version. |
| 334 | // 2) Otherwise, it is assumed that this library extends but does not contribute |
| 335 | // directly to a specific sdk_version and so this uses the sdk_version appropriate |
| 336 | // for the api scope. e.g. public will use sdk_version: current, system will use |
| 337 | // sdk_version: system_current, etc. |
| 338 | // |
| 339 | // This does not affect the sdk_version used for either generating the stubs source |
| 340 | // or the API file. They both have to use the same sdk_version as is used for |
| 341 | // compiling the implementation library. |
| 342 | Sdk_version *string |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 345 | type sdkLibraryProperties struct { |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 346 | // Visibility for stubs library modules. If not specified then defaults to the |
| 347 | // visibility property. |
| 348 | Stubs_library_visibility []string |
| 349 | |
| 350 | // Visibility for stubs source modules. If not specified then defaults to the |
| 351 | // visibility property. |
| 352 | Stubs_source_visibility []string |
| 353 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 354 | // List of Java libraries that will be in the classpath when building stubs |
| 355 | Stub_only_libs []string `android:"arch_variant"` |
| 356 | |
Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 357 | // list of package names that will be documented and publicized as API. |
| 358 | // This allows the API to be restricted to a subset of the source files provided. |
| 359 | // If this is unspecified then all the source files will be treated as being part |
| 360 | // of the API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 361 | Api_packages []string |
| 362 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 363 | // list of package names that must be hidden from the API |
| 364 | Hidden_api_packages []string |
| 365 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 366 | // the relative path to the directory containing the api specification files. |
| 367 | // Defaults to "api". |
| 368 | Api_dir *string |
| 369 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 370 | // If set to true there is no runtime library. |
| 371 | Api_only *bool |
| 372 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 373 | // local files that are used within user customized droiddoc options. |
| 374 | Droiddoc_option_files []string |
| 375 | |
| 376 | // additional droiddoc options |
| 377 | // Available variables for substitution: |
| 378 | // |
| 379 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 380 | Droiddoc_options []string |
| 381 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 382 | // a list of top-level directories containing files to merge qualifier annotations |
| 383 | // (i.e. those intended to be included in the stubs written) from. |
| 384 | Merge_annotations_dirs []string |
| 385 | |
| 386 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 387 | Merge_inclusion_annotations_dirs []string |
| 388 | |
| 389 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 390 | Core_lib *bool |
| 391 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 392 | // don't create dist rules. |
| 393 | No_dist *bool `blueprint:"mutated"` |
| 394 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 395 | // indicates whether system and test apis should be generated. |
| 396 | Generate_system_and_test_apis bool `blueprint:"mutated"` |
| 397 | |
| 398 | // The properties specific to the public api scope |
| 399 | // |
| 400 | // Unless explicitly specified by using public.enabled the public api scope is |
| 401 | // enabled by default in both legacy and non-legacy mode. |
| 402 | Public ApiScopeProperties |
| 403 | |
| 404 | // The properties specific to the system api scope |
| 405 | // |
| 406 | // In legacy mode the system api scope is enabled by default when sdk_version |
| 407 | // is set to something other than "none". |
| 408 | // |
| 409 | // In non-legacy mode the system api scope is disabled by default. |
| 410 | System ApiScopeProperties |
| 411 | |
| 412 | // The properties specific to the test api scope |
| 413 | // |
| 414 | // In legacy mode the test api scope is enabled by default when sdk_version |
| 415 | // is set to something other than "none". |
| 416 | // |
| 417 | // In non-legacy mode the test api scope is disabled by default. |
| 418 | Test ApiScopeProperties |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 419 | |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 420 | // The properties specific to the module_lib api scope |
| 421 | // |
| 422 | // Unless explicitly specified by using test.enabled the module_lib api scope is |
| 423 | // disabled by default. |
| 424 | Module_lib ApiScopeProperties |
| 425 | |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 426 | // Properties related to api linting. |
| 427 | Api_lint struct { |
| 428 | // Enable api linting. |
| 429 | Enabled *bool |
| 430 | } |
| 431 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 432 | // TODO: determines whether to create HTML doc or not |
| 433 | //Html_doc *bool |
| 434 | } |
| 435 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 436 | type scopePaths struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 437 | stubsHeaderPath android.Paths |
| 438 | stubsImplPath android.Paths |
| 439 | currentApiFilePath android.Path |
| 440 | removedApiFilePath android.Path |
| 441 | stubsSrcJar android.Path |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 444 | func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error { |
| 445 | if lib, ok := dep.(Dependency); ok { |
| 446 | paths.stubsHeaderPath = lib.HeaderJars() |
| 447 | paths.stubsImplPath = lib.ImplementationJars() |
| 448 | return nil |
| 449 | } else { |
| 450 | return fmt.Errorf("expected module that implements Dependency, e.g. java_library") |
| 451 | } |
| 452 | } |
| 453 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 454 | func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error { |
| 455 | if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { |
| 456 | action(apiStubsProvider) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 457 | return nil |
| 458 | } else { |
| 459 | return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs") |
| 460 | } |
| 461 | } |
| 462 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 463 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) { |
| 464 | paths.currentApiFilePath = provider.ApiFilePath() |
| 465 | paths.removedApiFilePath = provider.RemovedApiFilePath() |
| 466 | } |
| 467 | |
| 468 | func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error { |
| 469 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 470 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 471 | }) |
| 472 | } |
| 473 | |
| 474 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsProvider) { |
| 475 | paths.stubsSrcJar = provider.StubsSrcJar() |
| 476 | } |
| 477 | |
| 478 | func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error { |
| 479 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 480 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 481 | }) |
| 482 | } |
| 483 | |
| 484 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error { |
| 485 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 486 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 487 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 488 | }) |
| 489 | } |
| 490 | |
| 491 | type commonToSdkLibraryAndImportProperties struct { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 492 | // The naming scheme to use for the components that this module creates. |
| 493 | // |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 494 | // If not specified then it defaults to "default". The other allowable value is |
| 495 | // "framework-modules" which matches the scheme currently used by framework modules |
| 496 | // for the equivalent components represented as separate Soong modules. |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 497 | // |
| 498 | // This is a temporary mechanism to simplify conversion from separate modules for each |
| 499 | // component that follow a different naming pattern to the default one. |
| 500 | // |
| 501 | // TODO(b/155480189) - Remove once naming inconsistencies have been resolved. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 502 | Naming_scheme *string |
| 503 | } |
| 504 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 505 | // Common code between sdk library and sdk library import |
| 506 | type commonToSdkLibraryAndImport struct { |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 507 | moduleBase *android.ModuleBase |
| 508 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 509 | scopePaths map[*apiScope]*scopePaths |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 510 | |
| 511 | namingScheme sdkLibraryComponentNamingScheme |
| 512 | |
| 513 | commonProperties commonToSdkLibraryAndImportProperties |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 516 | func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) { |
| 517 | c.moduleBase = moduleBase |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 518 | |
| 519 | moduleBase.AddProperties(&c.commonProperties) |
| 520 | } |
| 521 | |
| 522 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { |
| 523 | schemeProperty := proptools.StringDefault(c.commonProperties.Naming_scheme, "default") |
| 524 | switch schemeProperty { |
| 525 | case "default": |
| 526 | c.namingScheme = &defaultNamingScheme{} |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 527 | case "framework-modules": |
| 528 | c.namingScheme = &frameworkModulesNamingScheme{} |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 529 | default: |
| 530 | ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty) |
| 531 | return false |
| 532 | } |
| 533 | |
| 534 | return true |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | // Name of the java_library module that compiles the stubs source. |
| 538 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 539 | return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | // Name of the droidstubs module that generates the stubs source and may also |
| 543 | // generate/check the API. |
| 544 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 545 | return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | // Name of the droidstubs module that generates/checks the API. Only used if it |
| 549 | // requires different arts to the stubs source generating module. |
| 550 | func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 551 | return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 552 | } |
| 553 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 554 | func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths { |
| 555 | if c.scopePaths == nil { |
| 556 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 557 | } |
| 558 | paths := c.scopePaths[scope] |
| 559 | if paths == nil { |
| 560 | paths = &scopePaths{} |
| 561 | c.scopePaths[scope] = paths |
| 562 | } |
| 563 | |
| 564 | return paths |
| 565 | } |
| 566 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 567 | func (c *commonToSdkLibraryAndImport) sdkJarsCommon(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { |
| 568 | |
| 569 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 570 | if sdkVersion.version.isNumbered() { |
| 571 | return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion) |
| 572 | } |
| 573 | |
| 574 | var apiScope *apiScope |
| 575 | switch sdkVersion.kind { |
| 576 | case sdkSystem: |
| 577 | apiScope = apiScopeSystem |
| 578 | case sdkTest: |
| 579 | apiScope = apiScopeTest |
| 580 | default: |
| 581 | apiScope = apiScopePublic |
| 582 | } |
| 583 | |
| 584 | paths := c.getScopePaths(apiScope) |
| 585 | if headerJars { |
| 586 | return paths.stubsHeaderPath |
| 587 | } else { |
| 588 | return paths.stubsImplPath |
| 589 | } |
| 590 | } |
| 591 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 592 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 593 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 594 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 595 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 596 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 597 | // Map from api scope to the scope specific property structure. |
| 598 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 599 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 600 | commonToSdkLibraryAndImport |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 601 | } |
| 602 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 603 | var _ Dependency = (*SdkLibrary)(nil) |
| 604 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 605 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 606 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 607 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 608 | } |
| 609 | |
| 610 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 611 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 612 | // must be. |
| 613 | anyScopesExplicitlyEnabled := false |
| 614 | for _, scope := range allApiScopes { |
| 615 | scopeProperties := module.scopeToProperties[scope] |
| 616 | if scopeProperties.Enabled != nil { |
| 617 | anyScopesExplicitlyEnabled = true |
| 618 | break |
| 619 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 620 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 621 | |
| 622 | var generatedScopes apiScopes |
| 623 | enabledScopes := make(map[*apiScope]struct{}) |
| 624 | for _, scope := range allApiScopes { |
| 625 | scopeProperties := module.scopeToProperties[scope] |
| 626 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 627 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 628 | // behaviour. |
| 629 | defaultEnabledStatus := false |
| 630 | if anyScopesExplicitlyEnabled { |
| 631 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 632 | } else { |
| 633 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 634 | } |
| 635 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 636 | if enabled { |
| 637 | enabledScopes[scope] = struct{}{} |
| 638 | generatedScopes = append(generatedScopes, scope) |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 643 | // enabled. |
| 644 | for _, scope := range allApiScopes { |
| 645 | if _, ok := enabledScopes[scope]; ok { |
| 646 | extends := scope.extends |
| 647 | if extends != nil { |
| 648 | if _, ok := enabledScopes[extends]; !ok { |
| 649 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 658 | var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"} |
| 659 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 660 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
| 661 | if dt, ok := depTag.(dependencyTag); ok { |
| 662 | return dt == xmlPermissionsFileTag |
| 663 | } |
| 664 | return false |
| 665 | } |
| 666 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 667 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 668 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 669 | // Add dependencies to the stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 670 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 671 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 672 | // If the stubs source and API cannot be generated together then add an additional dependency on |
| 673 | // the API module. |
| 674 | if apiScope.createStubsSourceAndApiTogether { |
| 675 | // Add a dependency on the stubs source in order to access both stubs source and api information. |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 676 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 677 | } else { |
| 678 | // Add separate dependencies on the creators of the stubs source files and the API. |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 679 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope)) |
| 680 | ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 681 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 682 | } |
| 683 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 684 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 685 | // Add dependency to the rule for generating the xml permissions file |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 686 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName()) |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 689 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 690 | } |
| 691 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 692 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 693 | // Don't build an implementation library if this is api only. |
| 694 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 695 | module.Library.GenerateAndroidBuildActions(ctx) |
| 696 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 697 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 698 | // Record the paths to the header jars of the library (stubs and impl). |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 699 | // When this java_sdk_library is depended upon from others via "libs" property, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 700 | // the recorded paths will be returned depending on the link type of the caller. |
| 701 | ctx.VisitDirectDeps(func(to android.Module) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 702 | tag := ctx.OtherModuleDependencyTag(to) |
| 703 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 704 | // Extract information from any of the scope specific dependencies. |
| 705 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 706 | apiScope := scopeTag.apiScope |
| 707 | scopePaths := module.getScopePaths(apiScope) |
| 708 | |
| 709 | // Extract information from the dependency. The exact information extracted |
| 710 | // is determined by the nature of the dependency which is determined by the tag. |
| 711 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 712 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 713 | }) |
| 714 | } |
| 715 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 716 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 717 | if proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 718 | return nil |
| 719 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 720 | entriesList := module.Library.AndroidMkEntries() |
| 721 | entries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 722 | entries.Required = append(entries.Required, module.xmlFileName()) |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 723 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 724 | } |
| 725 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 726 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 727 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 728 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 729 | } |
| 730 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 731 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 732 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 733 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 734 | } |
| 735 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 736 | // The dist path of the stub artifacts |
| 737 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
| 738 | if module.ModuleBase.Owner() != "" { |
| 739 | return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name) |
| 740 | } else if Bool(module.sdkLibraryProperties.Core_lib) { |
| 741 | return path.Join("apistubs", "core", apiScope.name) |
| 742 | } else { |
| 743 | return path.Join("apistubs", "android", apiScope.name) |
| 744 | } |
| 745 | } |
| 746 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 747 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 748 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 749 | scopeProperties := module.scopeToProperties[apiScope] |
| 750 | if scopeProperties.Sdk_version != nil { |
| 751 | return proptools.String(scopeProperties.Sdk_version) |
| 752 | } |
| 753 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 754 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 755 | if sdkDep.hasStandardLibs() { |
| 756 | // If building against a standard sdk then use the sdk version appropriate for the scope. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 757 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 758 | } else { |
| 759 | // Otherwise, use no system module. |
| 760 | return "none" |
| 761 | } |
| 762 | } |
| 763 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 764 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
| 765 | return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 766 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 767 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 768 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
| 769 | return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | // Creates a static java library that has API stubs |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 773 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 774 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 775 | Name *string |
| 776 | Visibility []string |
| 777 | Srcs []string |
| 778 | Installable *bool |
| 779 | Sdk_version *string |
| 780 | System_modules *string |
| 781 | Patch_module *string |
| 782 | Libs []string |
| 783 | Compile_dex *bool |
| 784 | Java_version *string |
| 785 | Product_variables struct { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 786 | Pdk struct { |
| 787 | Enabled *bool |
| 788 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 789 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 790 | Openjdk9 struct { |
| 791 | Srcs []string |
| 792 | Javacflags []string |
| 793 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 794 | Dist struct { |
| 795 | Targets []string |
| 796 | Dest *string |
| 797 | Dir *string |
| 798 | Tag *string |
| 799 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 800 | }{} |
| 801 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 802 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 803 | |
| 804 | // If stubs_library_visibility is not set then the created module will use the |
| 805 | // visibility of this module. |
| 806 | visibility := module.sdkLibraryProperties.Stubs_library_visibility |
| 807 | props.Visibility = visibility |
| 808 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 809 | // sources are generated from the droiddoc |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 810 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 811 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 812 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 813 | props.System_modules = module.deviceProperties.System_modules |
| 814 | props.Patch_module = module.properties.Patch_module |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 815 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 816 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 817 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 818 | props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs |
| 819 | props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags |
| 820 | props.Java_version = module.properties.Java_version |
| 821 | if module.deviceProperties.Compile_dex != nil { |
| 822 | props.Compile_dex = module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 823 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 824 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 825 | // Dist the class jar artifact for sdk builds. |
| 826 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 827 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 828 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName())) |
| 829 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) |
| 830 | props.Dist.Tag = proptools.StringPtr(".jar") |
| 831 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 832 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 833 | mctx.CreateModule(LibraryFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 834 | } |
| 835 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 836 | // Creates a droidstubs module that creates stubs source files from the given full source |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 837 | // files and also updates and checks the API specification files. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 838 | func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookContext, apiScope *apiScope, name string, createStubSources, createApi bool, scopeSpecificDroidstubsArgs []string) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 839 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 840 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 841 | Visibility []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 842 | Srcs []string |
| 843 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 844 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 845 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 846 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 847 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 848 | Args *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 849 | Java_version *string |
| 850 | Merge_annotations_dirs []string |
| 851 | Merge_inclusion_annotations_dirs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 852 | Generate_stubs *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 853 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 854 | Current ApiToCheck |
| 855 | Last_released ApiToCheck |
| 856 | Ignore_missing_latest_api *bool |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 857 | |
| 858 | Api_lint struct { |
| 859 | Enabled *bool |
| 860 | New_since *string |
| 861 | Baseline_file *string |
| 862 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 863 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 864 | Aidl struct { |
| 865 | Include_dirs []string |
| 866 | Local_include_dirs []string |
| 867 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 868 | Dist struct { |
| 869 | Targets []string |
| 870 | Dest *string |
| 871 | Dir *string |
| 872 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 873 | }{} |
| 874 | |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 875 | // The stubs source processing uses the same compile time classpath when extracting the |
| 876 | // API from the implementation library as it does when compiling it. i.e. the same |
| 877 | // * sdk version |
| 878 | // * system_modules |
| 879 | // * libs (static_libs/libs) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 880 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 881 | props.Name = proptools.StringPtr(name) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 882 | |
| 883 | // If stubs_source_visibility is not set then the created module will use the |
| 884 | // visibility of this module. |
| 885 | visibility := module.sdkLibraryProperties.Stubs_source_visibility |
| 886 | props.Visibility = visibility |
| 887 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 888 | props.Srcs = append(props.Srcs, module.properties.Srcs...) |
| 889 | props.Sdk_version = module.deviceProperties.Sdk_version |
| 890 | props.System_modules = module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 891 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 892 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 893 | // shared libs and static libs. So we need to add both of these libs to Libs property. |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 894 | props.Libs = module.properties.Libs |
| 895 | props.Libs = append(props.Libs, module.properties.Static_libs...) |
| 896 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs |
| 897 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs |
| 898 | props.Java_version = module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 899 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 900 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 901 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 902 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 903 | droidstubsArgs := []string{} |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 904 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 905 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 906 | } |
| 907 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 908 | droidstubsArgs = append(droidstubsArgs, |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 909 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 910 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 911 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 912 | disabledWarnings := []string{ |
| 913 | "MissingPermission", |
| 914 | "BroadcastBehavior", |
| 915 | "HiddenSuperclass", |
| 916 | "DeprecationMismatch", |
| 917 | "UnavailableSymbol", |
| 918 | "SdkConstant", |
| 919 | "HiddenTypeParameter", |
| 920 | "Todo", |
| 921 | "Typo", |
| 922 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 923 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 924 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 925 | if !createStubSources { |
| 926 | // Stubs are not required. |
| 927 | props.Generate_stubs = proptools.BoolPtr(false) |
| 928 | } |
| 929 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 930 | // Add in scope specific arguments. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 931 | droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 932 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 933 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 934 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 935 | if createApi { |
| 936 | // List of APIs identified from the provided source files are created. They are later |
| 937 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 938 | // last-released (a.k.a numbered) list of API. |
| 939 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 940 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
| 941 | apiDir := module.getApiDir() |
| 942 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 943 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 944 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 945 | // check against the not-yet-release API |
| 946 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 947 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 948 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 949 | if !apiScope.unstable { |
| 950 | // check against the latest released API |
| 951 | latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) |
| 952 | props.Check_api.Last_released.Api_file = latestApiFilegroupName |
| 953 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 954 | module.latestRemovedApiFilegroupName(apiScope)) |
| 955 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 956 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 957 | if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { |
| 958 | // Enable api lint. |
| 959 | props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) |
| 960 | props.Check_api.Api_lint.New_since = latestApiFilegroupName |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 961 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 962 | // If it exists then pass a lint-baseline.txt through to droidstubs. |
| 963 | baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") |
| 964 | baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) |
| 965 | paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) |
| 966 | if err != nil { |
| 967 | mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) |
| 968 | } |
| 969 | if len(paths) == 1 { |
| 970 | props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) |
| 971 | } else if len(paths) != 0 { |
| 972 | mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths) |
| 973 | } |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 974 | } |
| 975 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 976 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 977 | // Dist the api txt artifact for sdk builds. |
| 978 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 979 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 980 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName())) |
| 981 | props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) |
| 982 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 985 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 986 | } |
| 987 | |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 988 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 989 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 990 | if depTag == xmlPermissionsFileTag { |
| 991 | return true |
| 992 | } |
| 993 | return module.Library.DepIsInSameApex(mctx, dep) |
| 994 | } |
| 995 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 996 | // Creates the xml file that publicizes the runtime library |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 997 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 998 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 999 | Name *string |
| 1000 | Lib_name *string |
| 1001 | Apex_available []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1002 | }{ |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1003 | Name: proptools.StringPtr(module.xmlFileName()), |
| 1004 | Lib_name: proptools.StringPtr(module.BaseModuleName()), |
| 1005 | Apex_available: module.ApexProperties.Apex_available, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1006 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1007 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1008 | mctx.CreateModule(sdkLibraryXmlFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1009 | } |
| 1010 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1011 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1012 | var ver sdkVersion |
| 1013 | var kind sdkKind |
| 1014 | if s.usePrebuilt(ctx) { |
| 1015 | ver = s.version |
| 1016 | kind = s.kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1017 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1018 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 1019 | // Instead of breaking the build, fallback to use "system_current" |
| 1020 | ver = sdkVersionCurrent |
| 1021 | kind = sdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1022 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1023 | |
| 1024 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1025 | jar := filepath.Join(dir, baseName+".jar") |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1026 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 1027 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 1028 | if ctx.Config().AllowMissingDependencies() { |
| 1029 | return android.Paths{android.PathForSource(ctx, jar)} |
| 1030 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1031 | ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", s.raw, jar) |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 1032 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 1033 | return nil |
| 1034 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1035 | return android.Paths{jarPath.Path()} |
| 1036 | } |
| 1037 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1038 | func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1039 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1040 | // Check any special cases for java_sdk_library. |
| 1041 | if !sdkVersion.specified() { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1042 | if headerJars { |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1043 | return module.HeaderJars() |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1044 | } else { |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1045 | return module.ImplementationJars() |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1046 | } |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1047 | } else if sdkVersion.kind == sdkPrivate { |
| 1048 | return module.HeaderJars() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1049 | } |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1050 | |
| 1051 | return module.sdkJarsCommon(ctx, sdkVersion, headerJars) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1052 | } |
| 1053 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1054 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1055 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
| 1056 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 1057 | } |
| 1058 | |
| 1059 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1060 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1061 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1062 | } |
| 1063 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 1064 | func (module *SdkLibrary) SetNoDist() { |
| 1065 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 1066 | } |
| 1067 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1068 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 1069 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1070 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1071 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1072 | return &[]string{} |
| 1073 | }).(*[]string) |
| 1074 | } |
| 1075 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1076 | func (module *SdkLibrary) getApiDir() string { |
| 1077 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 1078 | } |
| 1079 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1080 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 1081 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 1082 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1083 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
| 1084 | // If the module has been disabled then don't create any child modules. |
| 1085 | if !module.Enabled() { |
| 1086 | return |
| 1087 | } |
| 1088 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1089 | if len(module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1090 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1091 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1092 | } |
| 1093 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1094 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 1095 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 1096 | // also assume it does not contribute to the dist build. |
| 1097 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 1098 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1099 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1100 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 1101 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1102 | missing_current_api := false |
| 1103 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1104 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1105 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1106 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1107 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1108 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1109 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1110 | p := android.ExistentPathForSource(mctx, path) |
| 1111 | if !p.Valid() { |
| 1112 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 1113 | missing_current_api = true |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | if missing_current_api { |
| 1119 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 1120 | p := android.ExistentPathForSource(mctx, script) |
| 1121 | |
| 1122 | if !p.Valid() { |
| 1123 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 1124 | } |
| 1125 | |
| 1126 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 1127 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1128 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1129 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1130 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1131 | return |
| 1132 | } |
| 1133 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1134 | for _, scope := range generatedScopes { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1135 | stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1136 | stubsSourceModuleName := module.stubsSourceModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1137 | |
| 1138 | // If the args needed to generate the stubs and API are the same then they |
| 1139 | // can be generated in a single invocation of metalava, otherwise they will |
| 1140 | // need separate invocations. |
| 1141 | if scope.createStubsSourceAndApiTogether { |
| 1142 | // Use the stubs source name for legacy reasons. |
| 1143 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs) |
| 1144 | } else { |
| 1145 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs) |
| 1146 | |
| 1147 | apiArgs := scope.droidstubsArgsForGeneratingApi |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1148 | apiName := module.apiModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1149 | module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs) |
| 1150 | } |
| 1151 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1152 | module.createStubsLibrary(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1153 | } |
| 1154 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1155 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 1156 | // for runtime |
| 1157 | module.createXmlFile(mctx) |
| 1158 | |
| 1159 | // record java_sdk_library modules so that they are exported to make |
| 1160 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1161 | javaSdkLibrariesLock.Lock() |
| 1162 | defer javaSdkLibrariesLock.Unlock() |
| 1163 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1164 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1168 | module.AddProperties( |
| 1169 | &module.sdkLibraryProperties, |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1170 | &module.properties, |
| 1171 | &module.dexpreoptProperties, |
| 1172 | &module.deviceProperties, |
| 1173 | &module.protoProperties, |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1174 | ) |
| 1175 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1176 | module.properties.Installable = proptools.BoolPtr(true) |
| 1177 | module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1178 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1179 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1180 | // Defines how to name the individual component modules the sdk library creates. |
| 1181 | type sdkLibraryComponentNamingScheme interface { |
| 1182 | stubsLibraryModuleName(scope *apiScope, baseName string) string |
| 1183 | |
| 1184 | stubsSourceModuleName(scope *apiScope, baseName string) string |
| 1185 | |
| 1186 | apiModuleName(scope *apiScope, baseName string) string |
| 1187 | } |
| 1188 | |
| 1189 | type defaultNamingScheme struct { |
| 1190 | } |
| 1191 | |
| 1192 | func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { |
| 1193 | return scope.stubsLibraryModuleName(baseName) |
| 1194 | } |
| 1195 | |
| 1196 | func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { |
| 1197 | return scope.stubsSourceModuleName(baseName) |
| 1198 | } |
| 1199 | |
| 1200 | func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string { |
| 1201 | return scope.apiModuleName(baseName) |
| 1202 | } |
| 1203 | |
| 1204 | var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) |
| 1205 | |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 1206 | type frameworkModulesNamingScheme struct { |
| 1207 | } |
| 1208 | |
| 1209 | func (s *frameworkModulesNamingScheme) moduleSuffix(scope *apiScope) string { |
| 1210 | suffix := scope.name |
| 1211 | if scope == apiScopeModuleLib { |
| 1212 | suffix = "module_libs_" |
| 1213 | } |
| 1214 | return suffix |
| 1215 | } |
| 1216 | |
| 1217 | func (s *frameworkModulesNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { |
| 1218 | return fmt.Sprintf("%s-stubs-%sapi", baseName, s.moduleSuffix(scope)) |
| 1219 | } |
| 1220 | |
| 1221 | func (s *frameworkModulesNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { |
| 1222 | return fmt.Sprintf("%s-stubs-srcs-%sapi", baseName, s.moduleSuffix(scope)) |
| 1223 | } |
| 1224 | |
| 1225 | func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName string) string { |
| 1226 | return fmt.Sprintf("%s-api-%sapi", baseName, s.moduleSuffix(scope)) |
| 1227 | } |
| 1228 | |
| 1229 | var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil) |
| 1230 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1231 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 1232 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 1233 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 1234 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 1235 | // the runtime lib to the classpath at runtime if requested via <uses-library>. |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1236 | func SdkLibraryFactory() android.Module { |
| 1237 | module := &SdkLibrary{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1238 | |
| 1239 | // Initialize information common between source and prebuilt. |
| 1240 | module.initCommon(&module.ModuleBase) |
| 1241 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1242 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1243 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1244 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1245 | |
| 1246 | // Initialize the map from scope to scope specific properties. |
| 1247 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
| 1248 | for _, scope := range allApiScopes { |
| 1249 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 1250 | } |
| 1251 | module.scopeToProperties = scopeToProperties |
| 1252 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1253 | // Add the properties containing visibility rules so that they are checked. |
| 1254 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 1255 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 1256 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1257 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
| 1258 | if module.initCommonAfterDefaultsApplied(ctx) { |
| 1259 | module.CreateInternalModules(ctx) |
| 1260 | } |
| 1261 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1262 | return module |
| 1263 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1264 | |
| 1265 | // |
| 1266 | // SDK library prebuilts |
| 1267 | // |
| 1268 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1269 | // Properties associated with each api scope. |
| 1270 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1271 | Jars []string `android:"path"` |
| 1272 | |
| 1273 | Sdk_version *string |
| 1274 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1275 | // List of shared java libs that this module has dependencies to |
| 1276 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1277 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1278 | // The stubs source. |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1279 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1280 | |
| 1281 | // The current.txt |
| 1282 | Current_api string `android:"path"` |
| 1283 | |
| 1284 | // The removed.txt |
| 1285 | Removed_api string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1288 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 1289 | // List of shared java libs, common to all scopes, that this module has |
| 1290 | // dependencies to |
| 1291 | Libs []string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1294 | type sdkLibraryImport struct { |
| 1295 | android.ModuleBase |
| 1296 | android.DefaultableModuleBase |
| 1297 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1298 | android.ApexModuleBase |
| 1299 | android.SdkBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1300 | |
| 1301 | properties sdkLibraryImportProperties |
| 1302 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1303 | // Map from api scope to the scope specific property structure. |
| 1304 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 1305 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1306 | commonToSdkLibraryAndImport |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) |
| 1310 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1311 | // The type of a structure that contains a field of type sdkLibraryScopeProperties |
| 1312 | // for each apiscope in allApiScopes, e.g. something like: |
| 1313 | // struct { |
| 1314 | // Public sdkLibraryScopeProperties |
| 1315 | // System sdkLibraryScopeProperties |
| 1316 | // ... |
| 1317 | // } |
| 1318 | var allScopeStructType = createAllScopePropertiesStructType() |
| 1319 | |
| 1320 | // Dynamically create a structure type for each apiscope in allApiScopes. |
| 1321 | func createAllScopePropertiesStructType() reflect.Type { |
| 1322 | var fields []reflect.StructField |
| 1323 | for _, apiScope := range allApiScopes { |
| 1324 | field := reflect.StructField{ |
| 1325 | Name: apiScope.fieldName, |
| 1326 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), |
| 1327 | } |
| 1328 | fields = append(fields, field) |
| 1329 | } |
| 1330 | |
| 1331 | return reflect.StructOf(fields) |
| 1332 | } |
| 1333 | |
| 1334 | // Create an instance of the scope specific structure type and return a map |
| 1335 | // from apiscope to a pointer to each scope specific field. |
| 1336 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { |
| 1337 | allScopePropertiesPtr := reflect.New(allScopeStructType) |
| 1338 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() |
| 1339 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 1340 | |
| 1341 | for _, apiScope := range allApiScopes { |
| 1342 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) |
| 1343 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) |
| 1344 | } |
| 1345 | |
| 1346 | return allScopePropertiesPtr.Interface(), scopeProperties |
| 1347 | } |
| 1348 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1349 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1350 | func sdkLibraryImportFactory() android.Module { |
| 1351 | module := &sdkLibraryImport{} |
| 1352 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1353 | allScopeProperties, scopeToProperties := createPropertiesInstance() |
| 1354 | module.scopeProperties = scopeToProperties |
| 1355 | module.AddProperties(&module.properties, allScopeProperties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1356 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1357 | // Initialize information common between source and prebuilt. |
| 1358 | module.initCommon(&module.ModuleBase) |
| 1359 | |
Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 1360 | android.InitPrebuiltModule(module, &[]string{""}) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1361 | android.InitApexModule(module) |
| 1362 | android.InitSdkAwareModule(module) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1363 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1364 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1365 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { |
| 1366 | if module.initCommonAfterDefaultsApplied(mctx) { |
| 1367 | module.createInternalModules(mctx) |
| 1368 | } |
| 1369 | }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1370 | return module |
| 1371 | } |
| 1372 | |
| 1373 | func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { |
| 1374 | return &module.prebuilt |
| 1375 | } |
| 1376 | |
| 1377 | func (module *sdkLibraryImport) Name() string { |
| 1378 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 1379 | } |
| 1380 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1381 | func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1382 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1383 | // If the build is configured to use prebuilts then force this to be preferred. |
| 1384 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1385 | module.prebuilt.ForcePrefer() |
| 1386 | } |
| 1387 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1388 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1389 | if len(scopeProperties.Jars) == 0 { |
| 1390 | continue |
| 1391 | } |
| 1392 | |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1393 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1394 | |
| 1395 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1396 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1397 | |
| 1398 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1399 | javaSdkLibrariesLock.Lock() |
| 1400 | defer javaSdkLibrariesLock.Unlock() |
| 1401 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1402 | } |
| 1403 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1404 | func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1405 | // Creates a java import for the jar with ".stubs" suffix |
| 1406 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1407 | Name *string |
| 1408 | Sdk_version *string |
| 1409 | Libs []string |
| 1410 | Jars []string |
| 1411 | Prefer *bool |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1412 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1413 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1414 | props.Sdk_version = scopeProperties.Sdk_version |
| 1415 | // Prepend any of the libs from the legacy public properties to the libs for each of the |
| 1416 | // scopes to avoid having to duplicate them in each scope. |
| 1417 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) |
| 1418 | props.Jars = scopeProperties.Jars |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1419 | |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1420 | // The imports are preferred if the java_sdk_library_import is preferred. |
| 1421 | props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1422 | mctx.CreateModule(ImportFactory, &props) |
| 1423 | } |
| 1424 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1425 | func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1426 | props := struct { |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1427 | Name *string |
| 1428 | Srcs []string |
| 1429 | Prefer *bool |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1430 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1431 | props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1432 | props.Srcs = scopeProperties.Stub_srcs |
| 1433 | mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1434 | |
| 1435 | // The stubs source is preferred if the java_sdk_library_import is preferred. |
| 1436 | props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1437 | } |
| 1438 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1439 | func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1440 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1441 | if len(scopeProperties.Jars) == 0 { |
| 1442 | continue |
| 1443 | } |
| 1444 | |
| 1445 | // Add dependencies to the prebuilt stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1446 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1447 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1451 | // Record the paths to the prebuilt stubs library. |
| 1452 | ctx.VisitDirectDeps(func(to android.Module) { |
| 1453 | tag := ctx.OtherModuleDependencyTag(to) |
| 1454 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1455 | if lib, ok := to.(Dependency); ok { |
| 1456 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1457 | apiScope := scopeTag.apiScope |
| 1458 | scopePaths := module.getScopePaths(apiScope) |
| 1459 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 1460 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1461 | } |
| 1462 | }) |
| 1463 | } |
| 1464 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1465 | func (module *sdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1466 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame^] | 1467 | // The java_sdk_library_import can only ever give back header jars as it does not |
| 1468 | // have an implementation jar. |
| 1469 | headerJars := true |
| 1470 | return module.sdkJarsCommon(ctx, sdkVersion, headerJars) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1473 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1474 | func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1475 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1476 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1480 | func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1481 | // This module is just a wrapper for the stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1482 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1483 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1484 | |
| 1485 | // |
| 1486 | // java_sdk_library_xml |
| 1487 | // |
| 1488 | type sdkLibraryXml struct { |
| 1489 | android.ModuleBase |
| 1490 | android.DefaultableModuleBase |
| 1491 | android.ApexModuleBase |
| 1492 | |
| 1493 | properties sdkLibraryXmlProperties |
| 1494 | |
| 1495 | outputFilePath android.OutputPath |
| 1496 | installDirPath android.InstallPath |
| 1497 | } |
| 1498 | |
| 1499 | type sdkLibraryXmlProperties struct { |
| 1500 | // canonical name of the lib |
| 1501 | Lib_name *string |
| 1502 | } |
| 1503 | |
| 1504 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. |
| 1505 | // Not to be used directly by users. java_sdk_library internally uses this. |
| 1506 | func sdkLibraryXmlFactory() android.Module { |
| 1507 | module := &sdkLibraryXml{} |
| 1508 | |
| 1509 | module.AddProperties(&module.properties) |
| 1510 | |
| 1511 | android.InitApexModule(module) |
| 1512 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1513 | |
| 1514 | return module |
| 1515 | } |
| 1516 | |
| 1517 | // from android.PrebuiltEtcModule |
| 1518 | func (module *sdkLibraryXml) SubDir() string { |
| 1519 | return "permissions" |
| 1520 | } |
| 1521 | |
| 1522 | // from android.PrebuiltEtcModule |
| 1523 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { |
| 1524 | return module.outputFilePath |
| 1525 | } |
| 1526 | |
| 1527 | // from android.ApexModule |
| 1528 | func (module *sdkLibraryXml) AvailableFor(what string) bool { |
| 1529 | return true |
| 1530 | } |
| 1531 | |
| 1532 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1533 | // do nothing |
| 1534 | } |
| 1535 | |
| 1536 | // File path to the runtime implementation library |
| 1537 | func (module *sdkLibraryXml) implPath() string { |
| 1538 | implName := proptools.String(module.properties.Lib_name) |
| 1539 | if apexName := module.ApexName(); apexName != "" { |
| 1540 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 1541 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 1542 | // this can be wrong. |
| 1543 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName) |
| 1544 | } |
| 1545 | partition := "system" |
| 1546 | if module.SocSpecific() { |
| 1547 | partition = "vendor" |
| 1548 | } else if module.DeviceSpecific() { |
| 1549 | partition = "odm" |
| 1550 | } else if module.ProductSpecific() { |
| 1551 | partition = "product" |
| 1552 | } else if module.SystemExtSpecific() { |
| 1553 | partition = "system_ext" |
| 1554 | } |
| 1555 | return "/" + partition + "/framework/" + implName + ".jar" |
| 1556 | } |
| 1557 | |
| 1558 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1559 | libName := proptools.String(module.properties.Lib_name) |
| 1560 | xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath()) |
| 1561 | |
| 1562 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath |
| 1563 | rule := android.NewRuleBuilder() |
| 1564 | rule.Command(). |
| 1565 | Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). |
| 1566 | Output(module.outputFilePath) |
| 1567 | |
| 1568 | rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML") |
| 1569 | |
| 1570 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) |
| 1571 | } |
| 1572 | |
| 1573 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { |
| 1574 | if !module.IsForPlatform() { |
| 1575 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1576 | Disabled: true, |
| 1577 | }} |
| 1578 | } |
| 1579 | |
| 1580 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1581 | Class: "ETC", |
| 1582 | OutputFile: android.OptionalPathForPath(module.outputFilePath), |
| 1583 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 1584 | func(entries *android.AndroidMkEntries) { |
| 1585 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
| 1586 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String()) |
| 1587 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) |
| 1588 | }, |
| 1589 | }, |
| 1590 | }} |
| 1591 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1592 | |
| 1593 | type sdkLibrarySdkMemberType struct { |
| 1594 | android.SdkMemberTypeBase |
| 1595 | } |
| 1596 | |
| 1597 | func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1598 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 1599 | } |
| 1600 | |
| 1601 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 1602 | _, ok := module.(*SdkLibrary) |
| 1603 | return ok |
| 1604 | } |
| 1605 | |
| 1606 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1607 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 1608 | } |
| 1609 | |
| 1610 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1611 | return &sdkLibrarySdkMemberProperties{} |
| 1612 | } |
| 1613 | |
| 1614 | type sdkLibrarySdkMemberProperties struct { |
| 1615 | android.SdkMemberPropertiesBase |
| 1616 | |
| 1617 | // Scope to per scope properties. |
| 1618 | Scopes map[*apiScope]scopeProperties |
| 1619 | |
| 1620 | // Additional libraries that the exported stubs libraries depend upon. |
| 1621 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1622 | |
| 1623 | // The Java stubs source files. |
| 1624 | Stub_srcs []string |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 1625 | |
| 1626 | // The naming scheme. |
| 1627 | Naming_scheme *string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1631 | Jars android.Paths |
| 1632 | StubsSrcJar android.Path |
| 1633 | CurrentApiFile android.Path |
| 1634 | RemovedApiFile android.Path |
| 1635 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 1639 | sdk := variant.(*SdkLibrary) |
| 1640 | |
| 1641 | s.Scopes = make(map[*apiScope]scopeProperties) |
| 1642 | for _, apiScope := range allApiScopes { |
| 1643 | paths := sdk.getScopePaths(apiScope) |
| 1644 | jars := paths.stubsImplPath |
| 1645 | if len(jars) > 0 { |
| 1646 | properties := scopeProperties{} |
| 1647 | properties.Jars = jars |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1648 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1649 | properties.StubsSrcJar = paths.stubsSrcJar |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1650 | properties.CurrentApiFile = paths.currentApiFilePath |
| 1651 | properties.RemovedApiFile = paths.removedApiFilePath |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1652 | s.Scopes[apiScope] = properties |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | s.Libs = sdk.properties.Libs |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 1657 | s.Naming_scheme = sdk.commonProperties.Naming_scheme |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 1661 | if s.Naming_scheme != nil { |
| 1662 | propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) |
| 1663 | } |
| 1664 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1665 | for _, apiScope := range allApiScopes { |
| 1666 | if properties, ok := s.Scopes[apiScope]; ok { |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 1667 | scopeSet := propertySet.AddPropertySet(apiScope.propertyName) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1668 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1669 | scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name) |
| 1670 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1671 | var jars []string |
| 1672 | for _, p := range properties.Jars { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1673 | dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1674 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 1675 | jars = append(jars, dest) |
| 1676 | } |
| 1677 | scopeSet.AddProperty("jars", jars) |
| 1678 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1679 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 1680 | // the source files are also unpacked. |
| 1681 | snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources") |
| 1682 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 1683 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 1684 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1685 | if properties.CurrentApiFile != nil { |
| 1686 | currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt") |
| 1687 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 1688 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 1689 | } |
| 1690 | |
| 1691 | if properties.RemovedApiFile != nil { |
| 1692 | removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt") |
| 1693 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath) |
| 1694 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 1695 | } |
| 1696 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1697 | if properties.SdkVersion != "" { |
| 1698 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | if len(s.Libs) > 0 { |
| 1704 | propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) |
| 1705 | } |
| 1706 | } |