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