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