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