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