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 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 194 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 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 { |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 482 | moduleBase *android.ModuleBase |
| 483 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 484 | scopePaths map[*apiScope]*scopePaths |
| 485 | } |
| 486 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 487 | func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) { |
| 488 | c.moduleBase = moduleBase |
| 489 | } |
| 490 | |
| 491 | // Name of the java_library module that compiles the stubs source. |
| 492 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { |
| 493 | return apiScope.stubsLibraryModuleName(c.moduleBase.BaseModuleName()) |
| 494 | } |
| 495 | |
| 496 | // Name of the droidstubs module that generates the stubs source and may also |
| 497 | // generate/check the API. |
| 498 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { |
| 499 | return apiScope.stubsSourceModuleName(c.moduleBase.BaseModuleName()) |
| 500 | } |
| 501 | |
| 502 | // Name of the droidstubs module that generates/checks the API. Only used if it |
| 503 | // requires different arts to the stubs source generating module. |
| 504 | func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string { |
| 505 | return apiScope.apiModuleName(c.moduleBase.BaseModuleName()) |
| 506 | } |
| 507 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 508 | func (c *commonToSdkLibraryAndImport) getScopePaths(scope *apiScope) *scopePaths { |
| 509 | if c.scopePaths == nil { |
| 510 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 511 | } |
| 512 | paths := c.scopePaths[scope] |
| 513 | if paths == nil { |
| 514 | paths = &scopePaths{} |
| 515 | c.scopePaths[scope] = paths |
| 516 | } |
| 517 | |
| 518 | return paths |
| 519 | } |
| 520 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 521 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 522 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 523 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 524 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 525 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 526 | // Map from api scope to the scope specific property structure. |
| 527 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 528 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 529 | commonToSdkLibraryAndImport |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 530 | } |
| 531 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 532 | var _ Dependency = (*SdkLibrary)(nil) |
| 533 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 534 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 535 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 536 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 537 | } |
| 538 | |
| 539 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 540 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 541 | // must be. |
| 542 | anyScopesExplicitlyEnabled := false |
| 543 | for _, scope := range allApiScopes { |
| 544 | scopeProperties := module.scopeToProperties[scope] |
| 545 | if scopeProperties.Enabled != nil { |
| 546 | anyScopesExplicitlyEnabled = true |
| 547 | break |
| 548 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 549 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 550 | |
| 551 | var generatedScopes apiScopes |
| 552 | enabledScopes := make(map[*apiScope]struct{}) |
| 553 | for _, scope := range allApiScopes { |
| 554 | scopeProperties := module.scopeToProperties[scope] |
| 555 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 556 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 557 | // behaviour. |
| 558 | defaultEnabledStatus := false |
| 559 | if anyScopesExplicitlyEnabled { |
| 560 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 561 | } else { |
| 562 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 563 | } |
| 564 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 565 | if enabled { |
| 566 | enabledScopes[scope] = struct{}{} |
| 567 | generatedScopes = append(generatedScopes, scope) |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 572 | // enabled. |
| 573 | for _, scope := range allApiScopes { |
| 574 | if _, ok := enabledScopes[scope]; ok { |
| 575 | extends := scope.extends |
| 576 | if extends != nil { |
| 577 | if _, ok := enabledScopes[extends]; !ok { |
| 578 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 587 | var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"} |
| 588 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 589 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
| 590 | if dt, ok := depTag.(dependencyTag); ok { |
| 591 | return dt == xmlPermissionsFileTag |
| 592 | } |
| 593 | return false |
| 594 | } |
| 595 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 596 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 597 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 598 | // Add dependencies to the stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 599 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 600 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 601 | // If the stubs source and API cannot be generated together then add an additional dependency on |
| 602 | // the API module. |
| 603 | if apiScope.createStubsSourceAndApiTogether { |
| 604 | // Add a dependency on the stubs source in order to access both stubs source and api information. |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 605 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 606 | } else { |
| 607 | // Add separate dependencies on the creators of the stubs source files and the API. |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 608 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope)) |
| 609 | ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 610 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 611 | } |
| 612 | |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 613 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 614 | // Add dependency to the rule for generating the xml permissions file |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 615 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlFileName()) |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 618 | module.Library.deps(ctx) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 619 | } |
| 620 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 621 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 622 | // Don't build an implementation library if this is api only. |
| 623 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 624 | module.Library.GenerateAndroidBuildActions(ctx) |
| 625 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 626 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 627 | // 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] | 628 | // 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] | 629 | // the recorded paths will be returned depending on the link type of the caller. |
| 630 | ctx.VisitDirectDeps(func(to android.Module) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 631 | tag := ctx.OtherModuleDependencyTag(to) |
| 632 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 633 | // Extract information from any of the scope specific dependencies. |
| 634 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 635 | apiScope := scopeTag.apiScope |
| 636 | scopePaths := module.getScopePaths(apiScope) |
| 637 | |
| 638 | // Extract information from the dependency. The exact information extracted |
| 639 | // is determined by the nature of the dependency which is determined by the tag. |
| 640 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 641 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 642 | }) |
| 643 | } |
| 644 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 645 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 646 | if proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 647 | return nil |
| 648 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 649 | entriesList := module.Library.AndroidMkEntries() |
| 650 | entries := &entriesList[0] |
Jaewoong Jung | b0c127c | 2019-08-29 14:56:03 -0700 | [diff] [blame] | 651 | entries.Required = append(entries.Required, module.xmlFileName()) |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 652 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 653 | } |
| 654 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 655 | // Module name of the runtime implementation library |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 656 | func (module *SdkLibrary) implName() string { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 657 | return module.BaseModuleName() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 658 | } |
| 659 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 660 | // Module name of the XML file for the lib |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 661 | func (module *SdkLibrary) xmlFileName() string { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 662 | return module.BaseModuleName() + sdkXmlFileSuffix |
| 663 | } |
| 664 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 665 | // The dist path of the stub artifacts |
| 666 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
| 667 | if module.ModuleBase.Owner() != "" { |
| 668 | return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name) |
| 669 | } else if Bool(module.sdkLibraryProperties.Core_lib) { |
| 670 | return path.Join("apistubs", "core", apiScope.name) |
| 671 | } else { |
| 672 | return path.Join("apistubs", "android", apiScope.name) |
| 673 | } |
| 674 | } |
| 675 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 676 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 677 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 678 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 679 | if sdkDep.hasStandardLibs() { |
| 680 | // 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] | 681 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 682 | } else { |
| 683 | // Otherwise, use no system module. |
| 684 | return "none" |
| 685 | } |
| 686 | } |
| 687 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 688 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
| 689 | return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 690 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 691 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 692 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
| 693 | return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // Creates a static java library that has API stubs |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 697 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 698 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 699 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 700 | Visibility []string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 701 | Srcs []string |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 702 | Installable *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 703 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 704 | System_modules *string |
Paul Duffin | ab8da5d | 2020-02-07 16:12:04 +0000 | [diff] [blame] | 705 | Patch_module *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 706 | Libs []string |
| 707 | Soc_specific *bool |
| 708 | Device_specific *bool |
| 709 | Product_specific *bool |
| 710 | System_ext_specific *bool |
| 711 | Compile_dex *bool |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 712 | Java_version *string |
| 713 | Product_variables struct { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 714 | Pdk struct { |
| 715 | Enabled *bool |
| 716 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 717 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 718 | Openjdk9 struct { |
| 719 | Srcs []string |
| 720 | Javacflags []string |
| 721 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 722 | Dist struct { |
| 723 | Targets []string |
| 724 | Dest *string |
| 725 | Dir *string |
| 726 | Tag *string |
| 727 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 728 | }{} |
| 729 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 730 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 731 | |
| 732 | // If stubs_library_visibility is not set then the created module will use the |
| 733 | // visibility of this module. |
| 734 | visibility := module.sdkLibraryProperties.Stubs_library_visibility |
| 735 | props.Visibility = visibility |
| 736 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 737 | // sources are generated from the droiddoc |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 738 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 739 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 740 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 741 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Paul Duffin | ab8da5d | 2020-02-07 16:12:04 +0000 | [diff] [blame] | 742 | props.Patch_module = module.Library.Module.properties.Patch_module |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 743 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 744 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 745 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 746 | props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs |
| 747 | props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags |
| 748 | props.Java_version = module.Library.Module.properties.Java_version |
| 749 | if module.Library.Module.deviceProperties.Compile_dex != nil { |
| 750 | props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 751 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 752 | |
| 753 | if module.SocSpecific() { |
| 754 | props.Soc_specific = proptools.BoolPtr(true) |
| 755 | } else if module.DeviceSpecific() { |
| 756 | props.Device_specific = proptools.BoolPtr(true) |
| 757 | } else if module.ProductSpecific() { |
| 758 | props.Product_specific = proptools.BoolPtr(true) |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 759 | } else if module.SystemExtSpecific() { |
| 760 | props.System_ext_specific = proptools.BoolPtr(true) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 761 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 762 | // Dist the class jar artifact for sdk builds. |
| 763 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 764 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 765 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName())) |
| 766 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) |
| 767 | props.Dist.Tag = proptools.StringPtr(".jar") |
| 768 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 769 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 770 | mctx.CreateModule(LibraryFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 771 | } |
| 772 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 773 | // 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] | 774 | // files and also updates and checks the API specification files. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 775 | 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] | 776 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 777 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 778 | Visibility []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 779 | Srcs []string |
| 780 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 781 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 782 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 783 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 784 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 785 | Args *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 786 | Java_version *string |
| 787 | Merge_annotations_dirs []string |
| 788 | Merge_inclusion_annotations_dirs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 789 | Generate_stubs *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 790 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 791 | Current ApiToCheck |
| 792 | Last_released ApiToCheck |
| 793 | Ignore_missing_latest_api *bool |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 794 | |
| 795 | Api_lint struct { |
| 796 | Enabled *bool |
| 797 | New_since *string |
| 798 | Baseline_file *string |
| 799 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 800 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 801 | Aidl struct { |
| 802 | Include_dirs []string |
| 803 | Local_include_dirs []string |
| 804 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 805 | Dist struct { |
| 806 | Targets []string |
| 807 | Dest *string |
| 808 | Dir *string |
| 809 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 810 | }{} |
| 811 | |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 812 | // The stubs source processing uses the same compile time classpath when extracting the |
| 813 | // API from the implementation library as it does when compiling it. i.e. the same |
| 814 | // * sdk version |
| 815 | // * system_modules |
| 816 | // * libs (static_libs/libs) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 817 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 818 | props.Name = proptools.StringPtr(name) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 819 | |
| 820 | // If stubs_source_visibility is not set then the created module will use the |
| 821 | // visibility of this module. |
| 822 | visibility := module.sdkLibraryProperties.Stubs_source_visibility |
| 823 | props.Visibility = visibility |
| 824 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 825 | props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...) |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 826 | props.Sdk_version = module.Library.Module.deviceProperties.Sdk_version |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 827 | props.System_modules = module.Library.Module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 828 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 829 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 830 | // 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] | 831 | props.Libs = module.Library.Module.properties.Libs |
| 832 | props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...) |
| 833 | props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs |
| 834 | 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] | 835 | props.Java_version = module.Library.Module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 836 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 837 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 838 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 839 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 840 | droidstubsArgs := []string{} |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 841 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 842 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 843 | } |
| 844 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 845 | droidstubsArgs = append(droidstubsArgs, |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 846 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 847 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 848 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 849 | disabledWarnings := []string{ |
| 850 | "MissingPermission", |
| 851 | "BroadcastBehavior", |
| 852 | "HiddenSuperclass", |
| 853 | "DeprecationMismatch", |
| 854 | "UnavailableSymbol", |
| 855 | "SdkConstant", |
| 856 | "HiddenTypeParameter", |
| 857 | "Todo", |
| 858 | "Typo", |
| 859 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 860 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 861 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 862 | if !createStubSources { |
| 863 | // Stubs are not required. |
| 864 | props.Generate_stubs = proptools.BoolPtr(false) |
| 865 | } |
| 866 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 867 | // Add in scope specific arguments. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 868 | droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 869 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 870 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 871 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 872 | if createApi { |
| 873 | // List of APIs identified from the provided source files are created. They are later |
| 874 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 875 | // last-released (a.k.a numbered) list of API. |
| 876 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 877 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
| 878 | apiDir := module.getApiDir() |
| 879 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 880 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 881 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 882 | // check against the not-yet-release API |
| 883 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 884 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 885 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 886 | if !apiScope.unstable { |
| 887 | // check against the latest released API |
| 888 | latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) |
| 889 | props.Check_api.Last_released.Api_file = latestApiFilegroupName |
| 890 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 891 | module.latestRemovedApiFilegroupName(apiScope)) |
| 892 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 893 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 894 | if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { |
| 895 | // Enable api lint. |
| 896 | props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) |
| 897 | props.Check_api.Api_lint.New_since = latestApiFilegroupName |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 898 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 899 | // If it exists then pass a lint-baseline.txt through to droidstubs. |
| 900 | baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") |
| 901 | baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) |
| 902 | paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) |
| 903 | if err != nil { |
| 904 | mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) |
| 905 | } |
| 906 | if len(paths) == 1 { |
| 907 | props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) |
| 908 | } else if len(paths) != 0 { |
| 909 | mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths) |
| 910 | } |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 911 | } |
| 912 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 913 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 914 | // Dist the api txt artifact for sdk builds. |
| 915 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 916 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 917 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName())) |
| 918 | props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) |
| 919 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 922 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 923 | } |
| 924 | |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 925 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 926 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 927 | if depTag == xmlPermissionsFileTag { |
| 928 | return true |
| 929 | } |
| 930 | return module.Library.DepIsInSameApex(mctx, dep) |
| 931 | } |
| 932 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 933 | // Creates the xml file that publicizes the runtime library |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 934 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 935 | props := struct { |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 936 | Name *string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 937 | Lib_name *string |
Sundong Ahn | 0d7dff4 | 2019-12-04 12:53:44 +0900 | [diff] [blame] | 938 | Soc_specific *bool |
| 939 | Device_specific *bool |
| 940 | Product_specific *bool |
| 941 | System_ext_specific *bool |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 942 | Apex_available []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 943 | }{ |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 944 | Name: proptools.StringPtr(module.xmlFileName()), |
| 945 | Lib_name: proptools.StringPtr(module.BaseModuleName()), |
| 946 | Apex_available: module.ApexProperties.Apex_available, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 947 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 948 | |
| 949 | if module.SocSpecific() { |
| 950 | props.Soc_specific = proptools.BoolPtr(true) |
| 951 | } else if module.DeviceSpecific() { |
| 952 | props.Device_specific = proptools.BoolPtr(true) |
| 953 | } else if module.ProductSpecific() { |
| 954 | props.Product_specific = proptools.BoolPtr(true) |
| 955 | } else if module.SystemExtSpecific() { |
| 956 | props.System_ext_specific = proptools.BoolPtr(true) |
| 957 | } |
| 958 | |
| 959 | mctx.CreateModule(sdkLibraryXmlFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 960 | } |
| 961 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 962 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 963 | var ver sdkVersion |
| 964 | var kind sdkKind |
| 965 | if s.usePrebuilt(ctx) { |
| 966 | ver = s.version |
| 967 | kind = s.kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 968 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 969 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 970 | // Instead of breaking the build, fallback to use "system_current" |
| 971 | ver = sdkVersionCurrent |
| 972 | kind = sdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 973 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 974 | |
| 975 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 976 | jar := filepath.Join(dir, baseName+".jar") |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 977 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 978 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 979 | if ctx.Config().AllowMissingDependencies() { |
| 980 | return android.Paths{android.PathForSource(ctx, jar)} |
| 981 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 982 | 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] | 983 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 984 | return nil |
| 985 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 986 | return android.Paths{jarPath.Path()} |
| 987 | } |
| 988 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 989 | func (module *SdkLibrary) sdkJars( |
| 990 | ctx android.BaseModuleContext, |
| 991 | sdkVersion sdkSpec, |
| 992 | headerJars bool) android.Paths { |
| 993 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 994 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 995 | if sdkVersion.version.isNumbered() { |
| 996 | return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 997 | } else { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 998 | if !sdkVersion.specified() { |
| 999 | if headerJars { |
| 1000 | return module.Library.HeaderJars() |
| 1001 | } else { |
| 1002 | return module.Library.ImplementationJars() |
| 1003 | } |
| 1004 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1005 | var apiScope *apiScope |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1006 | switch sdkVersion.kind { |
| 1007 | case sdkSystem: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1008 | apiScope = apiScopeSystem |
| 1009 | case sdkTest: |
| 1010 | apiScope = apiScopeTest |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1011 | case sdkPrivate: |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1012 | return module.Library.HeaderJars() |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1013 | default: |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1014 | apiScope = apiScopePublic |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1017 | paths := module.getScopePaths(apiScope) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1018 | if headerJars { |
| 1019 | return paths.stubsHeaderPath |
| 1020 | } else { |
| 1021 | return paths.stubsImplPath |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1022 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1026 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1027 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
| 1028 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 1029 | } |
| 1030 | |
| 1031 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1032 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1033 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1034 | } |
| 1035 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 1036 | func (module *SdkLibrary) SetNoDist() { |
| 1037 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 1038 | } |
| 1039 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1040 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 1041 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1042 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1043 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1044 | return &[]string{} |
| 1045 | }).(*[]string) |
| 1046 | } |
| 1047 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1048 | func (module *SdkLibrary) getApiDir() string { |
| 1049 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 1050 | } |
| 1051 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1052 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 1053 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 1054 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1055 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
| 1056 | // If the module has been disabled then don't create any child modules. |
| 1057 | if !module.Enabled() { |
| 1058 | return |
| 1059 | } |
| 1060 | |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 1061 | if len(module.Library.Module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1062 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1063 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1064 | } |
| 1065 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1066 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 1067 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 1068 | // also assume it does not contribute to the dist build. |
| 1069 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 1070 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1071 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1072 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 1073 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1074 | missing_current_api := false |
| 1075 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1076 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1077 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1078 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1079 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1080 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1081 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1082 | p := android.ExistentPathForSource(mctx, path) |
| 1083 | if !p.Valid() { |
| 1084 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 1085 | missing_current_api = true |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | if missing_current_api { |
| 1091 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 1092 | p := android.ExistentPathForSource(mctx, script) |
| 1093 | |
| 1094 | if !p.Valid() { |
| 1095 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 1096 | } |
| 1097 | |
| 1098 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 1099 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1100 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1101 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1102 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1103 | return |
| 1104 | } |
| 1105 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1106 | for _, scope := range generatedScopes { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1107 | stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1108 | stubsSourceModuleName := module.stubsSourceModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1109 | |
| 1110 | // If the args needed to generate the stubs and API are the same then they |
| 1111 | // can be generated in a single invocation of metalava, otherwise they will |
| 1112 | // need separate invocations. |
| 1113 | if scope.createStubsSourceAndApiTogether { |
| 1114 | // Use the stubs source name for legacy reasons. |
| 1115 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs) |
| 1116 | } else { |
| 1117 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs) |
| 1118 | |
| 1119 | apiArgs := scope.droidstubsArgsForGeneratingApi |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1120 | apiName := module.apiModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1121 | module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs) |
| 1122 | } |
| 1123 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1124 | module.createStubsLibrary(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1125 | } |
| 1126 | |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1127 | if !proptools.Bool(module.sdkLibraryProperties.Api_only) { |
| 1128 | // for runtime |
| 1129 | module.createXmlFile(mctx) |
| 1130 | |
| 1131 | // record java_sdk_library modules so that they are exported to make |
| 1132 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1133 | javaSdkLibrariesLock.Lock() |
| 1134 | defer javaSdkLibrariesLock.Unlock() |
| 1135 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1136 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1140 | module.AddProperties( |
| 1141 | &module.sdkLibraryProperties, |
| 1142 | &module.Library.Module.properties, |
| 1143 | &module.Library.Module.dexpreoptProperties, |
| 1144 | &module.Library.Module.deviceProperties, |
| 1145 | &module.Library.Module.protoProperties, |
| 1146 | ) |
| 1147 | |
| 1148 | module.Library.Module.properties.Installable = proptools.BoolPtr(true) |
| 1149 | module.Library.Module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1150 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1151 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1152 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 1153 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 1154 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 1155 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 1156 | // 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] | 1157 | func SdkLibraryFactory() android.Module { |
| 1158 | module := &SdkLibrary{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1159 | |
| 1160 | // Initialize information common between source and prebuilt. |
| 1161 | module.initCommon(&module.ModuleBase) |
| 1162 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1163 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1164 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1165 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1166 | |
| 1167 | // Initialize the map from scope to scope specific properties. |
| 1168 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
| 1169 | for _, scope := range allApiScopes { |
| 1170 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 1171 | } |
| 1172 | module.scopeToProperties = scopeToProperties |
| 1173 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1174 | // Add the properties containing visibility rules so that they are checked. |
| 1175 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 1176 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 1177 | |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1178 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { module.CreateInternalModules(ctx) }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1179 | return module |
| 1180 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1181 | |
| 1182 | // |
| 1183 | // SDK library prebuilts |
| 1184 | // |
| 1185 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1186 | // Properties associated with each api scope. |
| 1187 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1188 | Jars []string `android:"path"` |
| 1189 | |
| 1190 | Sdk_version *string |
| 1191 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1192 | // List of shared java libs that this module has dependencies to |
| 1193 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1194 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1195 | // The stubs source. |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1196 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1197 | |
| 1198 | // The current.txt |
| 1199 | Current_api string `android:"path"` |
| 1200 | |
| 1201 | // The removed.txt |
| 1202 | Removed_api string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1205 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 1206 | // List of shared java libs, common to all scopes, that this module has |
| 1207 | // dependencies to |
| 1208 | Libs []string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1211 | type sdkLibraryImport struct { |
| 1212 | android.ModuleBase |
| 1213 | android.DefaultableModuleBase |
| 1214 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1215 | android.ApexModuleBase |
| 1216 | android.SdkBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1217 | |
| 1218 | properties sdkLibraryImportProperties |
| 1219 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1220 | // Map from api scope to the scope specific property structure. |
| 1221 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 1222 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1223 | commonToSdkLibraryAndImport |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | var _ SdkLibraryDependency = (*sdkLibraryImport)(nil) |
| 1227 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1228 | // The type of a structure that contains a field of type sdkLibraryScopeProperties |
| 1229 | // for each apiscope in allApiScopes, e.g. something like: |
| 1230 | // struct { |
| 1231 | // Public sdkLibraryScopeProperties |
| 1232 | // System sdkLibraryScopeProperties |
| 1233 | // ... |
| 1234 | // } |
| 1235 | var allScopeStructType = createAllScopePropertiesStructType() |
| 1236 | |
| 1237 | // Dynamically create a structure type for each apiscope in allApiScopes. |
| 1238 | func createAllScopePropertiesStructType() reflect.Type { |
| 1239 | var fields []reflect.StructField |
| 1240 | for _, apiScope := range allApiScopes { |
| 1241 | field := reflect.StructField{ |
| 1242 | Name: apiScope.fieldName, |
| 1243 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), |
| 1244 | } |
| 1245 | fields = append(fields, field) |
| 1246 | } |
| 1247 | |
| 1248 | return reflect.StructOf(fields) |
| 1249 | } |
| 1250 | |
| 1251 | // Create an instance of the scope specific structure type and return a map |
| 1252 | // from apiscope to a pointer to each scope specific field. |
| 1253 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { |
| 1254 | allScopePropertiesPtr := reflect.New(allScopeStructType) |
| 1255 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() |
| 1256 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 1257 | |
| 1258 | for _, apiScope := range allApiScopes { |
| 1259 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) |
| 1260 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) |
| 1261 | } |
| 1262 | |
| 1263 | return allScopePropertiesPtr.Interface(), scopeProperties |
| 1264 | } |
| 1265 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1266 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1267 | func sdkLibraryImportFactory() android.Module { |
| 1268 | module := &sdkLibraryImport{} |
| 1269 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1270 | allScopeProperties, scopeToProperties := createPropertiesInstance() |
| 1271 | module.scopeProperties = scopeToProperties |
| 1272 | module.AddProperties(&module.properties, allScopeProperties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1273 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1274 | // Initialize information common between source and prebuilt. |
| 1275 | module.initCommon(&module.ModuleBase) |
| 1276 | |
Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 1277 | android.InitPrebuiltModule(module, &[]string{""}) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1278 | android.InitApexModule(module) |
| 1279 | android.InitSdkAwareModule(module) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1280 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1281 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1282 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { module.createInternalModules(mctx) }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1283 | return module |
| 1284 | } |
| 1285 | |
| 1286 | func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt { |
| 1287 | return &module.prebuilt |
| 1288 | } |
| 1289 | |
| 1290 | func (module *sdkLibraryImport) Name() string { |
| 1291 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 1292 | } |
| 1293 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1294 | func (module *sdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1295 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1296 | // If the build is configured to use prebuilts then force this to be preferred. |
| 1297 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1298 | module.prebuilt.ForcePrefer() |
| 1299 | } |
| 1300 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1301 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1302 | if len(scopeProperties.Jars) == 0 { |
| 1303 | continue |
| 1304 | } |
| 1305 | |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1306 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1307 | |
| 1308 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1309 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1310 | |
| 1311 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1312 | javaSdkLibrariesLock.Lock() |
| 1313 | defer javaSdkLibrariesLock.Unlock() |
| 1314 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1315 | } |
| 1316 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1317 | func (module *sdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1318 | // Creates a java import for the jar with ".stubs" suffix |
| 1319 | props := struct { |
| 1320 | Name *string |
| 1321 | Soc_specific *bool |
| 1322 | Device_specific *bool |
| 1323 | Product_specific *bool |
| 1324 | System_ext_specific *bool |
| 1325 | Sdk_version *string |
| 1326 | Libs []string |
| 1327 | Jars []string |
| 1328 | Prefer *bool |
| 1329 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1330 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1331 | props.Sdk_version = scopeProperties.Sdk_version |
| 1332 | // Prepend any of the libs from the legacy public properties to the libs for each of the |
| 1333 | // scopes to avoid having to duplicate them in each scope. |
| 1334 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) |
| 1335 | props.Jars = scopeProperties.Jars |
| 1336 | if module.SocSpecific() { |
| 1337 | props.Soc_specific = proptools.BoolPtr(true) |
| 1338 | } else if module.DeviceSpecific() { |
| 1339 | props.Device_specific = proptools.BoolPtr(true) |
| 1340 | } else if module.ProductSpecific() { |
| 1341 | props.Product_specific = proptools.BoolPtr(true) |
| 1342 | } else if module.SystemExtSpecific() { |
| 1343 | props.System_ext_specific = proptools.BoolPtr(true) |
| 1344 | } |
| 1345 | // If the build should use prebuilt sdks then set prefer to true on the stubs library. |
| 1346 | // That will cause the prebuilt version of the stubs to override the source version. |
| 1347 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1348 | props.Prefer = proptools.BoolPtr(true) |
| 1349 | } |
| 1350 | mctx.CreateModule(ImportFactory, &props) |
| 1351 | } |
| 1352 | |
Paul Duffin | 6e7ecbf | 2020-05-08 15:01:19 +0100 | [diff] [blame] | 1353 | func (module *sdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1354 | props := struct { |
| 1355 | Name *string |
| 1356 | Srcs []string |
| 1357 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1358 | props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1359 | props.Srcs = scopeProperties.Stub_srcs |
| 1360 | mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) |
| 1361 | } |
| 1362 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1363 | func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1364 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1365 | if len(scopeProperties.Jars) == 0 { |
| 1366 | continue |
| 1367 | } |
| 1368 | |
| 1369 | // Add dependencies to the prebuilt stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame^] | 1370 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1371 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1375 | // Record the paths to the prebuilt stubs library. |
| 1376 | ctx.VisitDirectDeps(func(to android.Module) { |
| 1377 | tag := ctx.OtherModuleDependencyTag(to) |
| 1378 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1379 | if lib, ok := to.(Dependency); ok { |
| 1380 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1381 | apiScope := scopeTag.apiScope |
| 1382 | scopePaths := module.getScopePaths(apiScope) |
| 1383 | scopePaths.stubsHeaderPath = lib.HeaderJars() |
| 1384 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1385 | } |
| 1386 | }) |
| 1387 | } |
| 1388 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1389 | func (module *sdkLibraryImport) sdkJars( |
| 1390 | ctx android.BaseModuleContext, |
| 1391 | sdkVersion sdkSpec) android.Paths { |
| 1392 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1393 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 1394 | if sdkVersion.version.isNumbered() { |
| 1395 | return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) |
| 1396 | } |
| 1397 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1398 | var apiScope *apiScope |
| 1399 | switch sdkVersion.kind { |
| 1400 | case sdkSystem: |
| 1401 | apiScope = apiScopeSystem |
| 1402 | case sdkTest: |
| 1403 | apiScope = apiScopeTest |
| 1404 | default: |
| 1405 | apiScope = apiScopePublic |
| 1406 | } |
| 1407 | |
| 1408 | paths := module.getScopePaths(apiScope) |
| 1409 | return paths.stubsHeaderPath |
| 1410 | } |
| 1411 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1412 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1413 | func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1414 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1415 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1419 | func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1420 | // This module is just a wrapper for the stubs. |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1421 | return module.sdkJars(ctx, sdkVersion) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1422 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1423 | |
| 1424 | // |
| 1425 | // java_sdk_library_xml |
| 1426 | // |
| 1427 | type sdkLibraryXml struct { |
| 1428 | android.ModuleBase |
| 1429 | android.DefaultableModuleBase |
| 1430 | android.ApexModuleBase |
| 1431 | |
| 1432 | properties sdkLibraryXmlProperties |
| 1433 | |
| 1434 | outputFilePath android.OutputPath |
| 1435 | installDirPath android.InstallPath |
| 1436 | } |
| 1437 | |
| 1438 | type sdkLibraryXmlProperties struct { |
| 1439 | // canonical name of the lib |
| 1440 | Lib_name *string |
| 1441 | } |
| 1442 | |
| 1443 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. |
| 1444 | // Not to be used directly by users. java_sdk_library internally uses this. |
| 1445 | func sdkLibraryXmlFactory() android.Module { |
| 1446 | module := &sdkLibraryXml{} |
| 1447 | |
| 1448 | module.AddProperties(&module.properties) |
| 1449 | |
| 1450 | android.InitApexModule(module) |
| 1451 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 1452 | |
| 1453 | return module |
| 1454 | } |
| 1455 | |
| 1456 | // from android.PrebuiltEtcModule |
| 1457 | func (module *sdkLibraryXml) SubDir() string { |
| 1458 | return "permissions" |
| 1459 | } |
| 1460 | |
| 1461 | // from android.PrebuiltEtcModule |
| 1462 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { |
| 1463 | return module.outputFilePath |
| 1464 | } |
| 1465 | |
| 1466 | // from android.ApexModule |
| 1467 | func (module *sdkLibraryXml) AvailableFor(what string) bool { |
| 1468 | return true |
| 1469 | } |
| 1470 | |
| 1471 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1472 | // do nothing |
| 1473 | } |
| 1474 | |
| 1475 | // File path to the runtime implementation library |
| 1476 | func (module *sdkLibraryXml) implPath() string { |
| 1477 | implName := proptools.String(module.properties.Lib_name) |
| 1478 | if apexName := module.ApexName(); apexName != "" { |
| 1479 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 1480 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 1481 | // this can be wrong. |
| 1482 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName) |
| 1483 | } |
| 1484 | partition := "system" |
| 1485 | if module.SocSpecific() { |
| 1486 | partition = "vendor" |
| 1487 | } else if module.DeviceSpecific() { |
| 1488 | partition = "odm" |
| 1489 | } else if module.ProductSpecific() { |
| 1490 | partition = "product" |
| 1491 | } else if module.SystemExtSpecific() { |
| 1492 | partition = "system_ext" |
| 1493 | } |
| 1494 | return "/" + partition + "/framework/" + implName + ".jar" |
| 1495 | } |
| 1496 | |
| 1497 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1498 | libName := proptools.String(module.properties.Lib_name) |
| 1499 | xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath()) |
| 1500 | |
| 1501 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath |
| 1502 | rule := android.NewRuleBuilder() |
| 1503 | rule.Command(). |
| 1504 | Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). |
| 1505 | Output(module.outputFilePath) |
| 1506 | |
| 1507 | rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML") |
| 1508 | |
| 1509 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) |
| 1510 | } |
| 1511 | |
| 1512 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { |
| 1513 | if !module.IsForPlatform() { |
| 1514 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1515 | Disabled: true, |
| 1516 | }} |
| 1517 | } |
| 1518 | |
| 1519 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 1520 | Class: "ETC", |
| 1521 | OutputFile: android.OptionalPathForPath(module.outputFilePath), |
| 1522 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 1523 | func(entries *android.AndroidMkEntries) { |
| 1524 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
| 1525 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String()) |
| 1526 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) |
| 1527 | }, |
| 1528 | }, |
| 1529 | }} |
| 1530 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1531 | |
| 1532 | type sdkLibrarySdkMemberType struct { |
| 1533 | android.SdkMemberTypeBase |
| 1534 | } |
| 1535 | |
| 1536 | func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1537 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 1538 | } |
| 1539 | |
| 1540 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 1541 | _, ok := module.(*SdkLibrary) |
| 1542 | return ok |
| 1543 | } |
| 1544 | |
| 1545 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1546 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 1547 | } |
| 1548 | |
| 1549 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1550 | return &sdkLibrarySdkMemberProperties{} |
| 1551 | } |
| 1552 | |
| 1553 | type sdkLibrarySdkMemberProperties struct { |
| 1554 | android.SdkMemberPropertiesBase |
| 1555 | |
| 1556 | // Scope to per scope properties. |
| 1557 | Scopes map[*apiScope]scopeProperties |
| 1558 | |
| 1559 | // Additional libraries that the exported stubs libraries depend upon. |
| 1560 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1561 | |
| 1562 | // The Java stubs source files. |
| 1563 | Stub_srcs []string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1567 | Jars android.Paths |
| 1568 | StubsSrcJar android.Path |
| 1569 | CurrentApiFile android.Path |
| 1570 | RemovedApiFile android.Path |
| 1571 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 1575 | sdk := variant.(*SdkLibrary) |
| 1576 | |
| 1577 | s.Scopes = make(map[*apiScope]scopeProperties) |
| 1578 | for _, apiScope := range allApiScopes { |
| 1579 | paths := sdk.getScopePaths(apiScope) |
| 1580 | jars := paths.stubsImplPath |
| 1581 | if len(jars) > 0 { |
| 1582 | properties := scopeProperties{} |
| 1583 | properties.Jars = jars |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1584 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1585 | properties.StubsSrcJar = paths.stubsSrcJar |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1586 | properties.CurrentApiFile = paths.currentApiFilePath |
| 1587 | properties.RemovedApiFile = paths.removedApiFilePath |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1588 | s.Scopes[apiScope] = properties |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | s.Libs = sdk.properties.Libs |
| 1593 | } |
| 1594 | |
| 1595 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
| 1596 | for _, apiScope := range allApiScopes { |
| 1597 | if properties, ok := s.Scopes[apiScope]; ok { |
| 1598 | scopeSet := propertySet.AddPropertySet(apiScope.name) |
| 1599 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1600 | scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name) |
| 1601 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1602 | var jars []string |
| 1603 | for _, p := range properties.Jars { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1604 | dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1605 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 1606 | jars = append(jars, dest) |
| 1607 | } |
| 1608 | scopeSet.AddProperty("jars", jars) |
| 1609 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1610 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 1611 | // the source files are also unpacked. |
| 1612 | snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources") |
| 1613 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 1614 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 1615 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1616 | if properties.CurrentApiFile != nil { |
| 1617 | currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt") |
| 1618 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 1619 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 1620 | } |
| 1621 | |
| 1622 | if properties.RemovedApiFile != nil { |
| 1623 | removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt") |
| 1624 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, removedApiSnapshotPath) |
| 1625 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 1626 | } |
| 1627 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1628 | if properties.SdkVersion != "" { |
| 1629 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | if len(s.Libs) > 0 { |
| 1635 | propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) |
| 1636 | } |
| 1637 | } |