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