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