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