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