Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 ( |
| 18 | "fmt" |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 19 | "path/filepath" |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 20 | "regexp" |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 21 | "strings" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/java/config" |
| 27 | "android/soong/remoteexec" |
| 28 | ) |
| 29 | |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 30 | // The values allowed for Droidstubs' Api_levels_sdk_type |
Cole Faust | 051fa91 | 2022-10-05 12:45:42 -0700 | [diff] [blame] | 31 | var allowedApiLevelSdkTypes = []string{"public", "system", "module-lib", "system-server"} |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 32 | |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 33 | type StubsType int |
| 34 | |
| 35 | const ( |
| 36 | Everything StubsType = iota |
| 37 | Runtime |
| 38 | Exportable |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 39 | Unavailable |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
| 42 | func (s StubsType) String() string { |
| 43 | switch s { |
| 44 | case Everything: |
| 45 | return "everything" |
| 46 | case Runtime: |
| 47 | return "runtime" |
| 48 | case Exportable: |
| 49 | return "exportable" |
| 50 | default: |
| 51 | return "" |
| 52 | } |
| 53 | } |
| 54 | |
Jihoon Kang | 5d70127 | 2024-02-15 21:53:49 +0000 | [diff] [blame] | 55 | func StringToStubsType(s string) StubsType { |
| 56 | switch strings.ToLower(s) { |
| 57 | case Everything.String(): |
| 58 | return Everything |
| 59 | case Runtime.String(): |
| 60 | return Runtime |
| 61 | case Exportable.String(): |
| 62 | return Exportable |
| 63 | default: |
| 64 | return Unavailable |
| 65 | } |
| 66 | } |
| 67 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 68 | func init() { |
| 69 | RegisterStubsBuildComponents(android.InitRegistrationContext) |
| 70 | } |
| 71 | |
| 72 | func RegisterStubsBuildComponents(ctx android.RegistrationContext) { |
| 73 | ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory) |
| 74 | |
| 75 | ctx.RegisterModuleType("droidstubs", DroidstubsFactory) |
| 76 | ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) |
| 77 | |
| 78 | ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) |
| 79 | } |
| 80 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 81 | type stubsArtifacts struct { |
| 82 | nullabilityWarningsFile android.WritablePath |
| 83 | annotationsZip android.WritablePath |
| 84 | apiVersionsXml android.WritablePath |
| 85 | metadataZip android.WritablePath |
| 86 | metadataDir android.WritablePath |
| 87 | } |
| 88 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 89 | // Droidstubs |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 90 | type Droidstubs struct { |
| 91 | Javadoc |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 92 | embeddableInModuleAndImport |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 93 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 94 | properties DroidstubsProperties |
| 95 | apiFile android.Path |
| 96 | removedApiFile android.Path |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 97 | |
| 98 | checkCurrentApiTimestamp android.WritablePath |
| 99 | updateCurrentApiTimestamp android.WritablePath |
| 100 | checkLastReleasedApiTimestamp android.WritablePath |
| 101 | apiLintTimestamp android.WritablePath |
| 102 | apiLintReport android.WritablePath |
| 103 | |
| 104 | checkNullabilityWarningsTimestamp android.WritablePath |
| 105 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 106 | everythingArtifacts stubsArtifacts |
| 107 | exportableArtifacts stubsArtifacts |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 108 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 109 | exportableApiFile android.WritablePath |
| 110 | exportableRemovedApiFile android.WritablePath |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | type DroidstubsProperties struct { |
| 114 | // The generated public API filename by Metalava, defaults to <module>_api.txt |
| 115 | Api_filename *string |
| 116 | |
| 117 | // the generated removed API filename by Metalava, defaults to <module>_removed.txt |
| 118 | Removed_api_filename *string |
| 119 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 120 | Check_api struct { |
| 121 | Last_released ApiToCheck |
| 122 | |
| 123 | Current ApiToCheck |
| 124 | |
| 125 | Api_lint struct { |
| 126 | Enabled *bool |
| 127 | |
| 128 | // If set, performs api_lint on any new APIs not found in the given signature file |
| 129 | New_since *string `android:"path"` |
| 130 | |
| 131 | // If not blank, path to the baseline txt file for approved API lint violations. |
| 132 | Baseline_file *string `android:"path"` |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // user can specify the version of previous released API file in order to do compatibility check. |
| 137 | Previous_api *string `android:"path"` |
| 138 | |
| 139 | // is set to true, Metalava will allow framework SDK to contain annotations. |
| 140 | Annotations_enabled *bool |
| 141 | |
| 142 | // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from. |
| 143 | Merge_annotations_dirs []string |
| 144 | |
| 145 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 146 | Merge_inclusion_annotations_dirs []string |
| 147 | |
| 148 | // a file containing a list of classes to do nullability validation for. |
| 149 | Validate_nullability_from_list *string |
| 150 | |
| 151 | // a file containing expected warnings produced by validation of nullability annotations. |
| 152 | Check_nullability_warnings *string |
| 153 | |
| 154 | // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. |
| 155 | Create_doc_stubs *bool |
| 156 | |
| 157 | // if set to true, cause Metalava to output Javadoc comments in the stubs source files. Defaults to false. |
| 158 | // Has no effect if create_doc_stubs: true. |
| 159 | Output_javadoc_comments *bool |
| 160 | |
| 161 | // if set to false then do not write out stubs. Defaults to true. |
| 162 | // |
| 163 | // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately. |
| 164 | Generate_stubs *bool |
| 165 | |
| 166 | // if set to true, provides a hint to the build system that this rule uses a lot of memory, |
Liz Kammer | 170dd72 | 2023-10-16 15:08:39 -0400 | [diff] [blame] | 167 | // which can be used for scheduling purposes |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 168 | High_mem *bool |
| 169 | |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 170 | // if set to true, Metalava will allow framework SDK to contain API levels annotations. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 171 | Api_levels_annotations_enabled *bool |
| 172 | |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 173 | // Apply the api levels database created by this module rather than generating one in this droidstubs. |
| 174 | Api_levels_module *string |
| 175 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 176 | // the dirs which Metalava extracts API levels annotations from. |
| 177 | Api_levels_annotations_dirs []string |
| 178 | |
Cole Faust | 051fa91 | 2022-10-05 12:45:42 -0700 | [diff] [blame] | 179 | // the sdk kind which Metalava extracts API levels annotations from. Supports 'public', 'system', 'module-lib' and 'system-server'; defaults to public. |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 180 | Api_levels_sdk_type *string |
| 181 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 182 | // the filename which Metalava extracts API levels annotations from. Defaults to android.jar. |
| 183 | Api_levels_jar_filename *string |
| 184 | |
| 185 | // if set to true, collect the values used by the Dev tools and |
| 186 | // write them in files packaged with the SDK. Defaults to false. |
| 187 | Write_sdk_values *bool |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 188 | |
| 189 | // path or filegroup to file defining extension an SDK name <-> numerical ID mapping and |
| 190 | // what APIs exist in which SDKs; passed to metalava via --sdk-extensions-info |
| 191 | Extensions_info_file *string `android:"path"` |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 192 | |
| 193 | // API surface of this module. If set, the module contributes to an API surface. |
| 194 | // For the full list of available API surfaces, refer to soong/android/sdk_version.go |
| 195 | Api_surface *string |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 196 | |
| 197 | // a list of aconfig_declarations module names that the stubs generated in this module |
| 198 | // depend on. |
| 199 | Aconfig_declarations []string |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 202 | // Used by xsd_config |
| 203 | type ApiFilePath interface { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 204 | ApiFilePath(StubsType) (android.Path, error) |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | type ApiStubsSrcProvider interface { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 208 | StubsSrcJar(StubsType) (android.Path, error) |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 211 | // Provider of information about API stubs, used by java_sdk_library. |
| 212 | type ApiStubsProvider interface { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 213 | AnnotationsZip(StubsType) (android.Path, error) |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 214 | ApiFilePath |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 215 | RemovedApiFilePath(StubsType) (android.Path, error) |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 216 | |
| 217 | ApiStubsSrcProvider |
| 218 | } |
| 219 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 220 | type currentApiTimestampProvider interface { |
| 221 | CurrentApiTimestamp() android.Path |
| 222 | } |
| 223 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 224 | type annotationFlagsParams struct { |
| 225 | migratingNullability bool |
| 226 | validatingNullability bool |
| 227 | nullabilityWarningsFile android.WritablePath |
| 228 | annotationsZip android.WritablePath |
| 229 | } |
| 230 | type stubsCommandParams struct { |
| 231 | srcJarDir android.ModuleOutPath |
| 232 | stubsDir android.OptionalPath |
| 233 | stubsSrcJar android.WritablePath |
| 234 | metadataZip android.WritablePath |
| 235 | metadataDir android.WritablePath |
| 236 | apiVersionsXml android.WritablePath |
| 237 | nullabilityWarningsFile android.WritablePath |
| 238 | annotationsZip android.WritablePath |
| 239 | stubConfig stubsCommandConfigParams |
| 240 | } |
| 241 | type stubsCommandConfigParams struct { |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 242 | stubsType StubsType |
| 243 | javaVersion javaVersion |
| 244 | deps deps |
| 245 | checkApi bool |
| 246 | generateStubs bool |
| 247 | doApiLint bool |
| 248 | doCheckReleased bool |
| 249 | writeSdkValues bool |
| 250 | migratingNullability bool |
| 251 | validatingNullability bool |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 254 | // droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be |
| 255 | // documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to |
| 256 | // a droiddoc module to generate documentation. |
| 257 | func DroidstubsFactory() android.Module { |
| 258 | module := &Droidstubs{} |
| 259 | |
| 260 | module.AddProperties(&module.properties, |
| 261 | &module.Javadoc.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 262 | module.initModuleAndImport(module) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 263 | |
| 264 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 265 | |
| 266 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
| 267 | module.createApiContribution(ctx) |
| 268 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 269 | return module |
| 270 | } |
| 271 | |
| 272 | // droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API |
| 273 | // to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be |
| 274 | // passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs |
| 275 | // module when symbols needed by the source files are provided by java_library_host modules. |
| 276 | func DroidstubsHostFactory() android.Module { |
| 277 | module := &Droidstubs{} |
| 278 | |
| 279 | module.AddProperties(&module.properties, |
| 280 | &module.Javadoc.properties) |
| 281 | |
| 282 | InitDroiddocModule(module, android.HostSupported) |
| 283 | return module |
| 284 | } |
| 285 | |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 286 | func getStubsTypeAndTag(tag string) (StubsType, string, error) { |
| 287 | if len(tag) == 0 { |
| 288 | return Everything, "", nil |
| 289 | } |
| 290 | if tag[0] != '.' { |
| 291 | return Unavailable, "", fmt.Errorf("tag must begin with \".\"") |
| 292 | } |
| 293 | |
| 294 | stubsType := Everything |
| 295 | // Check if the tag has a stubs type prefix (e.g. ".exportable") |
| 296 | for st := Everything; st <= Exportable; st++ { |
| 297 | if strings.HasPrefix(tag, "."+st.String()) { |
| 298 | stubsType = st |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | return stubsType, strings.TrimPrefix(tag, "."+stubsType.String()), nil |
| 303 | } |
| 304 | |
| 305 | // Droidstubs' tag supports specifying with the stubs type. |
| 306 | // While supporting the pre-existing tags, it also supports tags with |
| 307 | // the stubs type prefix. Some examples are shown below: |
| 308 | // {.annotations.zip} - pre-existing behavior. Returns the path to the |
| 309 | // annotation zip. |
| 310 | // {.exportable} - Returns the path to the exportable stubs src jar. |
| 311 | // {.exportable.annotations.zip} - Returns the path to the exportable |
| 312 | // annotations zip file. |
| 313 | // {.runtime.api_versions.xml} - Runtime stubs does not generate api versions |
| 314 | // xml file. For unsupported combinations, the default everything output file |
| 315 | // is returned. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 316 | func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) { |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 317 | stubsType, prefixRemovedTag, err := getStubsTypeAndTag(tag) |
| 318 | if err != nil { |
| 319 | return nil, err |
| 320 | } |
| 321 | switch prefixRemovedTag { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 322 | case "": |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 323 | stubsSrcJar, err := d.StubsSrcJar(stubsType) |
| 324 | return android.Paths{stubsSrcJar}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 325 | case ".docs.zip": |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 326 | docZip, err := d.DocZip(stubsType) |
| 327 | return android.Paths{docZip}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 328 | case ".api.txt", android.DefaultDistTag: |
| 329 | // This is the default dist path for dist properties that have no tag property. |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 330 | apiFilePath, err := d.ApiFilePath(stubsType) |
| 331 | return android.Paths{apiFilePath}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 332 | case ".removed-api.txt": |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 333 | removedApiFilePath, err := d.RemovedApiFilePath(stubsType) |
| 334 | return android.Paths{removedApiFilePath}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 335 | case ".annotations.zip": |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 336 | annotationsZip, err := d.AnnotationsZip(stubsType) |
| 337 | return android.Paths{annotationsZip}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 338 | case ".api_versions.xml": |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 339 | apiVersionsXmlFilePath, err := d.ApiVersionsXmlFilePath(stubsType) |
| 340 | return android.Paths{apiVersionsXmlFilePath}, err |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 341 | default: |
| 342 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 343 | } |
| 344 | } |
| 345 | |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 346 | func (d *Droidstubs) AnnotationsZip(stubsType StubsType) (ret android.Path, err error) { |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 347 | switch stubsType { |
| 348 | case Everything: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 349 | ret, err = d.everythingArtifacts.annotationsZip, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 350 | case Exportable: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 351 | ret, err = d.exportableArtifacts.annotationsZip, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 352 | default: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 353 | ret, err = nil, fmt.Errorf("annotations zip not supported for the stub type %s", stubsType.String()) |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 354 | } |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 355 | return ret, err |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 358 | func (d *Droidstubs) ApiFilePath(stubsType StubsType) (ret android.Path, err error) { |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 359 | switch stubsType { |
| 360 | case Everything: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 361 | ret, err = d.apiFile, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 362 | case Exportable: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 363 | ret, err = d.exportableApiFile, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 364 | default: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 365 | ret, err = nil, fmt.Errorf("api file path not supported for the stub type %s", stubsType.String()) |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 366 | } |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 367 | if ret == nil && err == nil { |
Jihoon Kang | 36c3d96 | 2024-03-14 17:28:44 +0000 | [diff] [blame] | 368 | err = fmt.Errorf("api file is null for the stub type %s", stubsType.String()) |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 369 | } |
| 370 | return ret, err |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 373 | func (d *Droidstubs) ApiVersionsXmlFilePath(stubsType StubsType) (ret android.Path, err error) { |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 374 | switch stubsType { |
| 375 | case Everything: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 376 | ret, err = d.everythingArtifacts.apiVersionsXml, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 377 | case Exportable: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 378 | ret, err = d.exportableArtifacts.apiVersionsXml, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 379 | default: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 380 | ret, err = nil, fmt.Errorf("api versions xml file path not supported for the stub type %s", stubsType.String()) |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 381 | } |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 382 | if ret == nil && err == nil { |
| 383 | err = fmt.Errorf("api versions xml file is null for the stub type %s", stubsType.String()) |
| 384 | } |
| 385 | return ret, err |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 388 | func (d *Droidstubs) DocZip(stubsType StubsType) (ret android.Path, err error) { |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 389 | switch stubsType { |
| 390 | case Everything: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 391 | ret, err = d.docZip, nil |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 392 | default: |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 393 | ret, err = nil, fmt.Errorf("docs zip not supported for the stub type %s", stubsType.String()) |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 394 | } |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 395 | if ret == nil && err == nil { |
| 396 | err = fmt.Errorf("docs zip is null for the stub type %s", stubsType.String()) |
| 397 | } |
| 398 | return ret, err |
| 399 | } |
| 400 | |
| 401 | func (d *Droidstubs) RemovedApiFilePath(stubsType StubsType) (ret android.Path, err error) { |
| 402 | switch stubsType { |
| 403 | case Everything: |
| 404 | ret, err = d.removedApiFile, nil |
| 405 | case Exportable: |
| 406 | ret, err = d.exportableRemovedApiFile, nil |
| 407 | default: |
| 408 | ret, err = nil, fmt.Errorf("removed api file path not supported for the stub type %s", stubsType.String()) |
| 409 | } |
| 410 | if ret == nil && err == nil { |
| 411 | err = fmt.Errorf("removed api file is null for the stub type %s", stubsType.String()) |
| 412 | } |
| 413 | return ret, err |
| 414 | } |
| 415 | |
| 416 | func (d *Droidstubs) StubsSrcJar(stubsType StubsType) (ret android.Path, err error) { |
| 417 | switch stubsType { |
| 418 | case Everything: |
| 419 | ret, err = d.stubsSrcJar, nil |
| 420 | case Exportable: |
| 421 | ret, err = d.exportableStubsSrcJar, nil |
| 422 | default: |
| 423 | ret, err = nil, fmt.Errorf("stubs srcjar not supported for the stub type %s", stubsType.String()) |
| 424 | } |
| 425 | if ret == nil && err == nil { |
| 426 | err = fmt.Errorf("stubs srcjar is null for the stub type %s", stubsType.String()) |
| 427 | } |
| 428 | return ret, err |
Jihoon Kang | 78f8914 | 2023-12-27 01:40:29 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 431 | func (d *Droidstubs) CurrentApiTimestamp() android.Path { |
| 432 | return d.checkCurrentApiTimestamp |
| 433 | } |
| 434 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 435 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} |
| 436 | var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"} |
| 437 | var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"} |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 438 | var metalavaAPILevelsModuleTag = dependencyTag{name: "metalava-api-levels-module-tag"} |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 439 | var metalavaCurrentApiTimestampTag = dependencyTag{name: "metalava-current-api-timestamp-tag"} |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 440 | |
| 441 | func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 442 | d.Javadoc.addDeps(ctx) |
| 443 | |
| 444 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 445 | for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs { |
| 446 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if len(d.properties.Merge_inclusion_annotations_dirs) != 0 { |
| 451 | for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs { |
| 452 | ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir) |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | if len(d.properties.Api_levels_annotations_dirs) != 0 { |
| 457 | for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs { |
| 458 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir) |
| 459 | } |
| 460 | } |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 461 | |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 462 | if len(d.properties.Aconfig_declarations) != 0 { |
| 463 | for _, aconfigDeclarationModuleName := range d.properties.Aconfig_declarations { |
| 464 | ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfigDeclarationModuleName) |
| 465 | } |
| 466 | } |
| 467 | |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 468 | if d.properties.Api_levels_module != nil { |
| 469 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsModuleTag, proptools.String(d.properties.Api_levels_module)) |
| 470 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 473 | func (d *Droidstubs) sdkValuesFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, metadataDir android.WritablePath) { |
| 474 | cmd.FlagWithArg("--sdk-values ", metadataDir.String()) |
| 475 | } |
| 476 | |
| 477 | func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath, stubsType StubsType, checkApi bool) { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 478 | |
Jihoon Kang | 36c3d96 | 2024-03-14 17:28:44 +0000 | [diff] [blame] | 479 | apiFileName := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") |
| 480 | uncheckedApiFile := android.PathForModuleOut(ctx, stubsType.String(), apiFileName) |
| 481 | cmd.FlagWithOutput("--api ", uncheckedApiFile) |
| 482 | if checkApi || String(d.properties.Api_filename) != "" { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 483 | if stubsType == Everything { |
| 484 | d.apiFile = uncheckedApiFile |
| 485 | } else if stubsType == Exportable { |
| 486 | d.exportableApiFile = uncheckedApiFile |
| 487 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 488 | } else if sourceApiFile := proptools.String(d.properties.Check_api.Current.Api_file); sourceApiFile != "" { |
Jihoon Kang | 36c3d96 | 2024-03-14 17:28:44 +0000 | [diff] [blame] | 489 | if stubsType == Everything { |
| 490 | // If check api is disabled then make the source file available for export. |
| 491 | d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile) |
| 492 | } else if stubsType == Exportable { |
| 493 | d.exportableApiFile = uncheckedApiFile |
| 494 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Jihoon Kang | 36c3d96 | 2024-03-14 17:28:44 +0000 | [diff] [blame] | 497 | removedApiFileName := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") |
| 498 | uncheckedRemovedFile := android.PathForModuleOut(ctx, stubsType.String(), removedApiFileName) |
| 499 | cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 500 | if checkApi || String(d.properties.Removed_api_filename) != "" { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 501 | if stubsType == Everything { |
| 502 | d.removedApiFile = uncheckedRemovedFile |
| 503 | } else if stubsType == Exportable { |
| 504 | d.exportableRemovedApiFile = uncheckedRemovedFile |
| 505 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 506 | } else if sourceRemovedApiFile := proptools.String(d.properties.Check_api.Current.Removed_api_file); sourceRemovedApiFile != "" { |
Jihoon Kang | 36c3d96 | 2024-03-14 17:28:44 +0000 | [diff] [blame] | 507 | if stubsType == Everything { |
| 508 | // If check api is disabled then make the source removed api file available for export. |
| 509 | d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile) |
| 510 | } else if stubsType == Exportable { |
| 511 | d.exportableRemovedApiFile = uncheckedRemovedFile |
| 512 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 515 | if stubsDir.Valid() { |
| 516 | if Bool(d.properties.Create_doc_stubs) { |
| 517 | cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) |
| 518 | } else { |
| 519 | cmd.FlagWithArg("--stubs ", stubsDir.String()) |
| 520 | if !Bool(d.properties.Output_javadoc_comments) { |
| 521 | cmd.Flag("--exclude-documentation-from-stubs") |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 527 | func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, params annotationFlagsParams) { |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 528 | if Bool(d.properties.Annotations_enabled) { |
| 529 | cmd.Flag(config.MetalavaAnnotationsFlags) |
Andrei Onea | 4985e51 | 2021-04-29 16:29:34 +0100 | [diff] [blame] | 530 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 531 | if params.migratingNullability { |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 532 | previousApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Previous_api)}) |
| 533 | cmd.FlagForEachInput("--migrate-nullness ", previousApiFiles) |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 534 | } |
Jihoon Kang | 6b93b38 | 2024-01-26 22:37:41 +0000 | [diff] [blame] | 535 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 536 | if s := String(d.properties.Validate_nullability_from_list); s != "" { |
| 537 | cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s)) |
| 538 | } |
Jihoon Kang | 6b93b38 | 2024-01-26 22:37:41 +0000 | [diff] [blame] | 539 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 540 | if params.validatingNullability { |
| 541 | cmd.FlagWithOutput("--nullability-warnings-txt ", params.nullabilityWarningsFile) |
| 542 | } |
Jihoon Kang | 6b93b38 | 2024-01-26 22:37:41 +0000 | [diff] [blame] | 543 | |
Jihoon Kang | ca2f9e8 | 2024-01-26 01:45:12 +0000 | [diff] [blame] | 544 | cmd.FlagWithOutput("--extract-annotations ", params.annotationsZip) |
Jihoon Kang | 6b93b38 | 2024-01-26 22:37:41 +0000 | [diff] [blame] | 545 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 546 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 547 | d.mergeAnnoDirFlags(ctx, cmd) |
| 548 | } |
Jihoon Kang | 6b93b38 | 2024-01-26 22:37:41 +0000 | [diff] [blame] | 549 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 550 | cmd.Flag(config.MetalavaAnnotationsWarningsFlags) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 551 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 555 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { |
| 556 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 557 | cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps) |
| 558 | } else { |
| 559 | ctx.PropertyErrorf("merge_annotations_dirs", |
| 560 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 561 | } |
| 562 | }) |
| 563 | } |
| 564 | |
| 565 | func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 566 | ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) { |
| 567 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 568 | cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps) |
| 569 | } else { |
| 570 | ctx.PropertyErrorf("merge_inclusion_annotations_dirs", |
| 571 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 572 | } |
| 573 | }) |
| 574 | } |
| 575 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 576 | func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType, apiVersionsXml android.WritablePath) { |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 577 | var apiVersions android.Path |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 578 | if proptools.Bool(d.properties.Api_levels_annotations_enabled) { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 579 | d.apiLevelsGenerationFlags(ctx, cmd, stubsType, apiVersionsXml) |
Jihoon Kang | d9a0694 | 2024-01-26 01:49:20 +0000 | [diff] [blame] | 580 | apiVersions = apiVersionsXml |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 581 | } else { |
| 582 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsModuleTag, func(m android.Module) { |
| 583 | if s, ok := m.(*Droidstubs); ok { |
Jihoon Kang | d9a0694 | 2024-01-26 01:49:20 +0000 | [diff] [blame] | 584 | if stubsType == Everything { |
| 585 | apiVersions = s.everythingArtifacts.apiVersionsXml |
| 586 | } else if stubsType == Exportable { |
| 587 | apiVersions = s.exportableArtifacts.apiVersionsXml |
| 588 | } else { |
Jihoon Kang | d40c591 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 589 | ctx.ModuleErrorf("%s stubs type does not generate api-versions.xml file", stubsType.String()) |
Jihoon Kang | d9a0694 | 2024-01-26 01:49:20 +0000 | [diff] [blame] | 590 | } |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 591 | } else { |
| 592 | ctx.PropertyErrorf("api_levels_module", |
| 593 | "module %q is not a droidstubs module", ctx.OtherModuleName(m)) |
| 594 | } |
| 595 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 596 | } |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 597 | if apiVersions != nil { |
| 598 | cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) |
| 599 | cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) |
| 600 | cmd.FlagWithInput("--apply-api-levels ", apiVersions) |
| 601 | } |
| 602 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 603 | |
Paul Duffin | 5a195f4 | 2024-05-01 12:52:35 +0100 | [diff] [blame] | 604 | // AndroidPlusUpdatableJar is the name of some extra jars added into `module-lib` and |
| 605 | // `system-server` directories that contain all the APIs provided by the platform and updatable |
| 606 | // modules because the `android.jar` files do not. See b/337836752. |
| 607 | const AndroidPlusUpdatableJar = "android-plus-updatable.jar" |
| 608 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 609 | func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType, apiVersionsXml android.WritablePath) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 610 | if len(d.properties.Api_levels_annotations_dirs) == 0 { |
| 611 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 612 | "has to be non-empty if api levels annotations was enabled!") |
| 613 | } |
| 614 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 615 | cmd.FlagWithOutput("--generate-api-levels ", apiVersionsXml) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 616 | |
| 617 | filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar") |
| 618 | |
Paul Duffin | 58cfc9a | 2024-04-25 17:01:49 +0100 | [diff] [blame] | 619 | // TODO: Avoid the duplication of API surfaces, reuse apiScope. |
| 620 | // Add all relevant --android-jar-pattern patterns for Metalava. |
| 621 | // When parsing a stub jar for a specific version, Metalava picks the first pattern that defines |
| 622 | // an actual file present on disk (in the order the patterns were passed). For system APIs for |
| 623 | // privileged apps that are only defined since API level 21 (Lollipop), fallback to public stubs |
| 624 | // for older releases. Similarly, module-lib falls back to system API. |
| 625 | var sdkDirs []string |
Paul Duffin | 92efc61 | 2024-05-02 17:18:05 +0100 | [diff] [blame] | 626 | apiLevelsSdkType := proptools.StringDefault(d.properties.Api_levels_sdk_type, "public") |
| 627 | switch apiLevelsSdkType { |
Paul Duffin | 58cfc9a | 2024-04-25 17:01:49 +0100 | [diff] [blame] | 628 | case "system-server": |
| 629 | sdkDirs = []string{"system-server", "module-lib", "system", "public"} |
| 630 | case "module-lib": |
| 631 | sdkDirs = []string{"module-lib", "system", "public"} |
| 632 | case "system": |
| 633 | sdkDirs = []string{"system", "public"} |
| 634 | case "public": |
| 635 | sdkDirs = []string{"public"} |
| 636 | default: |
| 637 | ctx.PropertyErrorf("api_levels_sdk_type", "needs to be one of %v", allowedApiLevelSdkTypes) |
| 638 | return |
| 639 | } |
| 640 | |
Paul Duffin | 92efc61 | 2024-05-02 17:18:05 +0100 | [diff] [blame] | 641 | // Construct a pattern to match the appropriate extensions that should be included in the |
| 642 | // generated api-versions.xml file. |
| 643 | // |
Paul Duffin | 58cfc9a | 2024-04-25 17:01:49 +0100 | [diff] [blame] | 644 | // Use the first item in the sdkDirs array as that is the sdk type for the target API levels |
| 645 | // being generated but has the advantage over `Api_levels_sdk_type` as it has been validated. |
Paul Duffin | 92efc61 | 2024-05-02 17:18:05 +0100 | [diff] [blame] | 646 | // The exception is for system-server which needs to include module-lib and system-server. That |
| 647 | // is because while system-server extends module-lib the system-server extension directory only |
| 648 | // contains service-* modules which provide system-server APIs it does not list the modules which |
| 649 | // only provide a module-lib, so they have to be included separately. |
| 650 | extensionSurfacesPattern := sdkDirs[0] |
| 651 | if apiLevelsSdkType == "system-server" { |
| 652 | // Take the first two items in sdkDirs, which are system-server and module-lib, and construct |
| 653 | // a pattern that will match either. |
| 654 | extensionSurfacesPattern = strings.Join(sdkDirs[0:2], "|") |
| 655 | } |
| 656 | extensionsPattern := fmt.Sprintf(`/extensions/[0-9]+/(%s)/.*\.jar`, extensionSurfacesPattern) |
Paul Duffin | 58cfc9a | 2024-04-25 17:01:49 +0100 | [diff] [blame] | 657 | |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 658 | var dirs []string |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 659 | var extensions_dir string |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 660 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) { |
| 661 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Paul Duffin | 58cfc9a | 2024-04-25 17:01:49 +0100 | [diff] [blame] | 662 | extRegex := regexp.MustCompile(t.dir.String() + extensionsPattern) |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 663 | |
| 664 | // Grab the first extensions_dir and we find while scanning ExportedDroiddocDir.deps; |
| 665 | // ideally this should be read from prebuiltApis.properties.Extensions_* |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 666 | for _, dep := range t.deps { |
Paul Duffin | 2ced2eb | 2024-05-01 13:13:51 +0100 | [diff] [blame] | 667 | // Check to see if it matches an extension first. |
| 668 | depBase := dep.Base() |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 669 | if extRegex.MatchString(dep.String()) && d.properties.Extensions_info_file != nil { |
| 670 | if extensions_dir == "" { |
| 671 | extensions_dir = t.dir.String() + "/extensions" |
| 672 | } |
| 673 | cmd.Implicit(dep) |
Paul Duffin | 2ced2eb | 2024-05-01 13:13:51 +0100 | [diff] [blame] | 674 | } else if depBase == filename { |
| 675 | // Check to see if it matches a dessert release for an SDK, e.g. Android, Car, Wear, etc.. |
Colin Cross | 5f6ffc7 | 2021-03-29 21:54:45 -0700 | [diff] [blame] | 676 | cmd.Implicit(dep) |
Paul Duffin | 5a195f4 | 2024-05-01 12:52:35 +0100 | [diff] [blame] | 677 | } else if depBase == AndroidPlusUpdatableJar && d.properties.Extensions_info_file != nil { |
| 678 | // The output api-versions.xml has been requested to include information on SDK |
| 679 | // extensions. That means it also needs to include |
| 680 | // so |
| 681 | // The module-lib and system-server directories should use `android-plus-updatable.jar` |
| 682 | // instead of `android.jar`. See AndroidPlusUpdatableJar for more information. |
| 683 | cmd.Implicit(dep) |
Paul Duffin | 2ced2eb | 2024-05-01 13:13:51 +0100 | [diff] [blame] | 684 | } else if filename != "android.jar" && depBase == "android.jar" { |
Colin Cross | 5f6ffc7 | 2021-03-29 21:54:45 -0700 | [diff] [blame] | 685 | // Metalava implicitly searches these patterns: |
| 686 | // prebuilts/tools/common/api-versions/android-%/android.jar |
| 687 | // prebuilts/sdk/%/public/android.jar |
| 688 | // Add android.jar files from the api_levels_annotations_dirs directories to try |
| 689 | // to satisfy these patterns. If Metalava can't find a match for an API level |
| 690 | // between 1 and 28 in at least one pattern it will fail. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 691 | cmd.Implicit(dep) |
| 692 | } |
| 693 | } |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 694 | |
| 695 | dirs = append(dirs, t.dir.String()) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 696 | } else { |
| 697 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 698 | "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m)) |
| 699 | } |
| 700 | }) |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 701 | |
Paul Duffin | 5a195f4 | 2024-05-01 12:52:35 +0100 | [diff] [blame] | 702 | // Generate the list of --android-jar-pattern options. The order matters so the first one which |
| 703 | // matches will be the one that is used for a specific api level.. |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 704 | for _, sdkDir := range sdkDirs { |
| 705 | for _, dir := range dirs { |
Paul Duffin | 5a195f4 | 2024-05-01 12:52:35 +0100 | [diff] [blame] | 706 | addPattern := func(jarFilename string) { |
| 707 | cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/%%/%s/%s", dir, sdkDir, jarFilename)) |
| 708 | } |
| 709 | |
| 710 | if sdkDir == "module-lib" || sdkDir == "system-server" { |
| 711 | // The module-lib and system-server android.jars do not include the updatable modules (as |
| 712 | // doing so in the source would introduce dependency cycles and the prebuilts have to |
| 713 | // match the sources). So, instead an additional `android-plus-updatable.jar` will be used |
| 714 | // that does include the updatable modules and this pattern will match that. This pattern |
| 715 | // is added in addition to the following pattern to decouple this change from the change |
| 716 | // to add the `android-plus-updatable.jar`. |
| 717 | addPattern(AndroidPlusUpdatableJar) |
| 718 | } |
| 719 | |
| 720 | addPattern(filename) |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 721 | } |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 722 | } |
MÃ¥rten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 723 | |
| 724 | if d.properties.Extensions_info_file != nil { |
| 725 | if extensions_dir == "" { |
| 726 | ctx.ModuleErrorf("extensions_info_file set, but no SDK extension dirs found") |
| 727 | } |
| 728 | info_file := android.PathForModuleSrc(ctx, *d.properties.Extensions_info_file) |
| 729 | cmd.Implicit(info_file) |
| 730 | cmd.FlagWithArg("--sdk-extensions-root ", extensions_dir) |
| 731 | cmd.FlagWithArg("--sdk-extensions-info ", info_file.String()) |
| 732 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Jihoon Kang | 472f73f | 2024-03-28 20:59:29 +0000 | [diff] [blame] | 735 | func (d *Droidstubs) apiCompatibilityFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType) { |
| 736 | if len(d.Javadoc.properties.Out) > 0 { |
| 737 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 738 | } |
| 739 | |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 740 | apiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Api_file)}) |
| 741 | removedApiFiles := android.PathsForModuleSrc(ctx, []string{String(d.properties.Check_api.Last_released.Removed_api_file)}) |
Jihoon Kang | 472f73f | 2024-03-28 20:59:29 +0000 | [diff] [blame] | 742 | |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 743 | cmd.FlagForEachInput("--check-compatibility:api:released ", apiFiles) |
| 744 | cmd.FlagForEachInput("--check-compatibility:removed:released ", removedApiFiles) |
Jihoon Kang | 472f73f | 2024-03-28 20:59:29 +0000 | [diff] [blame] | 745 | |
| 746 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file) |
| 747 | if baselineFile.Valid() { |
| 748 | cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path()) |
| 749 | } |
| 750 | } |
| 751 | |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 752 | func metalavaUseRbe(ctx android.ModuleContext) bool { |
| 753 | return ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA") |
| 754 | } |
| 755 | |
Jihoon Kang | 421c1cd | 2024-04-22 21:17:12 +0000 | [diff] [blame] | 756 | func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
| 757 | srcJarList android.Path, homeDir android.WritablePath, params stubsCommandConfigParams) *android.RuleBuilderCommand { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 758 | rule.Command().Text("rm -rf").Flag(homeDir.String()) |
| 759 | rule.Command().Text("mkdir -p").Flag(homeDir.String()) |
| 760 | |
Anton Hansson | 556e814 | 2021-06-04 16:20:25 +0100 | [diff] [blame] | 761 | cmd := rule.Command() |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 762 | cmd.FlagWithArg("ANDROID_PREFS_ROOT=", homeDir.String()) |
| 763 | |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 764 | if metalavaUseRbe(ctx) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 765 | rule.Remoteable(android.RemoteRuleSupports{RBE: true}) |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 766 | execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
Anas Sulaiman | 9d7a36d | 2023-11-21 23:00:07 +0000 | [diff] [blame] | 767 | compare := ctx.Config().IsEnvTrue("RBE_METALAVA_COMPARE") |
| 768 | remoteUpdateCache := !ctx.Config().IsEnvFalse("RBE_METALAVA_REMOTE_UPDATE_CACHE") |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 769 | labels := map[string]string{"type": "tool", "name": "metalava"} |
| 770 | // TODO: metalava pool rejects these jobs |
| 771 | pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16") |
| 772 | rule.Rewrapper(&remoteexec.REParams{ |
Anas Sulaiman | 9d7a36d | 2023-11-21 23:00:07 +0000 | [diff] [blame] | 773 | Labels: labels, |
| 774 | ExecStrategy: execStrategy, |
| 775 | ToolchainInputs: []string{config.JavaCmd(ctx).String()}, |
| 776 | Platform: map[string]string{remoteexec.PoolKey: pool}, |
| 777 | Compare: compare, |
| 778 | NumLocalRuns: 1, |
| 779 | NumRemoteRuns: 1, |
| 780 | NoRemoteUpdateCache: !remoteUpdateCache, |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 781 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Colin Cross | 6aa5c40 | 2021-03-24 12:28:50 -0700 | [diff] [blame] | 784 | cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")). |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 785 | Flag(config.JavacVmFlags). |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 786 | Flag(config.MetalavaAddOpens). |
Jihoon Kang | 421c1cd | 2024-04-22 21:17:12 +0000 | [diff] [blame] | 787 | FlagWithArg("--java-source ", params.javaVersion.String()). |
| 788 | FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, fmt.Sprintf("%s.metalava.rsp", params.stubsType.String())), srcs). |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 789 | FlagWithInput("@", srcJarList) |
| 790 | |
Paul Duffin | f8aaaa1 | 2023-08-10 15:16:35 +0100 | [diff] [blame] | 791 | // Metalava does not differentiate between bootclasspath and classpath and has not done so for |
| 792 | // years, so it is unlikely to change any time soon. |
Jihoon Kang | 421c1cd | 2024-04-22 21:17:12 +0000 | [diff] [blame] | 793 | combinedPaths := append(([]android.Path)(nil), params.deps.bootClasspath.Paths()...) |
| 794 | combinedPaths = append(combinedPaths, params.deps.classpath.Paths()...) |
Paul Duffin | f8aaaa1 | 2023-08-10 15:16:35 +0100 | [diff] [blame] | 795 | if len(combinedPaths) > 0 { |
| 796 | cmd.FlagWithInputList("--classpath ", combinedPaths, ":") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 799 | cmd.Flag(config.MetalavaFlags) |
Jihoon Kang | c831389 | 2023-09-20 00:54:47 +0000 | [diff] [blame] | 800 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 801 | return cmd |
| 802 | } |
| 803 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 804 | // Pass flagged apis related flags to metalava. When aconfig_declarations property is not |
| 805 | // defined for a module, simply revert all flagged apis annotations. If aconfig_declarations |
| 806 | // property is defined, apply transformations and only revert the flagged apis that are not |
| 807 | // enabled via release configurations and are not specified in aconfig_declarations |
Jihoon Kang | 5d70127 | 2024-02-15 21:53:49 +0000 | [diff] [blame] | 808 | func generateRevertAnnotationArgs(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsType StubsType, aconfigFlagsPaths android.Paths) { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 809 | |
| 810 | if len(aconfigFlagsPaths) == 0 { |
| 811 | cmd.Flag("--revert-annotation android.annotation.FlaggedApi") |
| 812 | return |
| 813 | } |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 814 | |
| 815 | releasedFlaggedApisFile := android.PathForModuleOut(ctx, fmt.Sprintf("released-flagged-apis-%s.txt", stubsType.String())) |
| 816 | revertAnnotationsFile := android.PathForModuleOut(ctx, fmt.Sprintf("revert-annotations-%s.txt", stubsType.String())) |
| 817 | |
| 818 | var filterArgs string |
| 819 | switch stubsType { |
| 820 | // No flagged apis specific flags need to be passed to metalava when generating |
| 821 | // everything stubs |
| 822 | case Everything: |
| 823 | return |
| 824 | |
| 825 | case Runtime: |
| 826 | filterArgs = "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'" |
| 827 | |
| 828 | case Exportable: |
Jihoon Kang | 5919815 | 2024-02-06 22:43:18 +0000 | [diff] [blame] | 829 | // When the build flag RELEASE_EXPORT_RUNTIME_APIS is set to true, apis marked with |
| 830 | // the flagged apis that have read_write permissions are exposed on top of the enabled |
| 831 | // and read_only apis. This is to support local override of flag values at runtime. |
| 832 | if ctx.Config().ReleaseExportRuntimeApis() { |
| 833 | filterArgs = "--filter='state:ENABLED+permission:READ_ONLY' --filter='permission:READ_WRITE'" |
| 834 | } else { |
| 835 | filterArgs = "--filter='state:ENABLED+permission:READ_ONLY'" |
| 836 | } |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | ctx.Build(pctx, android.BuildParams{ |
| 840 | Rule: gatherReleasedFlaggedApisRule, |
| 841 | Inputs: aconfigFlagsPaths, |
| 842 | Output: releasedFlaggedApisFile, |
| 843 | Description: fmt.Sprintf("%s gather aconfig flags", stubsType), |
| 844 | Args: map[string]string{ |
| 845 | "flags_path": android.JoinPathsWithPrefix(aconfigFlagsPaths, "--cache "), |
| 846 | "filter_args": filterArgs, |
| 847 | }, |
| 848 | }) |
| 849 | |
| 850 | ctx.Build(pctx, android.BuildParams{ |
| 851 | Rule: generateMetalavaRevertAnnotationsRule, |
| 852 | Input: releasedFlaggedApisFile, |
| 853 | Output: revertAnnotationsFile, |
| 854 | Description: fmt.Sprintf("%s revert annotations", stubsType), |
| 855 | }) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 856 | |
| 857 | cmd.FlagWithInput("@", revertAnnotationsFile) |
Jihoon Kang | 6592e87 | 2023-12-19 01:13:16 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 860 | func (d *Droidstubs) commonMetalavaStubCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
| 861 | params stubsCommandParams) *android.RuleBuilderCommand { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 862 | if BoolDefault(d.properties.High_mem, false) { |
| 863 | // This metalava run uses lots of memory, restrict the number of metalava jobs that can run in parallel. |
| 864 | rule.HighMem() |
| 865 | } |
| 866 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 867 | if params.stubConfig.generateStubs { |
| 868 | rule.Command().Text("rm -rf").Text(params.stubsDir.String()) |
| 869 | rule.Command().Text("mkdir -p").Text(params.stubsDir.String()) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 872 | srcJarList := zipSyncCmd(ctx, rule, params.srcJarDir, d.Javadoc.srcJars) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 873 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 874 | homeDir := android.PathForModuleOut(ctx, params.stubConfig.stubsType.String(), "home") |
Jihoon Kang | 421c1cd | 2024-04-22 21:17:12 +0000 | [diff] [blame] | 875 | cmd := metalavaCmd(ctx, rule, d.Javadoc.srcFiles, srcJarList, homeDir, params.stubConfig) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 876 | cmd.Implicits(d.Javadoc.implicits) |
| 877 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 878 | d.stubsFlags(ctx, cmd, params.stubsDir, params.stubConfig.stubsType, params.stubConfig.checkApi) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 879 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 880 | if params.stubConfig.writeSdkValues { |
| 881 | d.sdkValuesFlags(ctx, cmd, params.metadataDir) |
| 882 | } |
| 883 | |
| 884 | annotationParams := annotationFlagsParams{ |
| 885 | migratingNullability: params.stubConfig.migratingNullability, |
| 886 | validatingNullability: params.stubConfig.validatingNullability, |
| 887 | nullabilityWarningsFile: params.nullabilityWarningsFile, |
| 888 | annotationsZip: params.annotationsZip, |
| 889 | } |
| 890 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 891 | d.annotationsFlags(ctx, cmd, annotationParams) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 892 | d.inclusionAnnotationsFlags(ctx, cmd) |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 893 | d.apiLevelsAnnotationsFlags(ctx, cmd, params.stubConfig.stubsType, params.apiVersionsXml) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 894 | |
Jihoon Kang | 472f73f | 2024-03-28 20:59:29 +0000 | [diff] [blame] | 895 | if params.stubConfig.doCheckReleased { |
| 896 | d.apiCompatibilityFlags(ctx, cmd, params.stubConfig.stubsType) |
| 897 | } |
| 898 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 899 | d.expandArgs(ctx, cmd) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 900 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 901 | for _, o := range d.Javadoc.properties.Out { |
| 902 | cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) |
| 903 | } |
| 904 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 905 | return cmd |
| 906 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 907 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 908 | // Sandbox rule for generating the everything stubs and other artifacts |
| 909 | func (d *Droidstubs) everythingStubCmd(ctx android.ModuleContext, params stubsCommandConfigParams) { |
| 910 | srcJarDir := android.PathForModuleOut(ctx, Everything.String(), "srcjars") |
| 911 | rule := android.NewRuleBuilder(pctx, ctx) |
| 912 | rule.Sbox(android.PathForModuleOut(ctx, Everything.String()), |
| 913 | android.PathForModuleOut(ctx, "metalava.sbox.textproto")). |
| 914 | SandboxInputs() |
| 915 | |
| 916 | var stubsDir android.OptionalPath |
| 917 | if params.generateStubs { |
| 918 | stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, Everything.String(), "stubsDir")) |
| 919 | d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, Everything.String(), ctx.ModuleName()+"-"+"stubs.srcjar") |
| 920 | } |
| 921 | |
| 922 | if params.writeSdkValues { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 923 | d.everythingArtifacts.metadataDir = android.PathForModuleOut(ctx, Everything.String(), "metadata") |
| 924 | d.everythingArtifacts.metadataZip = android.PathForModuleOut(ctx, Everything.String(), ctx.ModuleName()+"-metadata.zip") |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 927 | if Bool(d.properties.Annotations_enabled) { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 928 | if params.validatingNullability { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 929 | d.everythingArtifacts.nullabilityWarningsFile = android.PathForModuleOut(ctx, Everything.String(), ctx.ModuleName()+"_nullability_warnings.txt") |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 930 | } |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 931 | d.everythingArtifacts.annotationsZip = android.PathForModuleOut(ctx, Everything.String(), ctx.ModuleName()+"_annotations.zip") |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 932 | } |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 933 | if Bool(d.properties.Api_levels_annotations_enabled) { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 934 | d.everythingArtifacts.apiVersionsXml = android.PathForModuleOut(ctx, Everything.String(), "api-versions.xml") |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | commonCmdParams := stubsCommandParams{ |
| 938 | srcJarDir: srcJarDir, |
| 939 | stubsDir: stubsDir, |
| 940 | stubsSrcJar: d.Javadoc.stubsSrcJar, |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 941 | metadataDir: d.everythingArtifacts.metadataDir, |
| 942 | apiVersionsXml: d.everythingArtifacts.apiVersionsXml, |
| 943 | nullabilityWarningsFile: d.everythingArtifacts.nullabilityWarningsFile, |
| 944 | annotationsZip: d.everythingArtifacts.annotationsZip, |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 945 | stubConfig: params, |
| 946 | } |
| 947 | |
| 948 | cmd := d.commonMetalavaStubCmd(ctx, rule, commonCmdParams) |
| 949 | |
| 950 | d.everythingOptionalCmd(ctx, cmd, params.doApiLint, params.doCheckReleased) |
| 951 | |
| 952 | if params.generateStubs { |
| 953 | rule.Command(). |
| 954 | BuiltTool("soong_zip"). |
| 955 | Flag("-write_if_changed"). |
| 956 | Flag("-jar"). |
| 957 | FlagWithOutput("-o ", d.Javadoc.stubsSrcJar). |
| 958 | FlagWithArg("-C ", stubsDir.String()). |
| 959 | FlagWithArg("-D ", stubsDir.String()) |
| 960 | } |
| 961 | |
| 962 | if params.writeSdkValues { |
| 963 | rule.Command(). |
| 964 | BuiltTool("soong_zip"). |
| 965 | Flag("-write_if_changed"). |
| 966 | Flag("-d"). |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 967 | FlagWithOutput("-o ", d.everythingArtifacts.metadataZip). |
| 968 | FlagWithArg("-C ", d.everythingArtifacts.metadataDir.String()). |
| 969 | FlagWithArg("-D ", d.everythingArtifacts.metadataDir.String()) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | // TODO: We don't really need two separate API files, but this is a reminiscence of how |
| 973 | // we used to run metalava separately for API lint and the "last_released" check. Unify them. |
| 974 | if params.doApiLint { |
| 975 | rule.Command().Text("touch").Output(d.apiLintTimestamp) |
| 976 | } |
| 977 | if params.doCheckReleased { |
| 978 | rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp) |
| 979 | } |
| 980 | |
| 981 | // TODO(b/183630617): rewrapper doesn't support restat rules |
| 982 | if !metalavaUseRbe(ctx) { |
| 983 | rule.Restat() |
| 984 | } |
| 985 | |
| 986 | zipSyncCleanupCmd(rule, srcJarDir) |
| 987 | |
| 988 | rule.Build("metalava", "metalava merged") |
| 989 | } |
| 990 | |
| 991 | // Sandbox rule for generating the everything artifacts that are not run by |
| 992 | // default but only run based on the module configurations |
| 993 | func (d *Droidstubs) everythingOptionalCmd(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, doApiLint bool, doCheckReleased bool) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 994 | |
| 995 | // Add API lint options. |
Paul Duffin | baf3478 | 2024-05-28 17:27:22 +0100 | [diff] [blame] | 996 | treatDocumentationIssuesAsErrors := false |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 997 | if doApiLint { |
Jihoon Kang | 5623e54 | 2024-01-31 23:27:26 +0000 | [diff] [blame] | 998 | var newSince android.Paths |
| 999 | if d.properties.Check_api.Api_lint.New_since != nil { |
| 1000 | newSince = android.PathsForModuleSrc(ctx, []string{proptools.String(d.properties.Check_api.Api_lint.New_since)}) |
| 1001 | } |
Paul Duffin | 0a71d73 | 2024-04-22 13:22:56 +0100 | [diff] [blame] | 1002 | cmd.Flag("--api-lint") |
| 1003 | cmd.FlagForEachInput("--api-lint-previous-api ", newSince) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1004 | d.apiLintReport = android.PathForModuleOut(ctx, Everything.String(), "api_lint_report.txt") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1005 | cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint" |
| 1006 | |
Colin Cross | 0d53241 | 2021-03-25 09:38:45 -0700 | [diff] [blame] | 1007 | // TODO(b/154317059): Clean up this allowlist by baselining and/or checking in last-released. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1008 | if d.Name() != "android.car-system-stubs-docs" && |
| 1009 | d.Name() != "android.car-stubs-docs" { |
Paul Duffin | baf3478 | 2024-05-28 17:27:22 +0100 | [diff] [blame] | 1010 | treatDocumentationIssuesAsErrors = true |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1011 | cmd.Flag("--warnings-as-errors") // Most lints are actually warnings. |
| 1012 | } |
| 1013 | |
| 1014 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1015 | updatedBaselineOutput := android.PathForModuleOut(ctx, Everything.String(), "api_lint_baseline.txt") |
| 1016 | d.apiLintTimestamp = android.PathForModuleOut(ctx, Everything.String(), "api_lint.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1017 | |
| 1018 | // Note this string includes a special shell quote $' ... ', which decodes the "\n"s. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1019 | // |
| 1020 | // TODO: metalava also has a slightly different message hardcoded. Should we unify this |
| 1021 | // message and metalava's one? |
| 1022 | msg := `$'` + // Enclose with $' ... ' |
| 1023 | `************************************************************\n` + |
| 1024 | `Your API changes are triggering API Lint warnings or errors.\n` + |
| 1025 | `To make these errors go away, fix the code according to the\n` + |
| 1026 | `error and/or warning messages above.\n` + |
| 1027 | `\n` + |
| 1028 | `If it is not possible to do so, there are workarounds:\n` + |
| 1029 | `\n` + |
Aurimas Liutikas | b23b745 | 2021-05-24 18:00:37 +0000 | [diff] [blame] | 1030 | `1. You can suppress the errors with @SuppressLint("<id>")\n` + |
| 1031 | ` where the <id> is given in brackets in the error message above.\n` |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1032 | |
| 1033 | if baselineFile.Valid() { |
| 1034 | cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path()) |
| 1035 | cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput) |
| 1036 | |
| 1037 | msg += fmt.Sprintf(``+ |
| 1038 | `2. You can update the baseline by executing the following\n`+ |
| 1039 | ` command:\n`+ |
Colin Cross | 63eeda0 | 2021-04-15 19:01:57 -0700 | [diff] [blame] | 1040 | ` (cd $ANDROID_BUILD_TOP && cp \\\n`+ |
| 1041 | ` "%s" \\\n`+ |
| 1042 | ` "%s")\n`+ |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1043 | ` To submit the revised baseline.txt to the main Android\n`+ |
| 1044 | ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path()) |
| 1045 | } else { |
| 1046 | msg += fmt.Sprintf(``+ |
| 1047 | `2. You can add a baseline file of existing lint failures\n`+ |
| 1048 | ` to the build rule of %s.\n`, d.Name()) |
| 1049 | } |
| 1050 | // Note the message ends with a ' (single quote), to close the $' ... ' . |
| 1051 | msg += `************************************************************\n'` |
| 1052 | |
| 1053 | cmd.FlagWithArg("--error-message:api-lint ", msg) |
| 1054 | } |
| 1055 | |
Paul Duffin | baf3478 | 2024-05-28 17:27:22 +0100 | [diff] [blame] | 1056 | if !treatDocumentationIssuesAsErrors { |
Paul Duffin | b679bdd | 2024-06-10 14:29:41 +0100 | [diff] [blame] | 1057 | treatDocumentationIssuesAsWarningErrorWhenNew(cmd) |
Paul Duffin | baf3478 | 2024-05-28 17:27:22 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1060 | // Add "check released" options. (Detect incompatible API changes from the last public release) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1061 | if doCheckReleased { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1062 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1063 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, Everything.String(), "check_last_released_api.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1064 | if baselineFile.Valid() { |
Jihoon Kang | 472f73f | 2024-03-28 20:59:29 +0000 | [diff] [blame] | 1065 | updatedBaselineOutput := android.PathForModuleOut(ctx, Everything.String(), "last_released_baseline.txt") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1066 | cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput) |
| 1067 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1068 | // Note this string includes quote ($' ... '), which decodes the "\n"s. |
| 1069 | msg := `$'\n******************************\n` + |
| 1070 | `You have tried to change the API from what has been previously released in\n` + |
| 1071 | `an SDK. Please fix the errors listed above.\n` + |
| 1072 | `******************************\n'` |
| 1073 | |
| 1074 | cmd.FlagWithArg("--error-message:compatibility:released ", msg) |
| 1075 | } |
| 1076 | |
Paul Duffin | 10a23c2 | 2023-08-11 22:47:31 +0100 | [diff] [blame] | 1077 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { |
| 1078 | // Pass the current API file into metalava so it can use it as the basis for determining how to |
| 1079 | // generate the output signature files (both api and removed). |
| 1080 | currentApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) |
| 1081 | cmd.FlagWithInput("--use-same-format-as ", currentApiFile) |
| 1082 | } |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1083 | } |
Paul Duffin | 10a23c2 | 2023-08-11 22:47:31 +0100 | [diff] [blame] | 1084 | |
Paul Duffin | b679bdd | 2024-06-10 14:29:41 +0100 | [diff] [blame] | 1085 | // HIDDEN_DOCUMENTATION_ISSUES is the set of documentation related issues that should always be |
| 1086 | // hidden as they are very noisy and provide little value. |
| 1087 | var HIDDEN_DOCUMENTATION_ISSUES = []string{ |
| 1088 | "Deprecated", |
| 1089 | "IntDef", |
| 1090 | "Nullable", |
| 1091 | } |
| 1092 | |
| 1093 | func treatDocumentationIssuesAsWarningErrorWhenNew(cmd *android.RuleBuilderCommand) { |
| 1094 | // Treat documentation issues as warnings, but error when new. |
| 1095 | cmd.Flag("--error-when-new-category").Flag("Documentation") |
| 1096 | |
| 1097 | // Hide some documentation issues that generated a lot of noise for little benefit. |
| 1098 | cmd.FlagForEachArg("--hide ", HIDDEN_DOCUMENTATION_ISSUES) |
| 1099 | } |
| 1100 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1101 | // Sandbox rule for generating exportable stubs and other artifacts |
| 1102 | func (d *Droidstubs) exportableStubCmd(ctx android.ModuleContext, params stubsCommandConfigParams) { |
| 1103 | optionalCmdParams := stubsCommandParams{ |
| 1104 | stubConfig: params, |
| 1105 | } |
| 1106 | |
Jihoon Kang | 246690a | 2024-02-01 21:55:01 +0000 | [diff] [blame] | 1107 | if params.generateStubs { |
| 1108 | d.Javadoc.exportableStubsSrcJar = android.PathForModuleOut(ctx, params.stubsType.String(), ctx.ModuleName()+"-"+"stubs.srcjar") |
| 1109 | optionalCmdParams.stubsSrcJar = d.Javadoc.exportableStubsSrcJar |
| 1110 | } |
| 1111 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1112 | if params.writeSdkValues { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1113 | d.exportableArtifacts.metadataZip = android.PathForModuleOut(ctx, params.stubsType.String(), ctx.ModuleName()+"-metadata.zip") |
| 1114 | d.exportableArtifacts.metadataDir = android.PathForModuleOut(ctx, params.stubsType.String(), "metadata") |
| 1115 | optionalCmdParams.metadataZip = d.exportableArtifacts.metadataZip |
| 1116 | optionalCmdParams.metadataDir = d.exportableArtifacts.metadataDir |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 1119 | if Bool(d.properties.Annotations_enabled) { |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1120 | if params.validatingNullability { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1121 | d.exportableArtifacts.nullabilityWarningsFile = android.PathForModuleOut(ctx, params.stubsType.String(), ctx.ModuleName()+"_nullability_warnings.txt") |
| 1122 | optionalCmdParams.nullabilityWarningsFile = d.exportableArtifacts.nullabilityWarningsFile |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1123 | } |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1124 | d.exportableArtifacts.annotationsZip = android.PathForModuleOut(ctx, params.stubsType.String(), ctx.ModuleName()+"_annotations.zip") |
| 1125 | optionalCmdParams.annotationsZip = d.exportableArtifacts.annotationsZip |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1126 | } |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 1127 | if Bool(d.properties.Api_levels_annotations_enabled) { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1128 | d.exportableArtifacts.apiVersionsXml = android.PathForModuleOut(ctx, params.stubsType.String(), "api-versions.xml") |
| 1129 | optionalCmdParams.apiVersionsXml = d.exportableArtifacts.apiVersionsXml |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | if params.checkApi || String(d.properties.Api_filename) != "" { |
| 1133 | filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") |
| 1134 | d.exportableApiFile = android.PathForModuleOut(ctx, params.stubsType.String(), filename) |
| 1135 | } |
| 1136 | |
| 1137 | if params.checkApi || String(d.properties.Removed_api_filename) != "" { |
| 1138 | filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_api.txt") |
| 1139 | d.exportableRemovedApiFile = android.PathForModuleOut(ctx, params.stubsType.String(), filename) |
| 1140 | } |
| 1141 | |
| 1142 | d.optionalStubCmd(ctx, optionalCmdParams) |
| 1143 | } |
| 1144 | |
| 1145 | func (d *Droidstubs) optionalStubCmd(ctx android.ModuleContext, params stubsCommandParams) { |
| 1146 | |
| 1147 | params.srcJarDir = android.PathForModuleOut(ctx, params.stubConfig.stubsType.String(), "srcjars") |
| 1148 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1149 | rule.Sbox(android.PathForModuleOut(ctx, params.stubConfig.stubsType.String()), |
| 1150 | android.PathForModuleOut(ctx, fmt.Sprintf("metalava_%s.sbox.textproto", params.stubConfig.stubsType.String()))). |
| 1151 | SandboxInputs() |
| 1152 | |
| 1153 | if params.stubConfig.generateStubs { |
| 1154 | params.stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, params.stubConfig.stubsType.String(), "stubsDir")) |
| 1155 | } |
| 1156 | |
| 1157 | cmd := d.commonMetalavaStubCmd(ctx, rule, params) |
| 1158 | |
Jihoon Kang | 5d70127 | 2024-02-15 21:53:49 +0000 | [diff] [blame] | 1159 | generateRevertAnnotationArgs(ctx, cmd, params.stubConfig.stubsType, params.stubConfig.deps.aconfigProtoFiles) |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1160 | |
| 1161 | if params.stubConfig.doApiLint { |
| 1162 | // Pass the lint baseline file as an input to resolve the lint errors. |
| 1163 | // The exportable stubs generation does not update the lint baseline file. |
| 1164 | // Lint baseline file update is handled by the everything stubs |
| 1165 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file) |
| 1166 | if baselineFile.Valid() { |
| 1167 | cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path()) |
| 1168 | } |
| 1169 | } |
| 1170 | |
Paul Duffin | 71527b7 | 2024-05-31 13:30:32 +0100 | [diff] [blame] | 1171 | // Treat documentation issues as warnings, but error when new. |
Paul Duffin | b679bdd | 2024-06-10 14:29:41 +0100 | [diff] [blame] | 1172 | treatDocumentationIssuesAsWarningErrorWhenNew(cmd) |
Paul Duffin | 71527b7 | 2024-05-31 13:30:32 +0100 | [diff] [blame] | 1173 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1174 | if params.stubConfig.generateStubs { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1175 | rule.Command(). |
| 1176 | BuiltTool("soong_zip"). |
| 1177 | Flag("-write_if_changed"). |
| 1178 | Flag("-jar"). |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1179 | FlagWithOutput("-o ", params.stubsSrcJar). |
| 1180 | FlagWithArg("-C ", params.stubsDir.String()). |
| 1181 | FlagWithArg("-D ", params.stubsDir.String()) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1184 | if params.stubConfig.writeSdkValues { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1185 | rule.Command(). |
| 1186 | BuiltTool("soong_zip"). |
| 1187 | Flag("-write_if_changed"). |
| 1188 | Flag("-d"). |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1189 | FlagWithOutput("-o ", params.metadataZip). |
| 1190 | FlagWithArg("-C ", params.metadataDir.String()). |
| 1191 | FlagWithArg("-D ", params.metadataDir.String()) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Colin Cross | 6aa5c40 | 2021-03-24 12:28:50 -0700 | [diff] [blame] | 1194 | // TODO(b/183630617): rewrapper doesn't support restat rules |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 1195 | if !metalavaUseRbe(ctx) { |
| 1196 | rule.Restat() |
| 1197 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1198 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1199 | zipSyncCleanupCmd(rule, params.srcJarDir) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1200 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1201 | rule.Build(fmt.Sprintf("metalava_%s", params.stubConfig.stubsType.String()), "metalava merged") |
| 1202 | } |
| 1203 | |
| 1204 | func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1205 | deps := d.Javadoc.collectDeps(ctx) |
| 1206 | |
| 1207 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), android.SdkContext(d)) |
| 1208 | generateStubs := BoolDefault(d.properties.Generate_stubs, true) |
| 1209 | |
| 1210 | // Add options for the other optional tasks: API-lint and check-released. |
| 1211 | // We generate separate timestamp files for them. |
| 1212 | doApiLint := BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) |
| 1213 | doCheckReleased := apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") |
| 1214 | |
| 1215 | writeSdkValues := Bool(d.properties.Write_sdk_values) |
| 1216 | |
| 1217 | annotationsEnabled := Bool(d.properties.Annotations_enabled) |
| 1218 | |
| 1219 | migratingNullability := annotationsEnabled && String(d.properties.Previous_api) != "" |
| 1220 | validatingNullability := annotationsEnabled && (strings.Contains(String(d.Javadoc.properties.Args), "--validate-nullability-from-merged-stubs") || |
| 1221 | String(d.properties.Validate_nullability_from_list) != "") |
| 1222 | |
| 1223 | checkApi := apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || |
| 1224 | apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") |
| 1225 | |
| 1226 | stubCmdParams := stubsCommandConfigParams{ |
Jihoon Kang | a11d679 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 1227 | javaVersion: javaVersion, |
| 1228 | deps: deps, |
| 1229 | checkApi: checkApi, |
| 1230 | generateStubs: generateStubs, |
| 1231 | doApiLint: doApiLint, |
| 1232 | doCheckReleased: doCheckReleased, |
| 1233 | writeSdkValues: writeSdkValues, |
| 1234 | migratingNullability: migratingNullability, |
| 1235 | validatingNullability: validatingNullability, |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1236 | } |
| 1237 | stubCmdParams.stubsType = Everything |
| 1238 | // Create default (i.e. "everything" stubs) rule for metalava |
| 1239 | d.everythingStubCmd(ctx, stubCmdParams) |
| 1240 | |
Jihoon Kang | d40c591 | 2024-03-05 16:12:20 +0000 | [diff] [blame] | 1241 | // The module generates "exportable" (and "runtime" eventually) stubs regardless of whether |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1242 | // aconfig_declarations property is defined or not. If the property is not defined, the module simply |
| 1243 | // strips all flagged apis to generate the "exportable" stubs |
| 1244 | stubCmdParams.stubsType = Exportable |
| 1245 | d.exportableStubCmd(ctx, stubCmdParams) |
Paul Duffin | c166b68 | 2022-05-27 12:23:08 +0000 | [diff] [blame] | 1246 | |
Paul Duffin | e7a8664 | 2022-08-16 15:43:20 +0000 | [diff] [blame] | 1247 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { |
| 1248 | |
| 1249 | if len(d.Javadoc.properties.Out) > 0 { |
| 1250 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 1251 | } |
| 1252 | |
| 1253 | apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) |
| 1254 | removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) |
| 1255 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) |
| 1256 | |
| 1257 | if baselineFile.Valid() { |
| 1258 | ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) |
| 1259 | } |
| 1260 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1261 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, Everything.String(), "check_current_api.timestamp") |
Paul Duffin | e7a8664 | 2022-08-16 15:43:20 +0000 | [diff] [blame] | 1262 | |
| 1263 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1264 | |
| 1265 | // Diff command line. |
| 1266 | // -F matches the closest "opening" line, such as "package android {" |
| 1267 | // and " public class Intent {". |
| 1268 | diff := `diff -u -F '{ *$'` |
| 1269 | |
| 1270 | rule.Command().Text("( true") |
| 1271 | rule.Command(). |
| 1272 | Text(diff). |
| 1273 | Input(apiFile).Input(d.apiFile) |
| 1274 | |
| 1275 | rule.Command(). |
| 1276 | Text(diff). |
| 1277 | Input(removedApiFile).Input(d.removedApiFile) |
| 1278 | |
| 1279 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 1280 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1281 | `To make these errors go away, you have two choices:\n`+ |
| 1282 | ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ |
| 1283 | ` to the new methods, etc. shown in the above diff.\n\n`+ |
| 1284 | ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ |
| 1285 | ` m %s-update-current-api\n\n`+ |
| 1286 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1287 | ` you will need approval.\n`+ |
Jihoon Kang | 3ea6467 | 2023-11-03 00:40:26 +0000 | [diff] [blame] | 1288 | `If your build failed due to stub validation, you can resolve the errors with\n`+ |
| 1289 | `either of the two choices above and try re-building the target.\n`+ |
| 1290 | `If the mismatch between the stubs and the current.txt is intended,\n`+ |
| 1291 | `you can try re-building the target by executing the following command:\n`+ |
Jihoon Kang | 91bf3dd | 2024-01-24 00:40:23 +0000 | [diff] [blame] | 1292 | `m DISABLE_STUB_VALIDATION=true <your build target>.\n`+ |
| 1293 | `Note that DISABLE_STUB_VALIDATION=true does not bypass checkapi.\n`+ |
Paul Duffin | e7a8664 | 2022-08-16 15:43:20 +0000 | [diff] [blame] | 1294 | `******************************\n`, ctx.ModuleName()) |
| 1295 | |
| 1296 | rule.Command(). |
| 1297 | Text("touch").Output(d.checkCurrentApiTimestamp). |
| 1298 | Text(") || ("). |
| 1299 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1300 | Text("; exit 38"). |
| 1301 | Text(")") |
| 1302 | |
| 1303 | rule.Build("metalavaCurrentApiCheck", "check current API") |
| 1304 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1305 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, Everything.String(), "update_current_api.timestamp") |
Paul Duffin | e7a8664 | 2022-08-16 15:43:20 +0000 | [diff] [blame] | 1306 | |
| 1307 | // update API rule |
| 1308 | rule = android.NewRuleBuilder(pctx, ctx) |
| 1309 | |
| 1310 | rule.Command().Text("( true") |
| 1311 | |
| 1312 | rule.Command(). |
| 1313 | Text("cp").Flag("-f"). |
| 1314 | Input(d.apiFile).Flag(apiFile.String()) |
| 1315 | |
| 1316 | rule.Command(). |
| 1317 | Text("cp").Flag("-f"). |
| 1318 | Input(d.removedApiFile).Flag(removedApiFile.String()) |
| 1319 | |
| 1320 | msg = "failed to update public API" |
| 1321 | |
| 1322 | rule.Command(). |
| 1323 | Text("touch").Output(d.updateCurrentApiTimestamp). |
| 1324 | Text(") || ("). |
| 1325 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1326 | Text("; exit 38"). |
| 1327 | Text(")") |
| 1328 | |
| 1329 | rule.Build("metalavaCurrentApiUpdate", "update current API") |
| 1330 | } |
| 1331 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1332 | if String(d.properties.Check_nullability_warnings) != "" { |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1333 | if d.everythingArtifacts.nullabilityWarningsFile == nil { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1334 | ctx.PropertyErrorf("check_nullability_warnings", |
| 1335 | "Cannot specify check_nullability_warnings unless validating nullability") |
| 1336 | } |
| 1337 | |
| 1338 | checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings)) |
| 1339 | |
Jihoon Kang | 3c89f04 | 2023-12-19 02:40:22 +0000 | [diff] [blame] | 1340 | d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, Everything.String(), "check_nullability_warnings.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1341 | |
| 1342 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 1343 | `The warnings encountered during nullability annotation validation did\n`+ |
| 1344 | `not match the checked in file of expected warnings. The diffs are shown\n`+ |
| 1345 | `above. You have two options:\n`+ |
| 1346 | ` 1. Resolve the differences by editing the nullability annotations.\n`+ |
| 1347 | ` 2. Update the file of expected warnings by running:\n`+ |
| 1348 | ` cp %s %s\n`+ |
| 1349 | ` and submitting the updated file as part of your change.`, |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1350 | d.everythingArtifacts.nullabilityWarningsFile, checkNullabilityWarnings) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1351 | |
| 1352 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1353 | |
| 1354 | rule.Command(). |
| 1355 | Text("("). |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1356 | Text("diff").Input(checkNullabilityWarnings).Input(d.everythingArtifacts.nullabilityWarningsFile). |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1357 | Text("&&"). |
| 1358 | Text("touch").Output(d.checkNullabilityWarningsTimestamp). |
| 1359 | Text(") || ("). |
| 1360 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1361 | Text("; exit 38"). |
| 1362 | Text(")") |
| 1363 | |
| 1364 | rule.Build("nullabilityWarningsCheck", "nullability warnings check") |
| 1365 | } |
| 1366 | } |
| 1367 | |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1368 | func (d *Droidstubs) createApiContribution(ctx android.DefaultableHookContext) { |
| 1369 | api_file := d.properties.Check_api.Current.Api_file |
| 1370 | api_surface := d.properties.Api_surface |
| 1371 | |
| 1372 | props := struct { |
| 1373 | Name *string |
| 1374 | Api_surface *string |
| 1375 | Api_file *string |
Jihoon Kang | 42b589c | 2023-02-03 22:56:13 +0000 | [diff] [blame] | 1376 | Visibility []string |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1377 | }{} |
| 1378 | |
| 1379 | props.Name = proptools.StringPtr(d.Name() + ".api.contribution") |
| 1380 | props.Api_surface = api_surface |
| 1381 | props.Api_file = api_file |
Jihoon Kang | 42b589c | 2023-02-03 22:56:13 +0000 | [diff] [blame] | 1382 | props.Visibility = []string{"//visibility:override", "//visibility:public"} |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 1383 | |
| 1384 | ctx.CreateModule(ApiContributionFactory, &props) |
| 1385 | } |
| 1386 | |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 1387 | // TODO (b/262014796): Export the API contributions of CorePlatformApi |
| 1388 | // A map to populate the api surface of a droidstub from a substring appearing in its name |
| 1389 | // This map assumes that droidstubs (either checked-in or created by java_sdk_library) |
| 1390 | // use a strict naming convention |
| 1391 | var ( |
| 1392 | droidstubsModuleNamingToSdkKind = map[string]android.SdkKind{ |
Paul Duffin | 2ced2eb | 2024-05-01 13:13:51 +0100 | [diff] [blame] | 1393 | // public is commented out since the core libraries use public in their java_sdk_library names |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 1394 | "intracore": android.SdkIntraCore, |
| 1395 | "intra.core": android.SdkIntraCore, |
| 1396 | "system_server": android.SdkSystemServer, |
| 1397 | "system-server": android.SdkSystemServer, |
| 1398 | "system": android.SdkSystem, |
| 1399 | "module_lib": android.SdkModule, |
| 1400 | "module-lib": android.SdkModule, |
Spandan Das | da97755 | 2023-01-26 20:45:16 +0000 | [diff] [blame] | 1401 | "platform.api": android.SdkCorePlatform, |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 1402 | "test": android.SdkTest, |
Spandan Das | 4ac2aed | 2022-12-28 01:54:29 +0000 | [diff] [blame] | 1403 | "toolchain": android.SdkToolchain, |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 1404 | } |
| 1405 | ) |
| 1406 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1407 | func StubsDefaultsFactory() android.Module { |
| 1408 | module := &DocDefaults{} |
| 1409 | |
| 1410 | module.AddProperties( |
| 1411 | &JavadocProperties{}, |
| 1412 | &DroidstubsProperties{}, |
| 1413 | ) |
| 1414 | |
| 1415 | android.InitDefaultsModule(module) |
| 1416 | |
| 1417 | return module |
| 1418 | } |
| 1419 | |
| 1420 | var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil) |
| 1421 | |
| 1422 | type PrebuiltStubsSourcesProperties struct { |
| 1423 | Srcs []string `android:"path"` |
Spandan Das | 23956d1 | 2024-01-19 00:22:22 +0000 | [diff] [blame] | 1424 | |
| 1425 | // Name of the source soong module that gets shadowed by this prebuilt |
| 1426 | // If unspecified, follows the naming convention that the source module of |
| 1427 | // the prebuilt is Name() without "prebuilt_" prefix |
| 1428 | Source_module_name *string |
| 1429 | |
| 1430 | // Non-nil if this prebuilt stub srcs module was dynamically created by a java_sdk_library_import |
| 1431 | // The name is the undecorated name of the java_sdk_library as it appears in the blueprint file |
| 1432 | // (without any prebuilt_ prefix) |
| 1433 | Created_by_java_sdk_library_name *string `blueprint:"mutated"` |
| 1434 | } |
| 1435 | |
| 1436 | func (j *PrebuiltStubsSources) BaseModuleName() string { |
| 1437 | return proptools.StringDefault(j.properties.Source_module_name, j.ModuleBase.Name()) |
| 1438 | } |
| 1439 | |
| 1440 | func (j *PrebuiltStubsSources) CreatedByJavaSdkLibraryName() *string { |
| 1441 | return j.properties.Created_by_java_sdk_library_name |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | type PrebuiltStubsSources struct { |
| 1445 | android.ModuleBase |
| 1446 | android.DefaultableModuleBase |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1447 | embeddableInModuleAndImport |
| 1448 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1449 | prebuilt android.Prebuilt |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1450 | |
| 1451 | properties PrebuiltStubsSourcesProperties |
| 1452 | |
kgui | 6700724 | 2022-01-25 13:50:25 +0800 | [diff] [blame] | 1453 | stubsSrcJar android.Path |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Jihoon Kang | ee11328 | 2024-01-23 00:16:41 +0000 | [diff] [blame] | 1456 | func (d *PrebuiltStubsSources) StubsSrcJar(_ StubsType) (android.Path, error) { |
| 1457 | return d.stubsSrcJar, nil |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1461 | if len(p.properties.Srcs) != 1 { |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 1462 | ctx.PropertyErrorf("srcs", "must only specify one directory path or srcjar, contains %d paths", len(p.properties.Srcs)) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1463 | return |
| 1464 | } |
| 1465 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 1466 | src := p.properties.Srcs[0] |
| 1467 | if filepath.Ext(src) == ".srcjar" { |
| 1468 | // This is a srcjar. We can use it directly. |
| 1469 | p.stubsSrcJar = android.PathForModuleSrc(ctx, src) |
| 1470 | } else { |
| 1471 | outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1472 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 1473 | // This is a directory. Glob the contents just in case the directory does not exist. |
| 1474 | srcGlob := src + "/**/*" |
| 1475 | srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1476 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 1477 | // Although PathForModuleSrc can return nil if either the path doesn't exist or |
| 1478 | // the path components are invalid it won't in this case because no components |
| 1479 | // are specified and the module directory must exist in order to get this far. |
| 1480 | srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, src) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1481 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 1482 | rule := android.NewRuleBuilder(pctx, ctx) |
| 1483 | rule.Command(). |
| 1484 | BuiltTool("soong_zip"). |
| 1485 | Flag("-write_if_changed"). |
| 1486 | Flag("-jar"). |
| 1487 | FlagWithOutput("-o ", outPath). |
| 1488 | FlagWithArg("-C ", srcDir.String()). |
| 1489 | FlagWithRspFileInputList("-r ", outPath.ReplaceExtension(ctx, "rsp"), srcPaths) |
| 1490 | rule.Restat() |
| 1491 | rule.Build("zip src", "Create srcjar from prebuilt source") |
| 1492 | p.stubsSrcJar = outPath |
| 1493 | } |
mrziwang | aa2a2b6 | 2024-07-01 12:09:20 -0700 | [diff] [blame] | 1494 | |
| 1495 | ctx.SetOutputFiles(android.Paths{p.stubsSrcJar}, "") |
| 1496 | // prebuilt droidstubs does not output "exportable" stubs. |
| 1497 | // Output the "everything" stubs srcjar file if the tag is ".exportable". |
| 1498 | ctx.SetOutputFiles(android.Paths{p.stubsSrcJar}, ".exportable") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt { |
| 1502 | return &p.prebuilt |
| 1503 | } |
| 1504 | |
| 1505 | func (p *PrebuiltStubsSources) Name() string { |
| 1506 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 1507 | } |
| 1508 | |
| 1509 | // prebuilt_stubs_sources imports a set of java source files as if they were |
| 1510 | // generated by droidstubs. |
| 1511 | // |
| 1512 | // By default, a prebuilt_stubs_sources has a single variant that expects a |
| 1513 | // set of `.java` files generated by droidstubs. |
| 1514 | // |
| 1515 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1516 | // for host modules. |
| 1517 | // |
| 1518 | // Intended only for use by sdk snapshots. |
| 1519 | func PrebuiltStubsSourcesFactory() android.Module { |
| 1520 | module := &PrebuiltStubsSources{} |
| 1521 | |
| 1522 | module.AddProperties(&module.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame] | 1523 | module.initModuleAndImport(module) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1524 | |
| 1525 | android.InitPrebuiltModule(module, &module.properties.Srcs) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1526 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 1527 | return module |
| 1528 | } |