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" |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 22 | "regexp" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 23 | "sort" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 24 | "strings" |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 25 | "sync" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 26 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 29 | |
| 30 | "android/soong/android" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 33 | const ( |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 34 | sdkXmlFileSuffix = ".xml" |
| 35 | permissionsTemplate = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 36 | `<!-- Copyright (C) 2018 The Android Open Source Project\n` + |
| 37 | `\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 38 | ` Licensed under the Apache License, Version 2.0 (the \"License\");\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 39 | ` you may not use this file except in compliance with the License.\n` + |
| 40 | ` You may obtain a copy of the License at\n` + |
| 41 | `\n` + |
| 42 | ` http://www.apache.org/licenses/LICENSE-2.0\n` + |
| 43 | `\n` + |
| 44 | ` Unless required by applicable law or agreed to in writing, software\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 45 | ` distributed under the License is distributed on an \"AS IS\" BASIS,\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 46 | ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` + |
| 47 | ` See the License for the specific language governing permissions and\n` + |
| 48 | ` limitations under the License.\n` + |
| 49 | `-->\n` + |
| 50 | `<permissions>\n` + |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 51 | ` <library name=\"%s\" file=\"%s\"/>\n` + |
Jooyung Han | 624058e | 2019-12-24 18:38:06 +0900 | [diff] [blame] | 52 | `</permissions>\n` |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 53 | ) |
| 54 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 55 | // A tag to associated a dependency with a specific api scope. |
| 56 | type scopeDependencyTag struct { |
| 57 | blueprint.BaseDependencyTag |
| 58 | name string |
| 59 | apiScope *apiScope |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 60 | |
| 61 | // Function for extracting appropriate path information from the dependency. |
| 62 | depInfoExtractor func(paths *scopePaths, dep android.Module) error |
| 63 | } |
| 64 | |
| 65 | // Extract tag specific information from the dependency. |
| 66 | func (tag scopeDependencyTag) extractDepInfo(ctx android.ModuleContext, dep android.Module, paths *scopePaths) { |
| 67 | err := tag.depInfoExtractor(paths, dep) |
| 68 | if err != nil { |
| 69 | ctx.ModuleErrorf("has an invalid {scopeDependencyTag: %s} dependency on module %s: %s", tag.name, ctx.OtherModuleName(dep), err.Error()) |
| 70 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // Provides information about an api scope, e.g. public, system, test. |
| 74 | type apiScope struct { |
| 75 | // The name of the api scope, e.g. public, system, test |
| 76 | name string |
| 77 | |
Paul Duffin | 97b53b8 | 2020-05-05 14:40:52 +0100 | [diff] [blame] | 78 | // The api scope that this scope extends. |
| 79 | extends *apiScope |
| 80 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 81 | // The legacy enabled status for a specific scope can be dependent on other |
| 82 | // properties that have been specified on the library so it is provided by |
| 83 | // a function that can determine the status by examining those properties. |
| 84 | legacyEnabledStatus func(module *SdkLibrary) bool |
| 85 | |
| 86 | // The default enabled status for non-legacy behavior, which is triggered by |
| 87 | // explicitly enabling at least one api scope. |
| 88 | defaultEnabledStatus bool |
| 89 | |
| 90 | // Gets a pointer to the scope specific properties. |
| 91 | scopeSpecificProperties func(module *SdkLibrary) *ApiScopeProperties |
| 92 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 93 | // The name of the field in the dynamically created structure. |
| 94 | fieldName string |
| 95 | |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 96 | // The name of the property in the java_sdk_library_import |
| 97 | propertyName string |
| 98 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 99 | // The tag to use to depend on the stubs library module. |
| 100 | stubsTag scopeDependencyTag |
| 101 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 102 | // The tag to use to depend on the stubs source module (if separate from the API module). |
| 103 | stubsSourceTag scopeDependencyTag |
| 104 | |
| 105 | // The tag to use to depend on the API file generating module (if separate from the stubs source module). |
| 106 | apiFileTag scopeDependencyTag |
| 107 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 108 | // The tag to use to depend on the stubs source and API module. |
| 109 | stubsSourceAndApiTag scopeDependencyTag |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 110 | |
| 111 | // The scope specific prefix to add to the api file base of "current.txt" or "removed.txt". |
| 112 | apiFilePrefix string |
| 113 | |
| 114 | // The scope specific prefix to add to the sdk library module name to construct a scope specific |
| 115 | // module name. |
| 116 | moduleSuffix string |
| 117 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 118 | // SDK version that the stubs library is built against. Note that this is always |
| 119 | // *current. Older stubs library built with a numbered SDK version is created from |
| 120 | // the prebuilt jar. |
| 121 | sdkVersion string |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 122 | |
| 123 | // Extra arguments to pass to droidstubs for this scope. |
| 124 | droidstubsArgs []string |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 125 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 126 | // The args that must be passed to droidstubs to generate the stubs source |
| 127 | // for this scope. |
| 128 | // |
| 129 | // The stubs source must include the definitions of everything that is in this |
| 130 | // api scope and all the scopes that this one extends. |
| 131 | droidstubsArgsForGeneratingStubsSource []string |
| 132 | |
| 133 | // The args that must be passed to droidstubs to generate the API for this scope. |
| 134 | // |
| 135 | // The API only includes the additional members that this scope adds over the scope |
| 136 | // that it extends. |
| 137 | droidstubsArgsForGeneratingApi []string |
| 138 | |
| 139 | // True if the stubs source and api can be created by the same metalava invocation. |
| 140 | createStubsSourceAndApiTogether bool |
| 141 | |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 142 | // Whether the api scope can be treated as unstable, and should skip compat checks. |
| 143 | unstable bool |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // Initialize a scope, creating and adding appropriate dependency tags |
| 147 | func initApiScope(scope *apiScope) *apiScope { |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 148 | name := scope.name |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 149 | scopeByName[name] = scope |
| 150 | allScopeNames = append(allScopeNames, name) |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 151 | scope.propertyName = strings.ReplaceAll(name, "-", "_") |
| 152 | scope.fieldName = proptools.FieldNameForProperty(scope.propertyName) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 153 | scope.stubsTag = scopeDependencyTag{ |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 154 | name: name + "-stubs", |
| 155 | apiScope: scope, |
| 156 | depInfoExtractor: (*scopePaths).extractStubsLibraryInfoFromDependency, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 157 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 158 | scope.stubsSourceTag = scopeDependencyTag{ |
| 159 | name: name + "-stubs-source", |
| 160 | apiScope: scope, |
| 161 | depInfoExtractor: (*scopePaths).extractStubsSourceInfoFromDep, |
| 162 | } |
| 163 | scope.apiFileTag = scopeDependencyTag{ |
| 164 | name: name + "-api", |
| 165 | apiScope: scope, |
| 166 | depInfoExtractor: (*scopePaths).extractApiInfoFromDep, |
| 167 | } |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 168 | scope.stubsSourceAndApiTag = scopeDependencyTag{ |
| 169 | name: name + "-stubs-source-and-api", |
| 170 | apiScope: scope, |
| 171 | depInfoExtractor: (*scopePaths).extractStubsSourceAndApiInfoFromApiStubsProvider, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 172 | } |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 173 | |
| 174 | // To get the args needed to generate the stubs source append all the args from |
| 175 | // this scope and all the scopes it extends as each set of args adds additional |
| 176 | // members to the stubs. |
| 177 | var stubsSourceArgs []string |
| 178 | for s := scope; s != nil; s = s.extends { |
| 179 | stubsSourceArgs = append(stubsSourceArgs, s.droidstubsArgs...) |
| 180 | } |
| 181 | scope.droidstubsArgsForGeneratingStubsSource = stubsSourceArgs |
| 182 | |
| 183 | // Currently the args needed to generate the API are the same as the args |
| 184 | // needed to add additional members. |
| 185 | apiArgs := scope.droidstubsArgs |
| 186 | scope.droidstubsArgsForGeneratingApi = apiArgs |
| 187 | |
| 188 | // If the args needed to generate the stubs and API are the same then they |
| 189 | // can be generated in a single invocation of metalava, otherwise they will |
| 190 | // need separate invocations. |
| 191 | scope.createStubsSourceAndApiTogether = reflect.DeepEqual(stubsSourceArgs, apiArgs) |
| 192 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 193 | return scope |
| 194 | } |
| 195 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 196 | func (scope *apiScope) stubsLibraryModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 197 | return baseName + ".stubs" + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 200 | func (scope *apiScope) stubsSourceModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 201 | return baseName + ".stubs.source" + scope.moduleSuffix |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 204 | func (scope *apiScope) apiModuleName(baseName string) string { |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 205 | return baseName + ".api" + scope.moduleSuffix |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 208 | func (scope *apiScope) String() string { |
| 209 | return scope.name |
| 210 | } |
| 211 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 212 | type apiScopes []*apiScope |
| 213 | |
| 214 | func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string { |
| 215 | var list []string |
| 216 | for _, scope := range scopes { |
| 217 | list = append(list, accessor(scope)) |
| 218 | } |
| 219 | return list |
| 220 | } |
| 221 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 222 | var ( |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 223 | scopeByName = make(map[string]*apiScope) |
| 224 | allScopeNames []string |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 225 | apiScopePublic = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 226 | name: "public", |
| 227 | |
| 228 | // Public scope is enabled by default for both legacy and non-legacy modes. |
| 229 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 230 | return true |
| 231 | }, |
| 232 | defaultEnabledStatus: true, |
| 233 | |
| 234 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 235 | return &module.sdkLibraryProperties.Public |
| 236 | }, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 237 | sdkVersion: "current", |
| 238 | }) |
| 239 | apiScopeSystem = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 240 | name: "system", |
| 241 | extends: apiScopePublic, |
| 242 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 243 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 244 | return &module.sdkLibraryProperties.System |
| 245 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 246 | apiFilePrefix: "system-", |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 247 | moduleSuffix: ".system", |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 248 | sdkVersion: "system_current", |
Paul Duffin | 0d54364 | 2020-04-29 22:18:41 +0100 | [diff] [blame] | 249 | 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] | 250 | }) |
| 251 | apiScopeTest = initApiScope(&apiScope{ |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 252 | name: "test", |
| 253 | extends: apiScopePublic, |
| 254 | legacyEnabledStatus: (*SdkLibrary).generateTestAndSystemScopesByDefault, |
| 255 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 256 | return &module.sdkLibraryProperties.Test |
| 257 | }, |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 258 | apiFilePrefix: "test-", |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 259 | moduleSuffix: ".test", |
Anton Hansson | 6affb1f | 2020-04-28 16:47:41 +0100 | [diff] [blame] | 260 | sdkVersion: "test_current", |
| 261 | droidstubsArgs: []string{"-showAnnotation android.annotation.TestApi"}, |
Anton Hansson | 6478ac1 | 2020-05-02 11:19:36 +0100 | [diff] [blame] | 262 | unstable: true, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 263 | }) |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 264 | apiScopeModuleLib = initApiScope(&apiScope{ |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 265 | name: "module-lib", |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 266 | extends: apiScopeSystem, |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 267 | // The module-lib scope is disabled by default in legacy mode. |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 268 | // |
| 269 | // Enabling this would break existing usages. |
| 270 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 271 | return false |
| 272 | }, |
| 273 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 274 | return &module.sdkLibraryProperties.Module_lib |
| 275 | }, |
| 276 | apiFilePrefix: "module-lib-", |
| 277 | moduleSuffix: ".module_lib", |
| 278 | sdkVersion: "module_current", |
| 279 | droidstubsArgs: []string{ |
| 280 | "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.MODULE_LIBRARIES\\)", |
| 281 | }, |
| 282 | }) |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 283 | apiScopeSystemServer = initApiScope(&apiScope{ |
| 284 | name: "system-server", |
| 285 | extends: apiScopePublic, |
| 286 | // The system-server scope is disabled by default in legacy mode. |
| 287 | // |
| 288 | // Enabling this would break existing usages. |
| 289 | legacyEnabledStatus: func(module *SdkLibrary) bool { |
| 290 | return false |
| 291 | }, |
| 292 | scopeSpecificProperties: func(module *SdkLibrary) *ApiScopeProperties { |
| 293 | return &module.sdkLibraryProperties.System_server |
| 294 | }, |
| 295 | apiFilePrefix: "system-server-", |
| 296 | moduleSuffix: ".system_server", |
| 297 | sdkVersion: "system_server_current", |
| 298 | droidstubsArgs: []string{ |
| 299 | "--show-annotation android.annotation.SystemApi\\(client=android.annotation.SystemApi.Client.SYSTEM_SERVER\\) ", |
| 300 | "--hide-annotation android.annotation.Hide", |
| 301 | // com.android.* classes are okay in this interface" |
| 302 | "--hide InternalClasses", |
| 303 | }, |
| 304 | }) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 305 | allApiScopes = apiScopes{ |
| 306 | apiScopePublic, |
| 307 | apiScopeSystem, |
| 308 | apiScopeTest, |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 309 | apiScopeModuleLib, |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 310 | apiScopeSystemServer, |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 311 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 312 | ) |
| 313 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 314 | var ( |
| 315 | javaSdkLibrariesLock sync.Mutex |
| 316 | ) |
| 317 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 318 | // TODO: these are big features that are currently missing |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 319 | // 1) disallowing linking to the runtime shared lib |
| 320 | // 2) HTML generation |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 321 | |
| 322 | func init() { |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 323 | RegisterSdkLibraryBuildComponents(android.InitRegistrationContext) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 324 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 325 | android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) { |
| 326 | javaSdkLibraries := javaSdkLibraries(ctx.Config()) |
| 327 | sort.Strings(*javaSdkLibraries) |
| 328 | ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " ")) |
| 329 | }) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 330 | |
| 331 | // Register sdk member types. |
| 332 | android.RegisterSdkMemberType(&sdkLibrarySdkMemberType{ |
| 333 | android.SdkMemberTypeBase{ |
| 334 | PropertyName: "java_sdk_libs", |
| 335 | SupportsSdk: true, |
| 336 | }, |
| 337 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 338 | } |
| 339 | |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 340 | func RegisterSdkLibraryBuildComponents(ctx android.RegistrationContext) { |
| 341 | ctx.RegisterModuleType("java_sdk_library", SdkLibraryFactory) |
| 342 | ctx.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory) |
| 343 | } |
| 344 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 345 | // Properties associated with each api scope. |
| 346 | type ApiScopeProperties struct { |
| 347 | // Indicates whether the api surface is generated. |
| 348 | // |
| 349 | // If this is set for any scope then all scopes must explicitly specify if they |
| 350 | // are enabled. This is to prevent new usages from depending on legacy behavior. |
| 351 | // |
| 352 | // Otherwise, if this is not set for any scope then the default behavior is |
| 353 | // scope specific so please refer to the scope specific property documentation. |
| 354 | Enabled *bool |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 355 | |
| 356 | // The sdk_version to use for building the stubs. |
| 357 | // |
| 358 | // If not specified then it will use an sdk_version determined as follows: |
| 359 | // 1) If the sdk_version specified on the java_sdk_library is none then this |
| 360 | // will be none. This is used for java_sdk_library instances that are used |
| 361 | // to create stubs that contribute to the core_current sdk version. |
| 362 | // 2) Otherwise, it is assumed that this library extends but does not contribute |
| 363 | // directly to a specific sdk_version and so this uses the sdk_version appropriate |
| 364 | // for the api scope. e.g. public will use sdk_version: current, system will use |
| 365 | // sdk_version: system_current, etc. |
| 366 | // |
| 367 | // This does not affect the sdk_version used for either generating the stubs source |
| 368 | // or the API file. They both have to use the same sdk_version as is used for |
| 369 | // compiling the implementation library. |
| 370 | Sdk_version *string |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 373 | type sdkLibraryProperties struct { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 374 | // Visibility for impl library module. If not specified then defaults to the |
| 375 | // visibility property. |
| 376 | Impl_library_visibility []string |
| 377 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 378 | // Visibility for stubs library modules. If not specified then defaults to the |
| 379 | // visibility property. |
| 380 | Stubs_library_visibility []string |
| 381 | |
| 382 | // Visibility for stubs source modules. If not specified then defaults to the |
| 383 | // visibility property. |
| 384 | Stubs_source_visibility []string |
| 385 | |
Sundong Ahn | f043cf6 | 2018-06-25 16:04:37 +0900 | [diff] [blame] | 386 | // List of Java libraries that will be in the classpath when building stubs |
| 387 | Stub_only_libs []string `android:"arch_variant"` |
| 388 | |
Paul Duffin | 7a586d3 | 2019-12-30 17:09:34 +0000 | [diff] [blame] | 389 | // list of package names that will be documented and publicized as API. |
| 390 | // This allows the API to be restricted to a subset of the source files provided. |
| 391 | // If this is unspecified then all the source files will be treated as being part |
| 392 | // of the API. |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 393 | Api_packages []string |
| 394 | |
Jiyong Park | 5a2c9d7 | 2018-05-01 22:25:41 +0900 | [diff] [blame] | 395 | // list of package names that must be hidden from the API |
| 396 | Hidden_api_packages []string |
| 397 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 398 | // the relative path to the directory containing the api specification files. |
| 399 | // Defaults to "api". |
| 400 | Api_dir *string |
| 401 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 402 | // Determines whether a runtime implementation library is built; defaults to false. |
| 403 | // |
| 404 | // If true then it also prevents the module from being used as a shared module, i.e. |
| 405 | // it is as is shared_library: false, was set. |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 406 | Api_only *bool |
| 407 | |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 408 | // local files that are used within user customized droiddoc options. |
| 409 | Droiddoc_option_files []string |
| 410 | |
| 411 | // additional droiddoc options |
| 412 | // Available variables for substitution: |
| 413 | // |
| 414 | // $(location <label>): the path to the droiddoc_option_files with name <label> |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 415 | Droiddoc_options []string |
| 416 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 417 | // a list of top-level directories containing files to merge qualifier annotations |
| 418 | // (i.e. those intended to be included in the stubs written) from. |
| 419 | Merge_annotations_dirs []string |
| 420 | |
| 421 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 422 | Merge_inclusion_annotations_dirs []string |
| 423 | |
| 424 | // If set to true, the path of dist files is apistubs/core. Defaults to false. |
| 425 | Core_lib *bool |
| 426 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 427 | // don't create dist rules. |
| 428 | No_dist *bool `blueprint:"mutated"` |
| 429 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 430 | // indicates whether system and test apis should be generated. |
| 431 | Generate_system_and_test_apis bool `blueprint:"mutated"` |
| 432 | |
| 433 | // The properties specific to the public api scope |
| 434 | // |
| 435 | // Unless explicitly specified by using public.enabled the public api scope is |
| 436 | // enabled by default in both legacy and non-legacy mode. |
| 437 | Public ApiScopeProperties |
| 438 | |
| 439 | // The properties specific to the system api scope |
| 440 | // |
| 441 | // In legacy mode the system api scope is enabled by default when sdk_version |
| 442 | // is set to something other than "none". |
| 443 | // |
| 444 | // In non-legacy mode the system api scope is disabled by default. |
| 445 | System ApiScopeProperties |
| 446 | |
| 447 | // The properties specific to the test api scope |
| 448 | // |
| 449 | // In legacy mode the test api scope is enabled by default when sdk_version |
| 450 | // is set to something other than "none". |
| 451 | // |
| 452 | // In non-legacy mode the test api scope is disabled by default. |
| 453 | Test ApiScopeProperties |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 454 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 455 | // The properties specific to the module-lib api scope |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 456 | // |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 457 | // Unless explicitly specified by using test.enabled the module-lib api scope is |
Paul Duffin | 8f265b9 | 2020-04-28 14:13:56 +0100 | [diff] [blame] | 458 | // disabled by default. |
| 459 | Module_lib ApiScopeProperties |
| 460 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 461 | // The properties specific to the system-server api scope |
| 462 | // |
| 463 | // Unless explicitly specified by using test.enabled the module-lib api scope is |
| 464 | // disabled by default. |
| 465 | System_server ApiScopeProperties |
| 466 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 467 | // Determines if the stubs are preferred over the implementation library |
| 468 | // for linking, even when the client doesn't specify sdk_version. When this |
| 469 | // is set to true, such clients are provided with the widest API surface that |
| 470 | // this lib provides. Note however that this option doesn't affect the clients |
| 471 | // that are in the same APEX as this library. In that case, the clients are |
| 472 | // always linked with the implementation library. Default is false. |
| 473 | Default_to_stubs *bool |
| 474 | |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 475 | // Properties related to api linting. |
| 476 | Api_lint struct { |
| 477 | // Enable api linting. |
| 478 | Enabled *bool |
| 479 | } |
| 480 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 481 | // TODO: determines whether to create HTML doc or not |
| 482 | //Html_doc *bool |
| 483 | } |
| 484 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 485 | // Paths to outputs from java_sdk_library and java_sdk_library_import. |
| 486 | // |
| 487 | // Fields that are android.Paths are always set (during GenerateAndroidBuildActions). |
| 488 | // OptionalPaths are always set by java_sdk_library but may not be set by |
| 489 | // java_sdk_library_import as not all instances provide that information. |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 490 | type scopePaths struct { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 491 | // The path (represented as Paths for convenience when returning) to the stubs header jar. |
| 492 | // |
| 493 | // That is the jar that is created by turbine. |
| 494 | stubsHeaderPath android.Paths |
| 495 | |
| 496 | // The path (represented as Paths for convenience when returning) to the stubs implementation jar. |
| 497 | // |
| 498 | // This is not the implementation jar, it still only contains stubs. |
| 499 | stubsImplPath android.Paths |
| 500 | |
| 501 | // The API specification file, e.g. system_current.txt. |
| 502 | currentApiFilePath android.OptionalPath |
| 503 | |
| 504 | // The specification of API elements removed since the last release. |
| 505 | removedApiFilePath android.OptionalPath |
| 506 | |
| 507 | // The stubs source jar. |
| 508 | stubsSrcJar android.OptionalPath |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 511 | func (paths *scopePaths) extractStubsLibraryInfoFromDependency(dep android.Module) error { |
| 512 | if lib, ok := dep.(Dependency); ok { |
| 513 | paths.stubsHeaderPath = lib.HeaderJars() |
| 514 | paths.stubsImplPath = lib.ImplementationJars() |
| 515 | return nil |
| 516 | } else { |
| 517 | return fmt.Errorf("expected module that implements Dependency, e.g. java_library") |
| 518 | } |
| 519 | } |
| 520 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 521 | func (paths *scopePaths) treatDepAsApiStubsProvider(dep android.Module, action func(provider ApiStubsProvider)) error { |
| 522 | if apiStubsProvider, ok := dep.(ApiStubsProvider); ok { |
| 523 | action(apiStubsProvider) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 524 | return nil |
| 525 | } else { |
| 526 | return fmt.Errorf("expected module that implements ApiStubsProvider, e.g. droidstubs") |
| 527 | } |
| 528 | } |
| 529 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 530 | func (paths *scopePaths) treatDepAsApiStubsSrcProvider(dep android.Module, action func(provider ApiStubsSrcProvider)) error { |
| 531 | if apiStubsProvider, ok := dep.(ApiStubsSrcProvider); ok { |
| 532 | action(apiStubsProvider) |
| 533 | return nil |
| 534 | } else { |
| 535 | return fmt.Errorf("expected module that implements ApiStubsSrcProvider, e.g. droidstubs") |
| 536 | } |
| 537 | } |
| 538 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 539 | func (paths *scopePaths) extractApiInfoFromApiStubsProvider(provider ApiStubsProvider) { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 540 | paths.currentApiFilePath = android.OptionalPathForPath(provider.ApiFilePath()) |
| 541 | paths.removedApiFilePath = android.OptionalPathForPath(provider.RemovedApiFilePath()) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | func (paths *scopePaths) extractApiInfoFromDep(dep android.Module) error { |
| 545 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 546 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 547 | }) |
| 548 | } |
| 549 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 550 | func (paths *scopePaths) extractStubsSourceInfoFromApiStubsProviders(provider ApiStubsSrcProvider) { |
| 551 | paths.stubsSrcJar = android.OptionalPathForPath(provider.StubsSrcJar()) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | func (paths *scopePaths) extractStubsSourceInfoFromDep(dep android.Module) error { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 555 | return paths.treatDepAsApiStubsSrcProvider(dep, func(provider ApiStubsSrcProvider) { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 556 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 557 | }) |
| 558 | } |
| 559 | |
| 560 | func (paths *scopePaths) extractStubsSourceAndApiInfoFromApiStubsProvider(dep android.Module) error { |
| 561 | return paths.treatDepAsApiStubsProvider(dep, func(provider ApiStubsProvider) { |
| 562 | paths.extractApiInfoFromApiStubsProvider(provider) |
| 563 | paths.extractStubsSourceInfoFromApiStubsProviders(provider) |
| 564 | }) |
| 565 | } |
| 566 | |
| 567 | type commonToSdkLibraryAndImportProperties struct { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 568 | // The naming scheme to use for the components that this module creates. |
| 569 | // |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 570 | // If not specified then it defaults to "default". The other allowable value is |
| 571 | // "framework-modules" which matches the scheme currently used by framework modules |
| 572 | // for the equivalent components represented as separate Soong modules. |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 573 | // |
| 574 | // This is a temporary mechanism to simplify conversion from separate modules for each |
| 575 | // component that follow a different naming pattern to the default one. |
| 576 | // |
| 577 | // TODO(b/155480189) - Remove once naming inconsistencies have been resolved. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 578 | Naming_scheme *string |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 579 | |
| 580 | // Specifies whether this module can be used as an Android shared library; defaults |
| 581 | // to true. |
| 582 | // |
| 583 | // An Android shared library is one that can be referenced in a <uses-library> element |
| 584 | // in an AndroidManifest.xml. |
| 585 | Shared_library *bool |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 588 | // Common code between sdk library and sdk library import |
| 589 | type commonToSdkLibraryAndImport struct { |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 590 | moduleBase *android.ModuleBase |
| 591 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 592 | scopePaths map[*apiScope]*scopePaths |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 593 | |
| 594 | namingScheme sdkLibraryComponentNamingScheme |
| 595 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 596 | commonSdkLibraryProperties commonToSdkLibraryAndImportProperties |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 597 | |
| 598 | // Functionality related to this being used as a component of a java_sdk_library. |
| 599 | EmbeddableSdkLibraryComponent |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 602 | func (c *commonToSdkLibraryAndImport) initCommon(moduleBase *android.ModuleBase) { |
| 603 | c.moduleBase = moduleBase |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 604 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 605 | moduleBase.AddProperties(&c.commonSdkLibraryProperties) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 606 | |
| 607 | // Initialize this as an sdk library component. |
| 608 | c.initSdkLibraryComponent(moduleBase) |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | func (c *commonToSdkLibraryAndImport) initCommonAfterDefaultsApplied(ctx android.DefaultableHookContext) bool { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 612 | schemeProperty := proptools.StringDefault(c.commonSdkLibraryProperties.Naming_scheme, "default") |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 613 | switch schemeProperty { |
| 614 | case "default": |
| 615 | c.namingScheme = &defaultNamingScheme{} |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 616 | case "framework-modules": |
| 617 | c.namingScheme = &frameworkModulesNamingScheme{} |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 618 | default: |
| 619 | ctx.PropertyErrorf("naming_scheme", "expected 'default' but was %q", schemeProperty) |
| 620 | return false |
| 621 | } |
| 622 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 623 | // Only track this sdk library if this can be used as a shared library. |
| 624 | if c.sharedLibrary() { |
| 625 | // Use the name specified in the module definition as the owner. |
| 626 | c.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName()) |
| 627 | } |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 628 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 629 | return true |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 632 | // Module name of the runtime implementation library |
| 633 | func (c *commonToSdkLibraryAndImport) implLibraryModuleName() string { |
| 634 | return c.moduleBase.BaseModuleName() + ".impl" |
| 635 | } |
| 636 | |
| 637 | // Module name of the XML file for the lib |
| 638 | func (c *commonToSdkLibraryAndImport) xmlPermissionsModuleName() string { |
| 639 | return c.moduleBase.BaseModuleName() + sdkXmlFileSuffix |
| 640 | } |
| 641 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 642 | // Name of the java_library module that compiles the stubs source. |
| 643 | func (c *commonToSdkLibraryAndImport) stubsLibraryModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 644 | return c.namingScheme.stubsLibraryModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | // Name of the droidstubs module that generates the stubs source and may also |
| 648 | // generate/check the API. |
| 649 | func (c *commonToSdkLibraryAndImport) stubsSourceModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 650 | return c.namingScheme.stubsSourceModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | // Name of the droidstubs module that generates/checks the API. Only used if it |
| 654 | // requires different arts to the stubs source generating module. |
| 655 | func (c *commonToSdkLibraryAndImport) apiModuleName(apiScope *apiScope) string { |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 656 | return c.namingScheme.apiModuleName(apiScope, c.moduleBase.BaseModuleName()) |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 659 | // The component names for different outputs of the java_sdk_library. |
| 660 | // |
| 661 | // They are similar to the names used for the child modules it creates |
| 662 | const ( |
| 663 | stubsSourceComponentName = "stubs.source" |
| 664 | |
| 665 | apiTxtComponentName = "api.txt" |
| 666 | |
| 667 | removedApiTxtComponentName = "removed-api.txt" |
| 668 | ) |
| 669 | |
| 670 | // A regular expression to match tags that reference a specific stubs component. |
| 671 | // |
| 672 | // It will only match if given a valid scope and a valid component. It is verfy strict |
| 673 | // to ensure it does not accidentally match a similar looking tag that should be processed |
| 674 | // by the embedded Library. |
| 675 | var tagSplitter = func() *regexp.Regexp { |
| 676 | // Given a list of literal string items returns a regular expression that will |
| 677 | // match any one of the items. |
| 678 | choice := func(items ...string) string { |
| 679 | return `\Q` + strings.Join(items, `\E|\Q`) + `\E` |
| 680 | } |
| 681 | |
| 682 | // Regular expression to match one of the scopes. |
| 683 | scopesRegexp := choice(allScopeNames...) |
| 684 | |
| 685 | // Regular expression to match one of the components. |
| 686 | componentsRegexp := choice(stubsSourceComponentName, apiTxtComponentName, removedApiTxtComponentName) |
| 687 | |
| 688 | // Regular expression to match any combination of one scope and one component. |
| 689 | return regexp.MustCompile(fmt.Sprintf(`^\.(%s)\.(%s)$`, scopesRegexp, componentsRegexp)) |
| 690 | }() |
| 691 | |
| 692 | // For OutputFileProducer interface |
| 693 | // |
| 694 | // .<scope>.stubs.source |
| 695 | // .<scope>.api.txt |
| 696 | // .<scope>.removed-api.txt |
| 697 | func (c *commonToSdkLibraryAndImport) commonOutputFiles(tag string) (android.Paths, error) { |
| 698 | if groups := tagSplitter.FindStringSubmatch(tag); groups != nil { |
| 699 | scopeName := groups[1] |
| 700 | component := groups[2] |
| 701 | |
| 702 | if scope, ok := scopeByName[scopeName]; ok { |
| 703 | paths := c.findScopePaths(scope) |
| 704 | if paths == nil { |
| 705 | return nil, fmt.Errorf("%q does not provide api scope %s", c.moduleBase.BaseModuleName(), scopeName) |
| 706 | } |
| 707 | |
| 708 | switch component { |
| 709 | case stubsSourceComponentName: |
| 710 | if paths.stubsSrcJar.Valid() { |
| 711 | return android.Paths{paths.stubsSrcJar.Path()}, nil |
| 712 | } |
| 713 | |
| 714 | case apiTxtComponentName: |
| 715 | if paths.currentApiFilePath.Valid() { |
| 716 | return android.Paths{paths.currentApiFilePath.Path()}, nil |
| 717 | } |
| 718 | |
| 719 | case removedApiTxtComponentName: |
| 720 | if paths.removedApiFilePath.Valid() { |
| 721 | return android.Paths{paths.removedApiFilePath.Path()}, nil |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | return nil, fmt.Errorf("%s not available for api scope %s", component, scopeName) |
| 726 | } else { |
| 727 | return nil, fmt.Errorf("unknown scope %s in %s", scope, tag) |
| 728 | } |
| 729 | |
| 730 | } else { |
| 731 | return nil, nil |
| 732 | } |
| 733 | } |
| 734 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 735 | func (c *commonToSdkLibraryAndImport) getScopePathsCreateIfNeeded(scope *apiScope) *scopePaths { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 736 | if c.scopePaths == nil { |
| 737 | c.scopePaths = make(map[*apiScope]*scopePaths) |
| 738 | } |
| 739 | paths := c.scopePaths[scope] |
| 740 | if paths == nil { |
| 741 | paths = &scopePaths{} |
| 742 | c.scopePaths[scope] = paths |
| 743 | } |
| 744 | |
| 745 | return paths |
| 746 | } |
| 747 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 748 | func (c *commonToSdkLibraryAndImport) findScopePaths(scope *apiScope) *scopePaths { |
| 749 | if c.scopePaths == nil { |
| 750 | return nil |
| 751 | } |
| 752 | |
| 753 | return c.scopePaths[scope] |
| 754 | } |
| 755 | |
| 756 | // If this does not support the requested api scope then find the closest available |
| 757 | // scope it does support. Returns nil if no such scope is available. |
| 758 | func (c *commonToSdkLibraryAndImport) findClosestScopePath(scope *apiScope) *scopePaths { |
| 759 | for s := scope; s != nil; s = s.extends { |
| 760 | if paths := c.findScopePaths(s); paths != nil { |
| 761 | return paths |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | // This should never happen outside tests as public should be the base scope for every |
| 766 | // scope and is enabled by default. |
| 767 | return nil |
| 768 | } |
| 769 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 770 | func (c *commonToSdkLibraryAndImport) selectHeaderJarsForSdkVersion(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 771 | |
| 772 | // If a specific numeric version has been requested then use prebuilt versions of the sdk. |
| 773 | if sdkVersion.version.isNumbered() { |
| 774 | return PrebuiltJars(ctx, c.moduleBase.BaseModuleName(), sdkVersion) |
| 775 | } |
| 776 | |
| 777 | var apiScope *apiScope |
| 778 | switch sdkVersion.kind { |
| 779 | case sdkSystem: |
| 780 | apiScope = apiScopeSystem |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 781 | case sdkModule: |
| 782 | apiScope = apiScopeModuleLib |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 783 | case sdkTest: |
| 784 | apiScope = apiScopeTest |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 785 | case sdkSystemServer: |
| 786 | apiScope = apiScopeSystemServer |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 787 | default: |
| 788 | apiScope = apiScopePublic |
| 789 | } |
| 790 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 791 | paths := c.findClosestScopePath(apiScope) |
| 792 | if paths == nil { |
| 793 | var scopes []string |
| 794 | for _, s := range allApiScopes { |
| 795 | if c.findScopePaths(s) != nil { |
| 796 | scopes = append(scopes, s.name) |
| 797 | } |
| 798 | } |
| 799 | ctx.ModuleErrorf("requires api scope %s from %s but it only has %q available", apiScope.name, c.moduleBase.BaseModuleName(), scopes) |
| 800 | return nil |
| 801 | } |
| 802 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 803 | return paths.stubsHeaderPath |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 804 | } |
| 805 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 806 | func (c *commonToSdkLibraryAndImport) sdkComponentPropertiesForChildLibrary() interface{} { |
| 807 | componentProps := &struct { |
| 808 | SdkLibraryToImplicitlyTrack *string |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 809 | }{} |
| 810 | |
| 811 | if c.sharedLibrary() { |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 812 | // Mark the stubs library as being components of this java_sdk_library so that |
| 813 | // any app that includes code which depends (directly or indirectly) on the stubs |
| 814 | // library will have the appropriate <uses-library> invocation inserted into its |
| 815 | // manifest if necessary. |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 816 | componentProps.SdkLibraryToImplicitlyTrack = proptools.StringPtr(c.moduleBase.BaseModuleName()) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | return componentProps |
| 820 | } |
| 821 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 822 | // Check if this can be used as a shared library. |
| 823 | func (c *commonToSdkLibraryAndImport) sharedLibrary() bool { |
| 824 | return proptools.BoolDefault(c.commonSdkLibraryProperties.Shared_library, true) |
| 825 | } |
| 826 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 827 | // Properties related to the use of a module as an component of a java_sdk_library. |
| 828 | type SdkLibraryComponentProperties struct { |
| 829 | |
| 830 | // The name of the java_sdk_library/_import to add to a <uses-library> entry |
| 831 | // in the AndroidManifest.xml of any Android app that includes code that references |
| 832 | // this module. If not set then no java_sdk_library/_import is tracked. |
| 833 | SdkLibraryToImplicitlyTrack *string `blueprint:"mutated"` |
| 834 | } |
| 835 | |
| 836 | // Structure to be embedded in a module struct that needs to support the |
| 837 | // SdkLibraryComponentDependency interface. |
| 838 | type EmbeddableSdkLibraryComponent struct { |
| 839 | sdkLibraryComponentProperties SdkLibraryComponentProperties |
| 840 | } |
| 841 | |
| 842 | func (e *EmbeddableSdkLibraryComponent) initSdkLibraryComponent(moduleBase *android.ModuleBase) { |
| 843 | moduleBase.AddProperties(&e.sdkLibraryComponentProperties) |
| 844 | } |
| 845 | |
| 846 | // to satisfy SdkLibraryComponentDependency |
| 847 | func (e *EmbeddableSdkLibraryComponent) OptionalImplicitSdkLibrary() []string { |
| 848 | if e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack != nil { |
| 849 | return []string{*e.sdkLibraryComponentProperties.SdkLibraryToImplicitlyTrack} |
| 850 | } |
| 851 | return nil |
| 852 | } |
| 853 | |
| 854 | // Implemented by modules that are (or possibly could be) a component of a java_sdk_library |
| 855 | // (including the java_sdk_library) itself. |
| 856 | type SdkLibraryComponentDependency interface { |
| 857 | // The optional name of the sdk library that should be implicitly added to the |
| 858 | // AndroidManifest of an app that contains code which references the sdk library. |
| 859 | // |
| 860 | // Returns an array containing 0 or 1 items rather than a *string to make it easier |
| 861 | // to append this to the list of exported sdk libraries. |
| 862 | OptionalImplicitSdkLibrary() []string |
| 863 | } |
| 864 | |
| 865 | // Make sure that all the module types that are components of java_sdk_library/_import |
| 866 | // and which can be referenced (directly or indirectly) from an android app implement |
| 867 | // the SdkLibraryComponentDependency interface. |
| 868 | var _ SdkLibraryComponentDependency = (*Library)(nil) |
| 869 | var _ SdkLibraryComponentDependency = (*Import)(nil) |
| 870 | var _ SdkLibraryComponentDependency = (*SdkLibrary)(nil) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 871 | var _ SdkLibraryComponentDependency = (*SdkLibraryImport)(nil) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 872 | |
| 873 | // Provides access to sdk_version related header and implentation jars. |
| 874 | type SdkLibraryDependency interface { |
| 875 | SdkLibraryComponentDependency |
| 876 | |
| 877 | // Get the header jars appropriate for the supplied sdk_version. |
| 878 | // |
| 879 | // These are turbine generated jars so they only change if the externals of the |
| 880 | // class changes but it does not contain and implementation or JavaDoc. |
| 881 | SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths |
| 882 | |
| 883 | // Get the implementation jars appropriate for the supplied sdk version. |
| 884 | // |
| 885 | // These are either the implementation jar for the whole sdk library or the implementation |
| 886 | // jars for the stubs. The latter should only be needed when generating JavaDoc as otherwise |
| 887 | // they are identical to the corresponding header jars. |
| 888 | SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths |
| 889 | } |
| 890 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 891 | type SdkLibrary struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 892 | Library |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 893 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 894 | sdkLibraryProperties sdkLibraryProperties |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 895 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 896 | // Map from api scope to the scope specific property structure. |
| 897 | scopeToProperties map[*apiScope]*ApiScopeProperties |
| 898 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 899 | commonToSdkLibraryAndImport |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 900 | } |
| 901 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 902 | var _ Dependency = (*SdkLibrary)(nil) |
| 903 | var _ SdkLibraryDependency = (*SdkLibrary)(nil) |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 904 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 905 | func (module *SdkLibrary) generateTestAndSystemScopesByDefault() bool { |
| 906 | return module.sdkLibraryProperties.Generate_system_and_test_apis |
| 907 | } |
| 908 | |
| 909 | func (module *SdkLibrary) getGeneratedApiScopes(ctx android.EarlyModuleContext) apiScopes { |
| 910 | // Check to see if any scopes have been explicitly enabled. If any have then all |
| 911 | // must be. |
| 912 | anyScopesExplicitlyEnabled := false |
| 913 | for _, scope := range allApiScopes { |
| 914 | scopeProperties := module.scopeToProperties[scope] |
| 915 | if scopeProperties.Enabled != nil { |
| 916 | anyScopesExplicitlyEnabled = true |
| 917 | break |
| 918 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 919 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 920 | |
| 921 | var generatedScopes apiScopes |
| 922 | enabledScopes := make(map[*apiScope]struct{}) |
| 923 | for _, scope := range allApiScopes { |
| 924 | scopeProperties := module.scopeToProperties[scope] |
| 925 | // If any scopes are explicitly enabled then ignore the legacy enabled status. |
| 926 | // This is to ensure that any new usages of this module type do not rely on legacy |
| 927 | // behaviour. |
| 928 | defaultEnabledStatus := false |
| 929 | if anyScopesExplicitlyEnabled { |
| 930 | defaultEnabledStatus = scope.defaultEnabledStatus |
| 931 | } else { |
| 932 | defaultEnabledStatus = scope.legacyEnabledStatus(module) |
| 933 | } |
| 934 | enabled := proptools.BoolDefault(scopeProperties.Enabled, defaultEnabledStatus) |
| 935 | if enabled { |
| 936 | enabledScopes[scope] = struct{}{} |
| 937 | generatedScopes = append(generatedScopes, scope) |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | // Now check to make sure that any scope that is extended by an enabled scope is also |
| 942 | // enabled. |
| 943 | for _, scope := range allApiScopes { |
| 944 | if _, ok := enabledScopes[scope]; ok { |
| 945 | extends := scope.extends |
| 946 | if extends != nil { |
| 947 | if _, ok := enabledScopes[extends]; !ok { |
| 948 | ctx.ModuleErrorf("enabled api scope %q depends on disabled scope %q", scope, extends) |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | return generatedScopes |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 957 | type sdkLibraryComponentTag struct { |
| 958 | blueprint.BaseDependencyTag |
| 959 | name string |
| 960 | } |
| 961 | |
| 962 | // Mark this tag so dependencies that use it are excluded from visibility enforcement. |
| 963 | func (t sdkLibraryComponentTag) ExcludeFromVisibilityEnforcement() {} |
| 964 | |
| 965 | var xmlPermissionsFileTag = sdkLibraryComponentTag{name: "xml-permissions-file"} |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 966 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 967 | func IsXmlPermissionsFileDepTag(depTag blueprint.DependencyTag) bool { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 968 | if dt, ok := depTag.(sdkLibraryComponentTag); ok { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 969 | return dt == xmlPermissionsFileTag |
| 970 | } |
| 971 | return false |
| 972 | } |
| 973 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 974 | var implLibraryTag = sdkLibraryComponentTag{name: "impl-library"} |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 975 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 976 | func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 977 | for _, apiScope := range module.getGeneratedApiScopes(ctx) { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 978 | // Add dependencies to the stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 979 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 980 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 981 | // If the stubs source and API cannot be generated together then add an additional dependency on |
| 982 | // the API module. |
| 983 | if apiScope.createStubsSourceAndApiTogether { |
| 984 | // 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] | 985 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceAndApiTag, module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 986 | } else { |
| 987 | // 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] | 988 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope)) |
| 989 | ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.apiModuleName(apiScope)) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 990 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 991 | } |
| 992 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 993 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 994 | // Add dependency to the rule for generating the implementation library. |
| 995 | ctx.AddDependency(module, implLibraryTag, module.implLibraryModuleName()) |
| 996 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 997 | if module.sharedLibrary() { |
| 998 | // Add dependency to the rule for generating the xml permissions file |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 999 | ctx.AddDependency(module, xmlPermissionsFileTag, module.xmlPermissionsModuleName()) |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1000 | } |
Paul Duffin | e74ac73 | 2020-02-06 13:51:46 +0000 | [diff] [blame] | 1001 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1002 | // Only add the deps for the library if it is actually going to be built. |
| 1003 | module.Library.deps(ctx) |
| 1004 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1005 | } |
| 1006 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1007 | func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { |
| 1008 | paths, err := module.commonOutputFiles(tag) |
| 1009 | if paths == nil && err == nil { |
| 1010 | return module.Library.OutputFiles(tag) |
| 1011 | } else { |
| 1012 | return paths, err |
| 1013 | } |
| 1014 | } |
| 1015 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1016 | func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1017 | // Only build an implementation library if required. |
| 1018 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1019 | module.Library.GenerateAndroidBuildActions(ctx) |
| 1020 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1021 | |
Sundong Ahn | 57368eb | 2018-07-06 11:20:23 +0900 | [diff] [blame] | 1022 | // 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] | 1023 | // 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] | 1024 | // the recorded paths will be returned depending on the link type of the caller. |
| 1025 | ctx.VisitDirectDeps(func(to android.Module) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1026 | tag := ctx.OtherModuleDependencyTag(to) |
| 1027 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1028 | // Extract information from any of the scope specific dependencies. |
| 1029 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1030 | apiScope := scopeTag.apiScope |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1031 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1032 | |
| 1033 | // Extract information from the dependency. The exact information extracted |
| 1034 | // is determined by the nature of the dependency which is determined by the tag. |
| 1035 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Sundong Ahn | 20e998b | 2018-07-24 11:19:26 +0900 | [diff] [blame] | 1036 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1037 | }) |
| 1038 | } |
| 1039 | |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1040 | func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1041 | if !module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1042 | return nil |
| 1043 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1044 | entriesList := module.Library.AndroidMkEntries() |
Yo Chiang | 07d7507 | 2020-06-05 17:43:19 +0800 | [diff] [blame^] | 1045 | if module.sharedLibrary() { |
| 1046 | entries := &entriesList[0] |
| 1047 | entries.Required = append(entries.Required, module.xmlPermissionsModuleName()) |
| 1048 | } |
Jiyong Park | 0b0e1b9 | 2019-12-03 13:24:29 +0900 | [diff] [blame] | 1049 | return entriesList |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1050 | } |
| 1051 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1052 | // The dist path of the stub artifacts |
| 1053 | func (module *SdkLibrary) apiDistPath(apiScope *apiScope) string { |
| 1054 | if module.ModuleBase.Owner() != "" { |
| 1055 | return path.Join("apistubs", module.ModuleBase.Owner(), apiScope.name) |
| 1056 | } else if Bool(module.sdkLibraryProperties.Core_lib) { |
| 1057 | return path.Join("apistubs", "core", apiScope.name) |
| 1058 | } else { |
| 1059 | return path.Join("apistubs", "android", apiScope.name) |
| 1060 | } |
| 1061 | } |
| 1062 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1063 | // Get the sdk version for use when compiling the stubs library. |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 1064 | func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.EarlyModuleContext, apiScope *apiScope) string { |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1065 | scopeProperties := module.scopeToProperties[apiScope] |
| 1066 | if scopeProperties.Sdk_version != nil { |
| 1067 | return proptools.String(scopeProperties.Sdk_version) |
| 1068 | } |
| 1069 | |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1070 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 1071 | if sdkDep.hasStandardLibs() { |
| 1072 | // 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] | 1073 | return apiScope.sdkVersion |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1074 | } else { |
| 1075 | // Otherwise, use no system module. |
| 1076 | return "none" |
| 1077 | } |
| 1078 | } |
| 1079 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1080 | func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string { |
| 1081 | return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest" |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1082 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1083 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1084 | func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string { |
| 1085 | return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest" |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1086 | } |
| 1087 | |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1088 | // Creates the implementation java library |
| 1089 | func (module *SdkLibrary) createImplLibrary(mctx android.DefaultableHookContext) { |
| 1090 | props := struct { |
| 1091 | Name *string |
| 1092 | Visibility []string |
| 1093 | }{ |
| 1094 | Name: proptools.StringPtr(module.implLibraryModuleName()), |
| 1095 | Visibility: module.sdkLibraryProperties.Impl_library_visibility, |
| 1096 | } |
| 1097 | |
| 1098 | properties := []interface{}{ |
| 1099 | &module.properties, |
| 1100 | &module.protoProperties, |
| 1101 | &module.deviceProperties, |
| 1102 | &module.dexpreoptProperties, |
| 1103 | &props, |
| 1104 | module.sdkComponentPropertiesForChildLibrary(), |
| 1105 | } |
| 1106 | mctx.CreateModule(LibraryFactory, properties...) |
| 1107 | } |
| 1108 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1109 | // Creates a static java library that has API stubs |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1110 | func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext, apiScope *apiScope) { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1111 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1112 | Name *string |
| 1113 | Visibility []string |
| 1114 | Srcs []string |
| 1115 | Installable *bool |
| 1116 | Sdk_version *string |
| 1117 | System_modules *string |
| 1118 | Patch_module *string |
| 1119 | Libs []string |
| 1120 | Compile_dex *bool |
| 1121 | Java_version *string |
| 1122 | Product_variables struct { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1123 | Pdk struct { |
| 1124 | Enabled *bool |
| 1125 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1126 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1127 | Openjdk9 struct { |
| 1128 | Srcs []string |
| 1129 | Javacflags []string |
| 1130 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1131 | Dist struct { |
| 1132 | Targets []string |
| 1133 | Dest *string |
| 1134 | Dir *string |
| 1135 | Tag *string |
| 1136 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1137 | }{} |
| 1138 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1139 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1140 | |
| 1141 | // If stubs_library_visibility is not set then the created module will use the |
| 1142 | // visibility of this module. |
| 1143 | visibility := module.sdkLibraryProperties.Stubs_library_visibility |
| 1144 | props.Visibility = visibility |
| 1145 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1146 | // sources are generated from the droiddoc |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1147 | props.Srcs = []string{":" + module.stubsSourceModuleName(apiScope)} |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1148 | sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1149 | props.Sdk_version = proptools.StringPtr(sdkVersion) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1150 | props.System_modules = module.deviceProperties.System_modules |
| 1151 | props.Patch_module = module.properties.Patch_module |
Paul Duffin | 367ab91 | 2019-12-23 19:40:36 +0000 | [diff] [blame] | 1152 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1153 | props.Libs = module.sdkLibraryProperties.Stub_only_libs |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1154 | props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1155 | props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs |
| 1156 | props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags |
Anton Hansson | 83509b5 | 2020-05-21 09:21:57 +0100 | [diff] [blame] | 1157 | // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential |
| 1158 | // interop with older developer tools that don't support 1.9. |
| 1159 | props.Java_version = proptools.StringPtr("1.8") |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1160 | if module.deviceProperties.Compile_dex != nil { |
| 1161 | props.Compile_dex = module.deviceProperties.Compile_dex |
Sundong Ahn | dd567f9 | 2018-07-31 17:19:11 +0900 | [diff] [blame] | 1162 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1163 | |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1164 | // Dist the class jar artifact for sdk builds. |
| 1165 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 1166 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 1167 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.jar", module.BaseModuleName())) |
| 1168 | props.Dist.Dir = proptools.StringPtr(module.apiDistPath(apiScope)) |
| 1169 | props.Dist.Tag = proptools.StringPtr(".jar") |
| 1170 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1171 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1172 | mctx.CreateModule(LibraryFactory, &props, module.sdkComponentPropertiesForChildLibrary()) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1173 | } |
| 1174 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1175 | // 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] | 1176 | // files and also updates and checks the API specification files. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1177 | 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] | 1178 | props := struct { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1179 | Name *string |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1180 | Visibility []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1181 | Srcs []string |
| 1182 | Installable *bool |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1183 | Sdk_version *string |
Paul Duffin | 12ceb46 | 2019-12-24 20:31:31 +0000 | [diff] [blame] | 1184 | System_modules *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1185 | Libs []string |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1186 | Arg_files []string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1187 | Args *string |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1188 | Java_version *string |
| 1189 | Merge_annotations_dirs []string |
| 1190 | Merge_inclusion_annotations_dirs []string |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1191 | Generate_stubs *bool |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1192 | Check_api struct { |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 1193 | Current ApiToCheck |
| 1194 | Last_released ApiToCheck |
| 1195 | Ignore_missing_latest_api *bool |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1196 | |
| 1197 | Api_lint struct { |
| 1198 | Enabled *bool |
| 1199 | New_since *string |
| 1200 | Baseline_file *string |
| 1201 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1202 | } |
Sundong Ahn | 1b92c82 | 2018-05-29 11:35:17 +0900 | [diff] [blame] | 1203 | Aidl struct { |
| 1204 | Include_dirs []string |
| 1205 | Local_include_dirs []string |
| 1206 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1207 | Dist struct { |
| 1208 | Targets []string |
| 1209 | Dest *string |
| 1210 | Dir *string |
| 1211 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1212 | }{} |
| 1213 | |
Paul Duffin | 7b78b4d | 2020-04-28 14:08:32 +0100 | [diff] [blame] | 1214 | // The stubs source processing uses the same compile time classpath when extracting the |
| 1215 | // API from the implementation library as it does when compiling it. i.e. the same |
| 1216 | // * sdk version |
| 1217 | // * system_modules |
| 1218 | // * libs (static_libs/libs) |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 1219 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1220 | props.Name = proptools.StringPtr(name) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1221 | |
| 1222 | // If stubs_source_visibility is not set then the created module will use the |
| 1223 | // visibility of this module. |
| 1224 | visibility := module.sdkLibraryProperties.Stubs_source_visibility |
| 1225 | props.Visibility = visibility |
| 1226 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1227 | props.Srcs = append(props.Srcs, module.properties.Srcs...) |
| 1228 | props.Sdk_version = module.deviceProperties.Sdk_version |
| 1229 | props.System_modules = module.deviceProperties.System_modules |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1230 | props.Installable = proptools.BoolPtr(false) |
Sundong Ahn | e6f0b05 | 2018-06-05 16:46:14 +0900 | [diff] [blame] | 1231 | // A droiddoc module has only one Libs property and doesn't distinguish between |
| 1232 | // shared libs and static libs. So we need to add both of these libs to Libs property. |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1233 | props.Libs = module.properties.Libs |
| 1234 | props.Libs = append(props.Libs, module.properties.Static_libs...) |
| 1235 | props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs |
| 1236 | props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs |
| 1237 | props.Java_version = module.properties.Java_version |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1238 | |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1239 | props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs |
| 1240 | props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs |
| 1241 | |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1242 | droidstubsArgs := []string{} |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1243 | if len(module.sdkLibraryProperties.Api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1244 | droidstubsArgs = append(droidstubsArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":")) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1245 | } |
| 1246 | if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 { |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1247 | droidstubsArgs = append(droidstubsArgs, |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1248 | android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) |
| 1249 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1250 | droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) |
Paul Duffin | 235ffff | 2019-12-24 10:41:30 +0000 | [diff] [blame] | 1251 | disabledWarnings := []string{ |
| 1252 | "MissingPermission", |
| 1253 | "BroadcastBehavior", |
| 1254 | "HiddenSuperclass", |
| 1255 | "DeprecationMismatch", |
| 1256 | "UnavailableSymbol", |
| 1257 | "SdkConstant", |
| 1258 | "HiddenTypeParameter", |
| 1259 | "Todo", |
| 1260 | "Typo", |
| 1261 | } |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1262 | droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) |
Sundong Ahn | fb2721f | 2018-09-17 13:23:09 +0900 | [diff] [blame] | 1263 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1264 | if !createStubSources { |
| 1265 | // Stubs are not required. |
| 1266 | props.Generate_stubs = proptools.BoolPtr(false) |
| 1267 | } |
| 1268 | |
Paul Duffin | 1fb487d | 2020-04-07 18:50:10 +0100 | [diff] [blame] | 1269 | // Add in scope specific arguments. |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1270 | droidstubsArgs = append(droidstubsArgs, scopeSpecificDroidstubsArgs...) |
Paul Duffin | 1151247 | 2019-02-11 15:55:17 +0000 | [diff] [blame] | 1271 | props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files |
Paul Duffin | 6d0886e | 2020-04-07 18:49:53 +0100 | [diff] [blame] | 1272 | props.Args = proptools.StringPtr(strings.Join(droidstubsArgs, " ")) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1273 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1274 | if createApi { |
| 1275 | // List of APIs identified from the provided source files are created. They are later |
| 1276 | // compared against to the not-yet-released (a.k.a current) list of APIs and to the |
| 1277 | // last-released (a.k.a numbered) list of API. |
| 1278 | currentApiFileName := apiScope.apiFilePrefix + "current.txt" |
| 1279 | removedApiFileName := apiScope.apiFilePrefix + "removed.txt" |
| 1280 | apiDir := module.getApiDir() |
| 1281 | currentApiFileName = path.Join(apiDir, currentApiFileName) |
| 1282 | removedApiFileName = path.Join(apiDir, removedApiFileName) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1283 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1284 | // check against the not-yet-release API |
| 1285 | props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName) |
| 1286 | props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1287 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1288 | if !apiScope.unstable { |
| 1289 | // check against the latest released API |
| 1290 | latestApiFilegroupName := proptools.StringPtr(module.latestApiFilegroupName(apiScope)) |
| 1291 | props.Check_api.Last_released.Api_file = latestApiFilegroupName |
| 1292 | props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( |
| 1293 | module.latestRemovedApiFilegroupName(apiScope)) |
| 1294 | props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true) |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1295 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1296 | if proptools.Bool(module.sdkLibraryProperties.Api_lint.Enabled) { |
| 1297 | // Enable api lint. |
| 1298 | props.Check_api.Api_lint.Enabled = proptools.BoolPtr(true) |
| 1299 | props.Check_api.Api_lint.New_since = latestApiFilegroupName |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1300 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1301 | // If it exists then pass a lint-baseline.txt through to droidstubs. |
| 1302 | baselinePath := path.Join(apiDir, apiScope.apiFilePrefix+"lint-baseline.txt") |
| 1303 | baselinePathRelativeToRoot := path.Join(mctx.ModuleDir(), baselinePath) |
| 1304 | paths, err := mctx.GlobWithDeps(baselinePathRelativeToRoot, nil) |
| 1305 | if err != nil { |
| 1306 | mctx.ModuleErrorf("error checking for presence of %s: %s", baselinePathRelativeToRoot, err) |
| 1307 | } |
| 1308 | if len(paths) == 1 { |
| 1309 | props.Check_api.Api_lint.Baseline_file = proptools.StringPtr(baselinePath) |
| 1310 | } else if len(paths) != 0 { |
| 1311 | mctx.ModuleErrorf("error checking for presence of %s: expected one path, found: %v", baselinePathRelativeToRoot, paths) |
| 1312 | } |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1313 | } |
| 1314 | } |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1315 | |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1316 | // Dist the api txt artifact for sdk builds. |
| 1317 | if !Bool(module.sdkLibraryProperties.No_dist) { |
| 1318 | props.Dist.Targets = []string{"sdk", "win_sdk"} |
| 1319 | props.Dist.Dest = proptools.StringPtr(fmt.Sprintf("%v.txt", module.BaseModuleName())) |
| 1320 | props.Dist.Dir = proptools.StringPtr(path.Join(module.apiDistPath(apiScope), "api")) |
| 1321 | } |
Anton Hansson | 5fd5d24 | 2020-03-27 19:43:19 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 1324 | mctx.CreateModule(DroidstubsFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1325 | } |
| 1326 | |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1327 | func (module *SdkLibrary) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 1328 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 1329 | if depTag == xmlPermissionsFileTag { |
| 1330 | return true |
| 1331 | } |
| 1332 | return module.Library.DepIsInSameApex(mctx, dep) |
| 1333 | } |
| 1334 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1335 | // Creates the xml file that publicizes the runtime library |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1336 | func (module *SdkLibrary) createXmlFile(mctx android.DefaultableHookContext) { |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1337 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1338 | Name *string |
| 1339 | Lib_name *string |
| 1340 | Apex_available []string |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1341 | }{ |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1342 | Name: proptools.StringPtr(module.xmlPermissionsModuleName()), |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 1343 | Lib_name: proptools.StringPtr(module.BaseModuleName()), |
| 1344 | Apex_available: module.ApexProperties.Apex_available, |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1345 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1346 | |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1347 | mctx.CreateModule(sdkLibraryXmlFactory, &props) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1348 | } |
| 1349 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1350 | func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1351 | var ver sdkVersion |
| 1352 | var kind sdkKind |
| 1353 | if s.usePrebuilt(ctx) { |
| 1354 | ver = s.version |
| 1355 | kind = s.kind |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1356 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1357 | // We don't have prebuilt SDK for the specific sdkVersion. |
| 1358 | // Instead of breaking the build, fallback to use "system_current" |
| 1359 | ver = sdkVersionCurrent |
| 1360 | kind = sdkSystem |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1361 | } |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1362 | |
| 1363 | dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1364 | jar := filepath.Join(dir, baseName+".jar") |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1365 | jarPath := android.ExistentPathForSource(ctx, jar) |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 1366 | if !jarPath.Valid() { |
Colin Cross | 07c8856 | 2020-01-07 09:34:44 -0800 | [diff] [blame] | 1367 | if ctx.Config().AllowMissingDependencies() { |
| 1368 | return android.Paths{android.PathForSource(ctx, jar)} |
| 1369 | } else { |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1370 | 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] | 1371 | } |
Sundong Ahn | ae418ac | 2019-02-28 15:01:28 +0900 | [diff] [blame] | 1372 | return nil |
| 1373 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1374 | return android.Paths{jarPath.Path()} |
| 1375 | } |
| 1376 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 1377 | // Get the apex name for module, "" if it is for platform. |
| 1378 | func getApexNameForModule(module android.Module) string { |
| 1379 | if apex, ok := module.(android.ApexModule); ok { |
| 1380 | return apex.ApexName() |
| 1381 | } |
| 1382 | |
| 1383 | return "" |
| 1384 | } |
| 1385 | |
| 1386 | // Check to see if the other module is within the same named APEX as this module. |
| 1387 | // |
| 1388 | // If either this or the other module are on the platform then this will return |
| 1389 | // false. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1390 | func withinSameApexAs(module android.ApexModule, other android.Module) bool { |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 1391 | name := module.ApexName() |
| 1392 | return name != "" && getApexNameForModule(other) == name |
| 1393 | } |
| 1394 | |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1395 | func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 1396 | // If the client doesn't set sdk_version, but if this library prefers stubs over |
| 1397 | // the impl library, let's provide the widest API surface possible. To do so, |
| 1398 | // force override sdk_version to module_current so that the closest possible API |
| 1399 | // surface could be found in selectHeaderJarsForSdkVersion |
| 1400 | if module.defaultsToStubs() && !sdkVersion.specified() { |
| 1401 | sdkVersion = sdkSpecFrom("module_current") |
| 1402 | } |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1403 | |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1404 | // Only provide access to the implementation library if it is actually built. |
| 1405 | if module.requiresRuntimeImplementationLibrary() { |
| 1406 | // Check any special cases for java_sdk_library. |
| 1407 | // |
| 1408 | // Only allow access to the implementation library in the following condition: |
| 1409 | // * No sdk_version specified on the referencing module. |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 1410 | // * The referencing module is in the same apex as this. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1411 | if sdkVersion.kind == sdkPrivate || withinSameApexAs(module, ctx.Module()) { |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1412 | if headerJars { |
| 1413 | return module.HeaderJars() |
| 1414 | } else { |
| 1415 | return module.ImplementationJars() |
| 1416 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1417 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1418 | } |
Paul Duffin | b05d429 | 2020-05-20 12:19:10 +0100 | [diff] [blame] | 1419 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 1420 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1421 | } |
| 1422 | |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1423 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1424 | func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
| 1425 | return module.sdkJars(ctx, sdkVersion, true /*headerJars*/) |
| 1426 | } |
| 1427 | |
| 1428 | // to satisfy SdkLibraryDependency interface |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 1429 | func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1430 | return module.sdkJars(ctx, sdkVersion, false /*headerJars*/) |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 1431 | } |
| 1432 | |
Sundong Ahn | 80a87b3 | 2019-05-13 15:02:50 +0900 | [diff] [blame] | 1433 | func (module *SdkLibrary) SetNoDist() { |
| 1434 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(true) |
| 1435 | } |
| 1436 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1437 | var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries") |
| 1438 | |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1439 | func javaSdkLibraries(config android.Config) *[]string { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1440 | return config.Once(javaSdkLibrariesKey, func() interface{} { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 1441 | return &[]string{} |
| 1442 | }).(*[]string) |
| 1443 | } |
| 1444 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1445 | func (module *SdkLibrary) getApiDir() string { |
| 1446 | return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api") |
| 1447 | } |
| 1448 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1449 | // For a java_sdk_library module, create internal modules for stubs, docs, |
| 1450 | // runtime libs and xml file. If requested, the stubs and docs are created twice |
| 1451 | // once for public API level and once for system API level |
Paul Duffin | f022920 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 1452 | func (module *SdkLibrary) CreateInternalModules(mctx android.DefaultableHookContext) { |
| 1453 | // If the module has been disabled then don't create any child modules. |
| 1454 | if !module.Enabled() { |
| 1455 | return |
| 1456 | } |
| 1457 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1458 | if len(module.properties.Srcs) == 0 { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1459 | mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1460 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1461 | } |
| 1462 | |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1463 | // If this builds against standard libraries (i.e. is not part of the core libraries) |
| 1464 | // then assume it provides both system and test apis. Otherwise, assume it does not and |
| 1465 | // also assume it does not contribute to the dist build. |
| 1466 | sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) |
| 1467 | hasSystemAndTestApis := sdkDep.hasStandardLibs() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1468 | module.sdkLibraryProperties.Generate_system_and_test_apis = hasSystemAndTestApis |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1469 | module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis) |
| 1470 | |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1471 | missing_current_api := false |
| 1472 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1473 | generatedScopes := module.getGeneratedApiScopes(mctx) |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1474 | |
Paul Duffin | 749f98f | 2019-12-30 17:23:46 +0000 | [diff] [blame] | 1475 | apiDir := module.getApiDir() |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1476 | for _, scope := range generatedScopes { |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1477 | for _, api := range []string{"current.txt", "removed.txt"} { |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1478 | path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1479 | p := android.ExistentPathForSource(mctx, path) |
| 1480 | if !p.Valid() { |
| 1481 | mctx.ModuleErrorf("Current api file %#v doesn't exist", path) |
| 1482 | missing_current_api = true |
| 1483 | } |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | if missing_current_api { |
| 1488 | script := "build/soong/scripts/gen-java-current-api-files.sh" |
| 1489 | p := android.ExistentPathForSource(mctx, script) |
| 1490 | |
| 1491 | if !p.Valid() { |
| 1492 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 1493 | } |
| 1494 | |
| 1495 | mctx.ModuleErrorf("One or more current api files are missing. "+ |
| 1496 | "You can update them by:\n"+ |
Paul Duffin | 37e0b77 | 2019-12-30 17:20:10 +0000 | [diff] [blame] | 1497 | "%s %q %s && m update-api", |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1498 | script, filepath.Join(mctx.ModuleDir(), apiDir), |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1499 | strings.Join(generatedScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " ")) |
Inseob Kim | 8098faa | 2019-03-18 10:19:51 +0900 | [diff] [blame] | 1500 | return |
| 1501 | } |
| 1502 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1503 | for _, scope := range generatedScopes { |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1504 | stubsSourceArgs := scope.droidstubsArgsForGeneratingStubsSource |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1505 | stubsSourceModuleName := module.stubsSourceModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1506 | |
| 1507 | // If the args needed to generate the stubs and API are the same then they |
| 1508 | // can be generated in a single invocation of metalava, otherwise they will |
| 1509 | // need separate invocations. |
| 1510 | if scope.createStubsSourceAndApiTogether { |
| 1511 | // Use the stubs source name for legacy reasons. |
| 1512 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, true, stubsSourceArgs) |
| 1513 | } else { |
| 1514 | module.createStubsSourcesAndApi(mctx, scope, stubsSourceModuleName, true, false, stubsSourceArgs) |
| 1515 | |
| 1516 | apiArgs := scope.droidstubsArgsForGeneratingApi |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1517 | apiName := module.apiModuleName(scope) |
Paul Duffin | 0ff08bd | 2020-04-29 13:30:54 +0100 | [diff] [blame] | 1518 | module.createStubsSourcesAndApi(mctx, scope, apiName, false, true, apiArgs) |
| 1519 | } |
| 1520 | |
Paul Duffin | d1b3a92 | 2020-01-22 11:57:20 +0000 | [diff] [blame] | 1521 | module.createStubsLibrary(mctx, scope) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1522 | } |
| 1523 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1524 | if module.requiresRuntimeImplementationLibrary() { |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1525 | // Create child module to create an implementation library. |
| 1526 | // |
| 1527 | // This temporarily creates a second implementation library that can be explicitly |
| 1528 | // referenced. |
| 1529 | // |
| 1530 | // TODO(b/156618935) - update comment once only one implementation library is created. |
| 1531 | module.createImplLibrary(mctx) |
| 1532 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1533 | // Only create an XML permissions file that declares the library as being usable |
| 1534 | // as a shared library if required. |
| 1535 | if module.sharedLibrary() { |
| 1536 | module.createXmlFile(mctx) |
| 1537 | } |
Paul Duffin | 43db9be | 2019-12-30 17:35:49 +0000 | [diff] [blame] | 1538 | |
| 1539 | // record java_sdk_library modules so that they are exported to make |
| 1540 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1541 | javaSdkLibrariesLock.Lock() |
| 1542 | defer javaSdkLibrariesLock.Unlock() |
| 1543 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1544 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | func (module *SdkLibrary) InitSdkLibraryProperties() { |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1548 | module.AddProperties( |
| 1549 | &module.sdkLibraryProperties, |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1550 | &module.properties, |
| 1551 | &module.dexpreoptProperties, |
| 1552 | &module.deviceProperties, |
| 1553 | &module.protoProperties, |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1554 | ) |
| 1555 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1556 | module.initSdkLibraryComponent(&module.ModuleBase) |
| 1557 | |
Paul Duffin | a18abc2 | 2020-05-16 18:54:24 +0100 | [diff] [blame] | 1558 | module.properties.Installable = proptools.BoolPtr(true) |
| 1559 | module.deviceProperties.IsSDKLibrary = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1560 | } |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1561 | |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1562 | func (module *SdkLibrary) requiresRuntimeImplementationLibrary() bool { |
| 1563 | return !proptools.Bool(module.sdkLibraryProperties.Api_only) |
| 1564 | } |
| 1565 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 1566 | func (module *SdkLibrary) defaultsToStubs() bool { |
| 1567 | return proptools.Bool(module.sdkLibraryProperties.Default_to_stubs) |
| 1568 | } |
| 1569 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1570 | // Defines how to name the individual component modules the sdk library creates. |
| 1571 | type sdkLibraryComponentNamingScheme interface { |
| 1572 | stubsLibraryModuleName(scope *apiScope, baseName string) string |
| 1573 | |
| 1574 | stubsSourceModuleName(scope *apiScope, baseName string) string |
| 1575 | |
| 1576 | apiModuleName(scope *apiScope, baseName string) string |
| 1577 | } |
| 1578 | |
| 1579 | type defaultNamingScheme struct { |
| 1580 | } |
| 1581 | |
| 1582 | func (s *defaultNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { |
| 1583 | return scope.stubsLibraryModuleName(baseName) |
| 1584 | } |
| 1585 | |
| 1586 | func (s *defaultNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { |
| 1587 | return scope.stubsSourceModuleName(baseName) |
| 1588 | } |
| 1589 | |
| 1590 | func (s *defaultNamingScheme) apiModuleName(scope *apiScope, baseName string) string { |
| 1591 | return scope.apiModuleName(baseName) |
| 1592 | } |
| 1593 | |
| 1594 | var _ sdkLibraryComponentNamingScheme = (*defaultNamingScheme)(nil) |
| 1595 | |
Paul Duffin | 6c9c5fc | 2020-05-08 15:36:30 +0100 | [diff] [blame] | 1596 | type frameworkModulesNamingScheme struct { |
| 1597 | } |
| 1598 | |
| 1599 | func (s *frameworkModulesNamingScheme) moduleSuffix(scope *apiScope) string { |
| 1600 | suffix := scope.name |
| 1601 | if scope == apiScopeModuleLib { |
| 1602 | suffix = "module_libs_" |
| 1603 | } |
| 1604 | return suffix |
| 1605 | } |
| 1606 | |
| 1607 | func (s *frameworkModulesNamingScheme) stubsLibraryModuleName(scope *apiScope, baseName string) string { |
| 1608 | return fmt.Sprintf("%s-stubs-%sapi", baseName, s.moduleSuffix(scope)) |
| 1609 | } |
| 1610 | |
| 1611 | func (s *frameworkModulesNamingScheme) stubsSourceModuleName(scope *apiScope, baseName string) string { |
| 1612 | return fmt.Sprintf("%s-stubs-srcs-%sapi", baseName, s.moduleSuffix(scope)) |
| 1613 | } |
| 1614 | |
| 1615 | func (s *frameworkModulesNamingScheme) apiModuleName(scope *apiScope, baseName string) string { |
| 1616 | return fmt.Sprintf("%s-api-%sapi", baseName, s.moduleSuffix(scope)) |
| 1617 | } |
| 1618 | |
| 1619 | var _ sdkLibraryComponentNamingScheme = (*frameworkModulesNamingScheme)(nil) |
| 1620 | |
Anton Hansson | 2d0c194 | 2020-05-25 12:20:51 +0100 | [diff] [blame] | 1621 | func moduleStubLinkType(name string) (stub bool, ret linkType) { |
| 1622 | // This suffix-based approach is fragile and could potentially mis-trigger. |
| 1623 | // TODO(b/155164730): Clean this up when modules no longer reference sdk_lib stubs directly. |
| 1624 | if strings.HasSuffix(name, ".stubs.public") || strings.HasSuffix(name, "-stubs-publicapi") { |
| 1625 | return true, javaSdk |
| 1626 | } |
| 1627 | if strings.HasSuffix(name, ".stubs.system") || strings.HasSuffix(name, "-stubs-systemapi") { |
| 1628 | return true, javaSystem |
| 1629 | } |
| 1630 | if strings.HasSuffix(name, ".stubs.module_lib") || strings.HasSuffix(name, "-stubs-module_libs_api") { |
| 1631 | return true, javaModule |
| 1632 | } |
| 1633 | if strings.HasSuffix(name, ".stubs.test") { |
| 1634 | return true, javaSystem |
| 1635 | } |
| 1636 | return false, javaPlatform |
| 1637 | } |
| 1638 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1639 | // java_sdk_library is a special Java library that provides optional platform APIs to apps. |
| 1640 | // In practice, it can be viewed as a combination of several modules: 1) stubs library that clients |
| 1641 | // are linked against to, 2) droiddoc module that internally generates API stubs source files, |
| 1642 | // 3) the real runtime shared library that implements the APIs, and 4) XML file for adding |
| 1643 | // 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] | 1644 | func SdkLibraryFactory() android.Module { |
| 1645 | module := &SdkLibrary{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1646 | |
| 1647 | // Initialize information common between source and prebuilt. |
| 1648 | module.initCommon(&module.ModuleBase) |
| 1649 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1650 | module.InitSdkLibraryProperties() |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 1651 | android.InitApexModule(module) |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1652 | InitJavaModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1653 | |
| 1654 | // Initialize the map from scope to scope specific properties. |
| 1655 | scopeToProperties := make(map[*apiScope]*ApiScopeProperties) |
| 1656 | for _, scope := range allApiScopes { |
| 1657 | scopeToProperties[scope] = scope.scopeSpecificProperties(module) |
| 1658 | } |
| 1659 | module.scopeToProperties = scopeToProperties |
| 1660 | |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1661 | // Add the properties containing visibility rules so that they are checked. |
Paul Duffin | 5df7930 | 2020-05-16 15:52:12 +0100 | [diff] [blame] | 1662 | android.AddVisibilityProperty(module, "impl_library_visibility", &module.sdkLibraryProperties.Impl_library_visibility) |
Paul Duffin | 4911a89 | 2020-04-29 23:35:13 +0100 | [diff] [blame] | 1663 | android.AddVisibilityProperty(module, "stubs_library_visibility", &module.sdkLibraryProperties.Stubs_library_visibility) |
| 1664 | android.AddVisibilityProperty(module, "stubs_source_visibility", &module.sdkLibraryProperties.Stubs_source_visibility) |
| 1665 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1666 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1667 | // If no implementation is required then it cannot be used as a shared library |
| 1668 | // either. |
| 1669 | if !module.requiresRuntimeImplementationLibrary() { |
| 1670 | // If shared_library has been explicitly set to true then it is incompatible |
| 1671 | // with api_only: true. |
| 1672 | if proptools.Bool(module.commonSdkLibraryProperties.Shared_library) { |
| 1673 | ctx.PropertyErrorf("api_only/shared_library", "inconsistent settings, shared_library and api_only cannot both be true") |
| 1674 | } |
| 1675 | // Set shared_library: false. |
| 1676 | module.commonSdkLibraryProperties.Shared_library = proptools.BoolPtr(false) |
| 1677 | } |
| 1678 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1679 | if module.initCommonAfterDefaultsApplied(ctx) { |
| 1680 | module.CreateInternalModules(ctx) |
| 1681 | } |
| 1682 | }) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1683 | return module |
| 1684 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1685 | |
| 1686 | // |
| 1687 | // SDK library prebuilts |
| 1688 | // |
| 1689 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1690 | // Properties associated with each api scope. |
| 1691 | type sdkLibraryScopeProperties struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1692 | Jars []string `android:"path"` |
| 1693 | |
| 1694 | Sdk_version *string |
| 1695 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1696 | // List of shared java libs that this module has dependencies to |
| 1697 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1698 | |
Paul Duffin | c878250 | 2020-04-29 20:45:27 +0100 | [diff] [blame] | 1699 | // The stubs source. |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1700 | Stub_srcs []string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1701 | |
| 1702 | // The current.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1703 | Current_api *string `android:"path"` |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1704 | |
| 1705 | // The removed.txt |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1706 | Removed_api *string `android:"path"` |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1709 | type sdkLibraryImportProperties struct { |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 1710 | // List of shared java libs, common to all scopes, that this module has |
| 1711 | // dependencies to |
| 1712 | Libs []string |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1715 | type SdkLibraryImport struct { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1716 | android.ModuleBase |
| 1717 | android.DefaultableModuleBase |
| 1718 | prebuilt android.Prebuilt |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1719 | android.ApexModuleBase |
| 1720 | android.SdkBase |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1721 | |
| 1722 | properties sdkLibraryImportProperties |
| 1723 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1724 | // Map from api scope to the scope specific property structure. |
| 1725 | scopeProperties map[*apiScope]*sdkLibraryScopeProperties |
| 1726 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1727 | commonToSdkLibraryAndImport |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1728 | |
| 1729 | // The reference to the implementation library created by the source module. |
| 1730 | // Is nil if the source module does not exist. |
| 1731 | implLibraryModule *Library |
| 1732 | |
| 1733 | // The reference to the xml permissions module created by the source module. |
| 1734 | // Is nil if the source module does not exist. |
| 1735 | xmlPermissionsFileModule *sdkLibraryXml |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1738 | var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1739 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1740 | // The type of a structure that contains a field of type sdkLibraryScopeProperties |
| 1741 | // for each apiscope in allApiScopes, e.g. something like: |
| 1742 | // struct { |
| 1743 | // Public sdkLibraryScopeProperties |
| 1744 | // System sdkLibraryScopeProperties |
| 1745 | // ... |
| 1746 | // } |
| 1747 | var allScopeStructType = createAllScopePropertiesStructType() |
| 1748 | |
| 1749 | // Dynamically create a structure type for each apiscope in allApiScopes. |
| 1750 | func createAllScopePropertiesStructType() reflect.Type { |
| 1751 | var fields []reflect.StructField |
| 1752 | for _, apiScope := range allApiScopes { |
| 1753 | field := reflect.StructField{ |
| 1754 | Name: apiScope.fieldName, |
| 1755 | Type: reflect.TypeOf(sdkLibraryScopeProperties{}), |
| 1756 | } |
| 1757 | fields = append(fields, field) |
| 1758 | } |
| 1759 | |
| 1760 | return reflect.StructOf(fields) |
| 1761 | } |
| 1762 | |
| 1763 | // Create an instance of the scope specific structure type and return a map |
| 1764 | // from apiscope to a pointer to each scope specific field. |
| 1765 | func createPropertiesInstance() (interface{}, map[*apiScope]*sdkLibraryScopeProperties) { |
| 1766 | allScopePropertiesPtr := reflect.New(allScopeStructType) |
| 1767 | allScopePropertiesStruct := allScopePropertiesPtr.Elem() |
| 1768 | scopeProperties := make(map[*apiScope]*sdkLibraryScopeProperties) |
| 1769 | |
| 1770 | for _, apiScope := range allApiScopes { |
| 1771 | field := allScopePropertiesStruct.FieldByName(apiScope.fieldName) |
| 1772 | scopeProperties[apiScope] = field.Addr().Interface().(*sdkLibraryScopeProperties) |
| 1773 | } |
| 1774 | |
| 1775 | return allScopePropertiesPtr.Interface(), scopeProperties |
| 1776 | } |
| 1777 | |
Jaewoong Jung | 4f158ee | 2019-07-11 10:05:35 -0700 | [diff] [blame] | 1778 | // java_sdk_library_import imports a prebuilt java_sdk_library. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1779 | func sdkLibraryImportFactory() android.Module { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1780 | module := &SdkLibraryImport{} |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1781 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1782 | allScopeProperties, scopeToProperties := createPropertiesInstance() |
| 1783 | module.scopeProperties = scopeToProperties |
| 1784 | module.AddProperties(&module.properties, allScopeProperties) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1785 | |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1786 | // Initialize information common between source and prebuilt. |
| 1787 | module.initCommon(&module.ModuleBase) |
| 1788 | |
Paul Duffin | 0bdcb27 | 2020-02-06 15:24:57 +0000 | [diff] [blame] | 1789 | android.InitPrebuiltModule(module, &[]string{""}) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 1790 | android.InitApexModule(module) |
| 1791 | android.InitSdkAwareModule(module) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1792 | InitJavaModule(module, android.HostAndDeviceSupported) |
| 1793 | |
Paul Duffin | 1b1e806 | 2020-05-08 13:44:43 +0100 | [diff] [blame] | 1794 | module.SetDefaultableHook(func(mctx android.DefaultableHookContext) { |
| 1795 | if module.initCommonAfterDefaultsApplied(mctx) { |
| 1796 | module.createInternalModules(mctx) |
| 1797 | } |
| 1798 | }) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1799 | return module |
| 1800 | } |
| 1801 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1802 | func (module *SdkLibraryImport) Prebuilt() *android.Prebuilt { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1803 | return &module.prebuilt |
| 1804 | } |
| 1805 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1806 | func (module *SdkLibraryImport) Name() string { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1807 | return module.prebuilt.Name(module.ModuleBase.Name()) |
| 1808 | } |
| 1809 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1810 | func (module *SdkLibraryImport) createInternalModules(mctx android.DefaultableHookContext) { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1811 | |
Paul Duffin | 5006151 | 2020-01-21 16:31:05 +0000 | [diff] [blame] | 1812 | // If the build is configured to use prebuilts then force this to be preferred. |
| 1813 | if mctx.Config().UnbundledBuildUsePrebuiltSdks() { |
| 1814 | module.prebuilt.ForcePrefer() |
| 1815 | } |
| 1816 | |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1817 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1818 | if len(scopeProperties.Jars) == 0 { |
| 1819 | continue |
| 1820 | } |
| 1821 | |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1822 | module.createJavaImportForStubs(mctx, apiScope, scopeProperties) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1823 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1824 | if len(scopeProperties.Stub_srcs) > 0 { |
| 1825 | module.createPrebuiltStubsSources(mctx, apiScope, scopeProperties) |
| 1826 | } |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1827 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1828 | |
| 1829 | javaSdkLibraries := javaSdkLibraries(mctx.Config()) |
| 1830 | javaSdkLibrariesLock.Lock() |
| 1831 | defer javaSdkLibrariesLock.Unlock() |
| 1832 | *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName()) |
| 1833 | } |
| 1834 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1835 | func (module *SdkLibraryImport) createJavaImportForStubs(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1836 | // Creates a java import for the jar with ".stubs" suffix |
| 1837 | props := struct { |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1838 | Name *string |
| 1839 | Sdk_version *string |
| 1840 | Libs []string |
| 1841 | Jars []string |
| 1842 | Prefer *bool |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1843 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1844 | props.Name = proptools.StringPtr(module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1845 | props.Sdk_version = scopeProperties.Sdk_version |
| 1846 | // Prepend any of the libs from the legacy public properties to the libs for each of the |
| 1847 | // scopes to avoid having to duplicate them in each scope. |
| 1848 | props.Libs = append(module.properties.Libs, scopeProperties.Libs...) |
| 1849 | props.Jars = scopeProperties.Jars |
Paul Duffin | 1dbe3ca | 2020-05-16 09:57:59 +0100 | [diff] [blame] | 1850 | |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1851 | // The imports are preferred if the java_sdk_library_import is preferred. |
| 1852 | props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1853 | |
| 1854 | mctx.CreateModule(ImportFactory, &props, module.sdkComponentPropertiesForChildLibrary()) |
Paul Duffin | bbb546b | 2020-04-09 00:07:11 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1857 | func (module *SdkLibraryImport) createPrebuiltStubsSources(mctx android.DefaultableHookContext, apiScope *apiScope, scopeProperties *sdkLibraryScopeProperties) { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1858 | props := struct { |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1859 | Name *string |
| 1860 | Srcs []string |
| 1861 | Prefer *bool |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1862 | }{} |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1863 | props.Name = proptools.StringPtr(module.stubsSourceModuleName(apiScope)) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1864 | props.Srcs = scopeProperties.Stub_srcs |
| 1865 | mctx.CreateModule(PrebuiltStubsSourcesFactory, &props) |
Paul Duffin | 38b5785 | 2020-05-13 16:08:09 +0100 | [diff] [blame] | 1866 | |
| 1867 | // The stubs source is preferred if the java_sdk_library_import is preferred. |
| 1868 | props.Prefer = proptools.BoolPtr(module.prebuilt.Prefer()) |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1871 | func (module *SdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) { |
Paul Duffin | 46a26a8 | 2020-04-07 19:27:04 +0100 | [diff] [blame] | 1872 | for apiScope, scopeProperties := range module.scopeProperties { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1873 | if len(scopeProperties.Jars) == 0 { |
| 1874 | continue |
| 1875 | } |
| 1876 | |
| 1877 | // Add dependencies to the prebuilt stubs library |
Paul Duffin | c3091c8 | 2020-05-08 14:16:20 +0100 | [diff] [blame] | 1878 | ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsLibraryModuleName(apiScope)) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1879 | |
| 1880 | if len(scopeProperties.Stub_srcs) > 0 { |
| 1881 | // Add dependencies to the prebuilt stubs source library |
| 1882 | ctx.AddVariationDependencies(nil, apiScope.stubsSourceTag, module.stubsSourceModuleName(apiScope)) |
| 1883 | } |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1884 | } |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1885 | |
| 1886 | implName := module.implLibraryModuleName() |
| 1887 | if ctx.OtherModuleExists(implName) { |
| 1888 | ctx.AddVariationDependencies(nil, implLibraryTag, implName) |
| 1889 | |
| 1890 | xmlPermissionsModuleName := module.xmlPermissionsModuleName() |
| 1891 | if module.sharedLibrary() && ctx.OtherModuleExists(xmlPermissionsModuleName) { |
| 1892 | // Add dependency to the rule for generating the xml permissions file |
| 1893 | ctx.AddDependency(module, xmlPermissionsFileTag, xmlPermissionsModuleName) |
| 1894 | } |
| 1895 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1898 | func (module *SdkLibraryImport) DepIsInSameApex(mctx android.BaseModuleContext, dep android.Module) bool { |
| 1899 | depTag := mctx.OtherModuleDependencyTag(dep) |
| 1900 | if depTag == xmlPermissionsFileTag { |
| 1901 | return true |
| 1902 | } |
| 1903 | |
| 1904 | // None of the other dependencies of the java_sdk_library_import are in the same apex |
| 1905 | // as the one that references this module. |
| 1906 | return false |
| 1907 | } |
| 1908 | |
| 1909 | func (module *SdkLibraryImport) OutputFiles(tag string) (android.Paths, error) { |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1910 | return module.commonOutputFiles(tag) |
| 1911 | } |
| 1912 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1913 | func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1914 | // Record the paths to the prebuilt stubs library and stubs source. |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1915 | ctx.VisitDirectDeps(func(to android.Module) { |
| 1916 | tag := ctx.OtherModuleDependencyTag(to) |
| 1917 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1918 | // Extract information from any of the scope specific dependencies. |
| 1919 | if scopeTag, ok := tag.(scopeDependencyTag); ok { |
| 1920 | apiScope := scopeTag.apiScope |
| 1921 | scopePaths := module.getScopePathsCreateIfNeeded(apiScope) |
| 1922 | |
| 1923 | // Extract information from the dependency. The exact information extracted |
| 1924 | // is determined by the nature of the dependency which is determined by the tag. |
| 1925 | scopeTag.extractDepInfo(ctx, to, scopePaths) |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1926 | } else if tag == implLibraryTag { |
| 1927 | if implLibrary, ok := to.(*Library); ok { |
| 1928 | module.implLibraryModule = implLibrary |
| 1929 | } else { |
| 1930 | ctx.ModuleErrorf("implementation library must be of type *java.Library but was %T", to) |
| 1931 | } |
| 1932 | } else if tag == xmlPermissionsFileTag { |
| 1933 | if xmlPermissionsFileModule, ok := to.(*sdkLibraryXml); ok { |
| 1934 | module.xmlPermissionsFileModule = xmlPermissionsFileModule |
| 1935 | } else { |
| 1936 | ctx.ModuleErrorf("xml permissions file module must be of type *sdkLibraryXml but was %T", to) |
| 1937 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1938 | } |
| 1939 | }) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1940 | |
| 1941 | // Populate the scope paths with information from the properties. |
| 1942 | for apiScope, scopeProperties := range module.scopeProperties { |
| 1943 | if len(scopeProperties.Jars) == 0 { |
| 1944 | continue |
| 1945 | } |
| 1946 | |
| 1947 | paths := module.getScopePathsCreateIfNeeded(apiScope) |
| 1948 | paths.currentApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Current_api) |
| 1949 | paths.removedApiFilePath = android.OptionalPathForModuleSrc(ctx, scopeProperties.Removed_api) |
| 1950 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1953 | func (module *SdkLibraryImport) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths { |
| 1954 | |
| 1955 | // For consistency with SdkLibrary make the implementation jar available to libraries that |
| 1956 | // are within the same APEX. |
| 1957 | implLibraryModule := module.implLibraryModule |
| 1958 | if implLibraryModule != nil && withinSameApexAs(module, ctx.Module()) { |
| 1959 | if headerJars { |
| 1960 | return implLibraryModule.HeaderJars() |
| 1961 | } else { |
| 1962 | return implLibraryModule.ImplementationJars() |
| 1963 | } |
| 1964 | } |
| 1965 | |
Paul Duffin | 23970f4 | 2020-05-20 14:20:02 +0100 | [diff] [blame] | 1966 | return module.selectHeaderJarsForSdkVersion(ctx, sdkVersion) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1969 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1970 | func (module *SdkLibraryImport) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1971 | // This module is just a wrapper for the prebuilt stubs. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1972 | return module.sdkJars(ctx, sdkVersion, true) |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | // to satisfy SdkLibraryDependency interface |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1976 | func (module *SdkLibraryImport) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 1977 | // This module is just a wrapper for the stubs. |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 1978 | return module.sdkJars(ctx, sdkVersion, false) |
| 1979 | } |
| 1980 | |
| 1981 | // to satisfy apex.javaDependency interface |
| 1982 | func (module *SdkLibraryImport) DexJarBuildPath() android.Path { |
| 1983 | if module.implLibraryModule == nil { |
| 1984 | return nil |
| 1985 | } else { |
| 1986 | return module.implLibraryModule.DexJarBuildPath() |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | // to satisfy apex.javaDependency interface |
| 1991 | func (module *SdkLibraryImport) JacocoReportClassesFile() android.Path { |
| 1992 | if module.implLibraryModule == nil { |
| 1993 | return nil |
| 1994 | } else { |
| 1995 | return module.implLibraryModule.JacocoReportClassesFile() |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | // to satisfy apex.javaDependency interface |
| 2000 | func (module *SdkLibraryImport) Stem() string { |
| 2001 | return module.BaseModuleName() |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 2002 | } |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 2003 | |
| 2004 | // |
| 2005 | // java_sdk_library_xml |
| 2006 | // |
| 2007 | type sdkLibraryXml struct { |
| 2008 | android.ModuleBase |
| 2009 | android.DefaultableModuleBase |
| 2010 | android.ApexModuleBase |
| 2011 | |
| 2012 | properties sdkLibraryXmlProperties |
| 2013 | |
| 2014 | outputFilePath android.OutputPath |
| 2015 | installDirPath android.InstallPath |
| 2016 | } |
| 2017 | |
| 2018 | type sdkLibraryXmlProperties struct { |
| 2019 | // canonical name of the lib |
| 2020 | Lib_name *string |
| 2021 | } |
| 2022 | |
| 2023 | // java_sdk_library_xml builds the permission xml file for a java_sdk_library. |
| 2024 | // Not to be used directly by users. java_sdk_library internally uses this. |
| 2025 | func sdkLibraryXmlFactory() android.Module { |
| 2026 | module := &sdkLibraryXml{} |
| 2027 | |
| 2028 | module.AddProperties(&module.properties) |
| 2029 | |
| 2030 | android.InitApexModule(module) |
| 2031 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) |
| 2032 | |
| 2033 | return module |
| 2034 | } |
| 2035 | |
| 2036 | // from android.PrebuiltEtcModule |
| 2037 | func (module *sdkLibraryXml) SubDir() string { |
| 2038 | return "permissions" |
| 2039 | } |
| 2040 | |
| 2041 | // from android.PrebuiltEtcModule |
| 2042 | func (module *sdkLibraryXml) OutputFile() android.OutputPath { |
| 2043 | return module.outputFilePath |
| 2044 | } |
| 2045 | |
| 2046 | // from android.ApexModule |
| 2047 | func (module *sdkLibraryXml) AvailableFor(what string) bool { |
| 2048 | return true |
| 2049 | } |
| 2050 | |
| 2051 | func (module *sdkLibraryXml) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 2052 | // do nothing |
| 2053 | } |
| 2054 | |
| 2055 | // File path to the runtime implementation library |
| 2056 | func (module *sdkLibraryXml) implPath() string { |
| 2057 | implName := proptools.String(module.properties.Lib_name) |
| 2058 | if apexName := module.ApexName(); apexName != "" { |
| 2059 | // TODO(b/146468504): ApexName() is only a soong module name, not apex name. |
| 2060 | // In most cases, this works fine. But when apex_name is set or override_apex is used |
| 2061 | // this can be wrong. |
| 2062 | return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName) |
| 2063 | } |
| 2064 | partition := "system" |
| 2065 | if module.SocSpecific() { |
| 2066 | partition = "vendor" |
| 2067 | } else if module.DeviceSpecific() { |
| 2068 | partition = "odm" |
| 2069 | } else if module.ProductSpecific() { |
| 2070 | partition = "product" |
| 2071 | } else if module.SystemExtSpecific() { |
| 2072 | partition = "system_ext" |
| 2073 | } |
| 2074 | return "/" + partition + "/framework/" + implName + ".jar" |
| 2075 | } |
| 2076 | |
| 2077 | func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 2078 | libName := proptools.String(module.properties.Lib_name) |
| 2079 | xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath()) |
| 2080 | |
| 2081 | module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath |
| 2082 | rule := android.NewRuleBuilder() |
| 2083 | rule.Command(). |
| 2084 | Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). |
| 2085 | Output(module.outputFilePath) |
| 2086 | |
| 2087 | rule.Build(pctx, ctx, "java_sdk_xml", "Permission XML") |
| 2088 | |
| 2089 | module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) |
| 2090 | } |
| 2091 | |
| 2092 | func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { |
| 2093 | if !module.IsForPlatform() { |
| 2094 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 2095 | Disabled: true, |
| 2096 | }} |
| 2097 | } |
| 2098 | |
| 2099 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 2100 | Class: "ETC", |
| 2101 | OutputFile: android.OptionalPathForPath(module.outputFilePath), |
| 2102 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 2103 | func(entries *android.AndroidMkEntries) { |
| 2104 | entries.SetString("LOCAL_MODULE_TAGS", "optional") |
| 2105 | entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String()) |
| 2106 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) |
| 2107 | }, |
| 2108 | }, |
| 2109 | }} |
| 2110 | } |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2111 | |
| 2112 | type sdkLibrarySdkMemberType struct { |
| 2113 | android.SdkMemberTypeBase |
| 2114 | } |
| 2115 | |
| 2116 | func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 2117 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 2118 | } |
| 2119 | |
| 2120 | func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { |
| 2121 | _, ok := module.(*SdkLibrary) |
| 2122 | return ok |
| 2123 | } |
| 2124 | |
| 2125 | func (s *sdkLibrarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 2126 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_sdk_library_import") |
| 2127 | } |
| 2128 | |
| 2129 | func (s *sdkLibrarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 2130 | return &sdkLibrarySdkMemberProperties{} |
| 2131 | } |
| 2132 | |
| 2133 | type sdkLibrarySdkMemberProperties struct { |
| 2134 | android.SdkMemberPropertiesBase |
| 2135 | |
| 2136 | // Scope to per scope properties. |
| 2137 | Scopes map[*apiScope]scopeProperties |
| 2138 | |
| 2139 | // Additional libraries that the exported stubs libraries depend upon. |
| 2140 | Libs []string |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2141 | |
| 2142 | // The Java stubs source files. |
| 2143 | Stub_srcs []string |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2144 | |
| 2145 | // The naming scheme. |
| 2146 | Naming_scheme *string |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2147 | |
| 2148 | // True if the java_sdk_library_import is for a shared library, false |
| 2149 | // otherwise. |
| 2150 | Shared_library *bool |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | type scopeProperties struct { |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2154 | Jars android.Paths |
| 2155 | StubsSrcJar android.Path |
| 2156 | CurrentApiFile android.Path |
| 2157 | RemovedApiFile android.Path |
| 2158 | SdkVersion string |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | func (s *sdkLibrarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 2162 | sdk := variant.(*SdkLibrary) |
| 2163 | |
| 2164 | s.Scopes = make(map[*apiScope]scopeProperties) |
| 2165 | for _, apiScope := range allApiScopes { |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2166 | paths := sdk.findScopePaths(apiScope) |
| 2167 | if paths == nil { |
| 2168 | continue |
| 2169 | } |
| 2170 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2171 | jars := paths.stubsImplPath |
| 2172 | if len(jars) > 0 { |
| 2173 | properties := scopeProperties{} |
| 2174 | properties.Jars = jars |
Paul Duffin | 780c5f4 | 2020-05-12 15:52:55 +0100 | [diff] [blame] | 2175 | properties.SdkVersion = sdk.sdkVersionForStubsLibrary(ctx.SdkModuleContext(), apiScope) |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 2176 | properties.StubsSrcJar = paths.stubsSrcJar.Path() |
| 2177 | properties.CurrentApiFile = paths.currentApiFilePath.Path() |
| 2178 | properties.RemovedApiFile = paths.removedApiFilePath.Path() |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2179 | s.Scopes[apiScope] = properties |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | s.Libs = sdk.properties.Libs |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 2184 | s.Naming_scheme = sdk.commonSdkLibraryProperties.Naming_scheme |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2185 | s.Shared_library = proptools.BoolPtr(sdk.sharedLibrary()) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2189 | if s.Naming_scheme != nil { |
| 2190 | propertySet.AddProperty("naming_scheme", proptools.String(s.Naming_scheme)) |
| 2191 | } |
Paul Duffin | d7eb1c2 | 2020-05-26 20:57:10 +0100 | [diff] [blame] | 2192 | if s.Shared_library != nil { |
| 2193 | propertySet.AddProperty("shared_library", *s.Shared_library) |
| 2194 | } |
Paul Duffin | f7a6433 | 2020-05-13 16:54:55 +0100 | [diff] [blame] | 2195 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2196 | for _, apiScope := range allApiScopes { |
| 2197 | if properties, ok := s.Scopes[apiScope]; ok { |
Paul Duffin | 6b836ba | 2020-05-13 19:19:49 +0100 | [diff] [blame] | 2198 | scopeSet := propertySet.AddPropertySet(apiScope.propertyName) |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2199 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2200 | scopeDir := filepath.Join("sdk_library", s.OsPrefix(), apiScope.name) |
| 2201 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2202 | var jars []string |
| 2203 | for _, p := range properties.Jars { |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2204 | dest := filepath.Join(scopeDir, ctx.Name()+"-stubs.jar") |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2205 | ctx.SnapshotBuilder().CopyToSnapshot(p, dest) |
| 2206 | jars = append(jars, dest) |
| 2207 | } |
| 2208 | scopeSet.AddProperty("jars", jars) |
| 2209 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 2210 | // Merge the stubs source jar into the snapshot zip so that when it is unpacked |
| 2211 | // the source files are also unpacked. |
| 2212 | snapshotRelativeDir := filepath.Join(scopeDir, ctx.Name()+"_stub_sources") |
| 2213 | ctx.SnapshotBuilder().UnzipToSnapshot(properties.StubsSrcJar, snapshotRelativeDir) |
| 2214 | scopeSet.AddProperty("stub_srcs", []string{snapshotRelativeDir}) |
| 2215 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2216 | if properties.CurrentApiFile != nil { |
| 2217 | currentApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+".txt") |
| 2218 | ctx.SnapshotBuilder().CopyToSnapshot(properties.CurrentApiFile, currentApiSnapshotPath) |
| 2219 | scopeSet.AddProperty("current_api", currentApiSnapshotPath) |
| 2220 | } |
| 2221 | |
| 2222 | if properties.RemovedApiFile != nil { |
| 2223 | removedApiSnapshotPath := filepath.Join(scopeDir, ctx.Name()+"-removed.txt") |
Paul Duffin | 3dbf9fd | 2020-06-02 13:00:02 +0100 | [diff] [blame] | 2224 | ctx.SnapshotBuilder().CopyToSnapshot(properties.RemovedApiFile, removedApiSnapshotPath) |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 2225 | scopeSet.AddProperty("removed_api", removedApiSnapshotPath) |
| 2226 | } |
| 2227 | |
Paul Duffin | dd46f71 | 2020-02-10 13:37:10 +0000 | [diff] [blame] | 2228 | if properties.SdkVersion != "" { |
| 2229 | scopeSet.AddProperty("sdk_version", properties.SdkVersion) |
| 2230 | } |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | if len(s.Libs) > 0 { |
| 2235 | propertySet.AddPropertyWithTag("libs", s.Libs, ctx.SnapshotBuilder().SdkMemberReferencePropertyTag(false)) |
| 2236 | } |
| 2237 | } |