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