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" |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 21 | "sort" |
Anas Sulaiman | 9c49364 | 2023-10-18 16:34:37 +0000 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint/proptools" |
| 26 | |
| 27 | "android/soong/android" |
| 28 | "android/soong/java/config" |
| 29 | "android/soong/remoteexec" |
| 30 | ) |
| 31 | |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 32 | // The values allowed for Droidstubs' Api_levels_sdk_type |
Cole Faust | 051fa91 | 2022-10-05 12:45:42 -0700 | [diff] [blame] | 33 | var allowedApiLevelSdkTypes = []string{"public", "system", "module-lib", "system-server"} |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 34 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 35 | func init() { |
| 36 | RegisterStubsBuildComponents(android.InitRegistrationContext) |
| 37 | } |
| 38 | |
| 39 | func RegisterStubsBuildComponents(ctx android.RegistrationContext) { |
| 40 | ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory) |
| 41 | |
| 42 | ctx.RegisterModuleType("droidstubs", DroidstubsFactory) |
| 43 | ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) |
| 44 | |
| 45 | ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) |
| 46 | } |
| 47 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 48 | // Droidstubs |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 49 | type Droidstubs struct { |
| 50 | Javadoc |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame^] | 51 | embeddableInModuleAndImport |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 52 | |
| 53 | properties DroidstubsProperties |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 54 | apiFile android.Path |
| 55 | removedApiFile android.Path |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 56 | nullabilityWarningsFile android.WritablePath |
| 57 | |
| 58 | checkCurrentApiTimestamp android.WritablePath |
| 59 | updateCurrentApiTimestamp android.WritablePath |
| 60 | checkLastReleasedApiTimestamp android.WritablePath |
| 61 | apiLintTimestamp android.WritablePath |
| 62 | apiLintReport android.WritablePath |
| 63 | |
| 64 | checkNullabilityWarningsTimestamp android.WritablePath |
| 65 | |
| 66 | annotationsZip android.WritablePath |
| 67 | apiVersionsXml android.WritablePath |
| 68 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 69 | metadataZip android.WritablePath |
| 70 | metadataDir android.WritablePath |
| 71 | } |
| 72 | |
| 73 | type DroidstubsProperties struct { |
| 74 | // The generated public API filename by Metalava, defaults to <module>_api.txt |
| 75 | Api_filename *string |
| 76 | |
| 77 | // the generated removed API filename by Metalava, defaults to <module>_removed.txt |
| 78 | Removed_api_filename *string |
| 79 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 80 | Check_api struct { |
| 81 | Last_released ApiToCheck |
| 82 | |
| 83 | Current ApiToCheck |
| 84 | |
| 85 | Api_lint struct { |
| 86 | Enabled *bool |
| 87 | |
| 88 | // If set, performs api_lint on any new APIs not found in the given signature file |
| 89 | New_since *string `android:"path"` |
| 90 | |
| 91 | // If not blank, path to the baseline txt file for approved API lint violations. |
| 92 | Baseline_file *string `android:"path"` |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // user can specify the version of previous released API file in order to do compatibility check. |
| 97 | Previous_api *string `android:"path"` |
| 98 | |
| 99 | // is set to true, Metalava will allow framework SDK to contain annotations. |
| 100 | Annotations_enabled *bool |
| 101 | |
| 102 | // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from. |
| 103 | Merge_annotations_dirs []string |
| 104 | |
| 105 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 106 | Merge_inclusion_annotations_dirs []string |
| 107 | |
| 108 | // a file containing a list of classes to do nullability validation for. |
| 109 | Validate_nullability_from_list *string |
| 110 | |
| 111 | // a file containing expected warnings produced by validation of nullability annotations. |
| 112 | Check_nullability_warnings *string |
| 113 | |
| 114 | // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. |
| 115 | Create_doc_stubs *bool |
| 116 | |
| 117 | // if set to true, cause Metalava to output Javadoc comments in the stubs source files. Defaults to false. |
| 118 | // Has no effect if create_doc_stubs: true. |
| 119 | Output_javadoc_comments *bool |
| 120 | |
| 121 | // if set to false then do not write out stubs. Defaults to true. |
| 122 | // |
| 123 | // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately. |
| 124 | Generate_stubs *bool |
| 125 | |
| 126 | // 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] | 127 | // which can be used for scheduling purposes |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 128 | High_mem *bool |
| 129 | |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 130 | // 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] | 131 | Api_levels_annotations_enabled *bool |
| 132 | |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 133 | // Apply the api levels database created by this module rather than generating one in this droidstubs. |
| 134 | Api_levels_module *string |
| 135 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 136 | // the dirs which Metalava extracts API levels annotations from. |
| 137 | Api_levels_annotations_dirs []string |
| 138 | |
Cole Faust | 051fa91 | 2022-10-05 12:45:42 -0700 | [diff] [blame] | 139 | // 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] | 140 | Api_levels_sdk_type *string |
| 141 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 142 | // the filename which Metalava extracts API levels annotations from. Defaults to android.jar. |
| 143 | Api_levels_jar_filename *string |
| 144 | |
| 145 | // if set to true, collect the values used by the Dev tools and |
| 146 | // write them in files packaged with the SDK. Defaults to false. |
| 147 | Write_sdk_values *bool |
Mårten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 148 | |
| 149 | // path or filegroup to file defining extension an SDK name <-> numerical ID mapping and |
| 150 | // what APIs exist in which SDKs; passed to metalava via --sdk-extensions-info |
| 151 | Extensions_info_file *string `android:"path"` |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 152 | |
| 153 | // API surface of this module. If set, the module contributes to an API surface. |
| 154 | // For the full list of available API surfaces, refer to soong/android/sdk_version.go |
| 155 | Api_surface *string |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 158 | // Used by xsd_config |
| 159 | type ApiFilePath interface { |
| 160 | ApiFilePath() android.Path |
| 161 | } |
| 162 | |
| 163 | type ApiStubsSrcProvider interface { |
| 164 | StubsSrcJar() android.Path |
| 165 | } |
| 166 | |
| 167 | // Provider of information about API stubs, used by java_sdk_library. |
| 168 | type ApiStubsProvider interface { |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 169 | AnnotationsZip() android.Path |
Anton Hansson | 5260932 | 2021-05-05 10:36:05 +0100 | [diff] [blame] | 170 | ApiFilePath |
| 171 | RemovedApiFilePath() android.Path |
| 172 | |
| 173 | ApiStubsSrcProvider |
| 174 | } |
| 175 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 176 | type currentApiTimestampProvider interface { |
| 177 | CurrentApiTimestamp() android.Path |
| 178 | } |
| 179 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 180 | // droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be |
| 181 | // documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to |
| 182 | // a droiddoc module to generate documentation. |
| 183 | func DroidstubsFactory() android.Module { |
| 184 | module := &Droidstubs{} |
| 185 | |
| 186 | module.AddProperties(&module.properties, |
| 187 | &module.Javadoc.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame^] | 188 | module.initModuleAndImport(module) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 189 | |
| 190 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 191 | |
| 192 | module.SetDefaultableHook(func(ctx android.DefaultableHookContext) { |
| 193 | module.createApiContribution(ctx) |
| 194 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 195 | return module |
| 196 | } |
| 197 | |
| 198 | // droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API |
| 199 | // to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be |
| 200 | // passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs |
| 201 | // module when symbols needed by the source files are provided by java_library_host modules. |
| 202 | func DroidstubsHostFactory() android.Module { |
| 203 | module := &Droidstubs{} |
| 204 | |
| 205 | module.AddProperties(&module.properties, |
| 206 | &module.Javadoc.properties) |
| 207 | |
| 208 | InitDroiddocModule(module, android.HostSupported) |
| 209 | return module |
| 210 | } |
| 211 | |
| 212 | func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) { |
| 213 | switch tag { |
| 214 | case "": |
| 215 | return android.Paths{d.stubsSrcJar}, nil |
| 216 | case ".docs.zip": |
| 217 | return android.Paths{d.docZip}, nil |
| 218 | case ".api.txt", android.DefaultDistTag: |
| 219 | // This is the default dist path for dist properties that have no tag property. |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 220 | return android.Paths{d.apiFile}, nil |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 221 | case ".removed-api.txt": |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 222 | return android.Paths{d.removedApiFile}, nil |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 223 | case ".annotations.zip": |
| 224 | return android.Paths{d.annotationsZip}, nil |
| 225 | case ".api_versions.xml": |
| 226 | return android.Paths{d.apiVersionsXml}, nil |
| 227 | default: |
| 228 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 229 | } |
| 230 | } |
| 231 | |
Anton Hansson | d78eb76 | 2021-09-21 15:25:12 +0100 | [diff] [blame] | 232 | func (d *Droidstubs) AnnotationsZip() android.Path { |
| 233 | return d.annotationsZip |
| 234 | } |
| 235 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 236 | func (d *Droidstubs) ApiFilePath() android.Path { |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 237 | return d.apiFile |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | func (d *Droidstubs) RemovedApiFilePath() android.Path { |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 241 | return d.removedApiFile |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | func (d *Droidstubs) StubsSrcJar() android.Path { |
| 245 | return d.stubsSrcJar |
| 246 | } |
| 247 | |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 248 | func (d *Droidstubs) CurrentApiTimestamp() android.Path { |
| 249 | return d.checkCurrentApiTimestamp |
| 250 | } |
| 251 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 252 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} |
| 253 | var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"} |
| 254 | var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"} |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 255 | var metalavaAPILevelsModuleTag = dependencyTag{name: "metalava-api-levels-module-tag"} |
Jihoon Kang | 063ec00 | 2023-06-28 01:16:23 +0000 | [diff] [blame] | 256 | var metalavaCurrentApiTimestampTag = dependencyTag{name: "metalava-current-api-timestamp-tag"} |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 257 | |
| 258 | func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 259 | d.Javadoc.addDeps(ctx) |
| 260 | |
| 261 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 262 | for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs { |
| 263 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | if len(d.properties.Merge_inclusion_annotations_dirs) != 0 { |
| 268 | for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs { |
| 269 | ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir) |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if len(d.properties.Api_levels_annotations_dirs) != 0 { |
| 274 | for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs { |
| 275 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir) |
| 276 | } |
| 277 | } |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 278 | |
| 279 | if d.properties.Api_levels_module != nil { |
| 280 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsModuleTag, proptools.String(d.properties.Api_levels_module)) |
| 281 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) { |
| 285 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || |
| 286 | apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || |
| 287 | String(d.properties.Api_filename) != "" { |
| 288 | filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 289 | uncheckedApiFile := android.PathForModuleOut(ctx, "metalava", filename) |
| 290 | cmd.FlagWithOutput("--api ", uncheckedApiFile) |
| 291 | d.apiFile = uncheckedApiFile |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 292 | } else if sourceApiFile := proptools.String(d.properties.Check_api.Current.Api_file); sourceApiFile != "" { |
| 293 | // If check api is disabled then make the source file available for export. |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 294 | d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || |
| 298 | apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || |
| 299 | String(d.properties.Removed_api_filename) != "" { |
| 300 | filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 301 | uncheckedRemovedFile := android.PathForModuleOut(ctx, "metalava", filename) |
| 302 | cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile) |
| 303 | d.removedApiFile = uncheckedRemovedFile |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 304 | } else if sourceRemovedApiFile := proptools.String(d.properties.Check_api.Current.Removed_api_file); sourceRemovedApiFile != "" { |
| 305 | // If check api is disabled then make the source removed api file available for export. |
Paul Duffin | c71d2b7 | 2022-08-16 15:24:01 +0000 | [diff] [blame] | 306 | d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 309 | if Bool(d.properties.Write_sdk_values) { |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 310 | d.metadataDir = android.PathForModuleOut(ctx, "metalava", "metadata") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 311 | cmd.FlagWithArg("--sdk-values ", d.metadataDir.String()) |
| 312 | } |
| 313 | |
| 314 | if stubsDir.Valid() { |
| 315 | if Bool(d.properties.Create_doc_stubs) { |
| 316 | cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) |
| 317 | } else { |
| 318 | cmd.FlagWithArg("--stubs ", stubsDir.String()) |
| 319 | if !Bool(d.properties.Output_javadoc_comments) { |
| 320 | cmd.Flag("--exclude-documentation-from-stubs") |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 327 | if Bool(d.properties.Annotations_enabled) { |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 328 | cmd.Flag(config.MetalavaAnnotationsFlags) |
Andrei Onea | 4985e51 | 2021-04-29 16:29:34 +0100 | [diff] [blame] | 329 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 330 | validatingNullability := |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 331 | strings.Contains(String(d.Javadoc.properties.Args), "--validate-nullability-from-merged-stubs") || |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 332 | String(d.properties.Validate_nullability_from_list) != "" |
| 333 | |
| 334 | migratingNullability := String(d.properties.Previous_api) != "" |
| 335 | if migratingNullability { |
| 336 | previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api)) |
| 337 | cmd.FlagWithInput("--migrate-nullness ", previousApi) |
| 338 | } |
| 339 | |
| 340 | if s := String(d.properties.Validate_nullability_from_list); s != "" { |
| 341 | cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s)) |
| 342 | } |
| 343 | |
| 344 | if validatingNullability { |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 345 | d.nullabilityWarningsFile = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"_nullability_warnings.txt") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 346 | cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile) |
| 347 | } |
| 348 | |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 349 | d.annotationsZip = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"_annotations.zip") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 350 | cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip) |
| 351 | |
| 352 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 353 | d.mergeAnnoDirFlags(ctx, cmd) |
| 354 | } |
| 355 | |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 356 | cmd.Flag(config.MetalavaAnnotationsWarningsFlags) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 361 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { |
| 362 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 363 | cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps) |
| 364 | } else { |
| 365 | ctx.PropertyErrorf("merge_annotations_dirs", |
| 366 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 367 | } |
| 368 | }) |
| 369 | } |
| 370 | |
| 371 | func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 372 | ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) { |
| 373 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 374 | cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps) |
| 375 | } else { |
| 376 | ctx.PropertyErrorf("merge_inclusion_annotations_dirs", |
| 377 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 378 | } |
| 379 | }) |
| 380 | } |
| 381 | |
| 382 | func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 383 | var apiVersions android.Path |
| 384 | if proptools.Bool(d.properties.Api_levels_annotations_enabled) { |
| 385 | d.apiLevelsGenerationFlags(ctx, cmd) |
| 386 | apiVersions = d.apiVersionsXml |
| 387 | } else { |
| 388 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsModuleTag, func(m android.Module) { |
| 389 | if s, ok := m.(*Droidstubs); ok { |
| 390 | apiVersions = s.apiVersionsXml |
| 391 | } else { |
| 392 | ctx.PropertyErrorf("api_levels_module", |
| 393 | "module %q is not a droidstubs module", ctx.OtherModuleName(m)) |
| 394 | } |
| 395 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 396 | } |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 397 | if apiVersions != nil { |
| 398 | cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) |
| 399 | cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) |
| 400 | cmd.FlagWithInput("--apply-api-levels ", apiVersions) |
| 401 | } |
| 402 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 403 | |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 404 | func (d *Droidstubs) apiLevelsGenerationFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 405 | if len(d.properties.Api_levels_annotations_dirs) == 0 { |
| 406 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 407 | "has to be non-empty if api levels annotations was enabled!") |
| 408 | } |
| 409 | |
Anton Hansson | c04a16e | 2022-05-09 09:30:26 +0000 | [diff] [blame] | 410 | d.apiVersionsXml = android.PathForModuleOut(ctx, "metalava", "api-versions.xml") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 411 | cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 412 | |
| 413 | filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar") |
| 414 | |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 415 | var dirs []string |
Mårten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 416 | var extensions_dir string |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 417 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) { |
| 418 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Mårten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 419 | extRegex := regexp.MustCompile(t.dir.String() + `/extensions/[0-9]+/public/.*\.jar`) |
| 420 | |
| 421 | // Grab the first extensions_dir and we find while scanning ExportedDroiddocDir.deps; |
| 422 | // ideally this should be read from prebuiltApis.properties.Extensions_* |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 423 | for _, dep := range t.deps { |
Mårten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 424 | if extRegex.MatchString(dep.String()) && d.properties.Extensions_info_file != nil { |
| 425 | if extensions_dir == "" { |
| 426 | extensions_dir = t.dir.String() + "/extensions" |
| 427 | } |
| 428 | cmd.Implicit(dep) |
| 429 | } |
Colin Cross | 5f6ffc7 | 2021-03-29 21:54:45 -0700 | [diff] [blame] | 430 | if dep.Base() == filename { |
| 431 | cmd.Implicit(dep) |
| 432 | } |
| 433 | if filename != "android.jar" && dep.Base() == "android.jar" { |
| 434 | // Metalava implicitly searches these patterns: |
| 435 | // prebuilts/tools/common/api-versions/android-%/android.jar |
| 436 | // prebuilts/sdk/%/public/android.jar |
| 437 | // Add android.jar files from the api_levels_annotations_dirs directories to try |
| 438 | // to satisfy these patterns. If Metalava can't find a match for an API level |
| 439 | // between 1 and 28 in at least one pattern it will fail. |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 440 | cmd.Implicit(dep) |
| 441 | } |
| 442 | } |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 443 | |
| 444 | dirs = append(dirs, t.dir.String()) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 445 | } else { |
| 446 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 447 | "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m)) |
| 448 | } |
| 449 | }) |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 450 | |
| 451 | // Add all relevant --android-jar-pattern patterns for Metalava. |
| 452 | // When parsing a stub jar for a specific version, Metalava picks the first pattern that defines |
| 453 | // an actual file present on disk (in the order the patterns were passed). For system APIs for |
| 454 | // privileged apps that are only defined since API level 21 (Lollipop), fallback to public stubs |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 455 | // for older releases. Similarly, module-lib falls back to system API. |
| 456 | var sdkDirs []string |
| 457 | switch proptools.StringDefault(d.properties.Api_levels_sdk_type, "public") { |
Cole Faust | 051fa91 | 2022-10-05 12:45:42 -0700 | [diff] [blame] | 458 | case "system-server": |
| 459 | sdkDirs = []string{"system-server", "module-lib", "system", "public"} |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 460 | case "module-lib": |
| 461 | sdkDirs = []string{"module-lib", "system", "public"} |
| 462 | case "system": |
| 463 | sdkDirs = []string{"system", "public"} |
| 464 | case "public": |
| 465 | sdkDirs = []string{"public"} |
| 466 | default: |
| 467 | ctx.PropertyErrorf("api_levels_sdk_type", "needs to be one of %v", allowedApiLevelSdkTypes) |
| 468 | return |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 469 | } |
Pedro Loureiro | cc20350 | 2021-10-04 17:24:00 +0000 | [diff] [blame] | 470 | |
| 471 | for _, sdkDir := range sdkDirs { |
| 472 | for _, dir := range dirs { |
| 473 | cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/%%/%s/%s", dir, sdkDir, filename)) |
| 474 | } |
satayev | 783195c | 2021-06-23 21:49:57 +0100 | [diff] [blame] | 475 | } |
Mårten Kongstad | 802ae0f | 2022-07-27 13:47:32 +0200 | [diff] [blame] | 476 | |
| 477 | if d.properties.Extensions_info_file != nil { |
| 478 | if extensions_dir == "" { |
| 479 | ctx.ModuleErrorf("extensions_info_file set, but no SDK extension dirs found") |
| 480 | } |
| 481 | info_file := android.PathForModuleSrc(ctx, *d.properties.Extensions_info_file) |
| 482 | cmd.Implicit(info_file) |
| 483 | cmd.FlagWithArg("--sdk-extensions-root ", extensions_dir) |
| 484 | cmd.FlagWithArg("--sdk-extensions-info ", info_file.String()) |
| 485 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 488 | func metalavaUseRbe(ctx android.ModuleContext) bool { |
| 489 | return ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA") |
| 490 | } |
| 491 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 492 | func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths, |
Anton Hansson | 556e814 | 2021-06-04 16:20:25 +0100 | [diff] [blame] | 493 | srcJarList android.Path, bootclasspath, classpath classpath, homeDir android.WritablePath) *android.RuleBuilderCommand { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 494 | rule.Command().Text("rm -rf").Flag(homeDir.String()) |
| 495 | rule.Command().Text("mkdir -p").Flag(homeDir.String()) |
| 496 | |
Anton Hansson | 556e814 | 2021-06-04 16:20:25 +0100 | [diff] [blame] | 497 | cmd := rule.Command() |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 498 | cmd.FlagWithArg("ANDROID_PREFS_ROOT=", homeDir.String()) |
| 499 | |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 500 | if metalavaUseRbe(ctx) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 501 | rule.Remoteable(android.RemoteRuleSupports{RBE: true}) |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 502 | execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
Anas Sulaiman | 9c49364 | 2023-10-18 16:34:37 +0000 | [diff] [blame] | 503 | compare, _ := strconv.ParseBool(ctx.Config().GetenvWithDefault("RBE_METALAVA_COMPARE", "false")) |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 504 | labels := map[string]string{"type": "tool", "name": "metalava"} |
| 505 | // TODO: metalava pool rejects these jobs |
| 506 | pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "java16") |
| 507 | rule.Rewrapper(&remoteexec.REParams{ |
| 508 | Labels: labels, |
| 509 | ExecStrategy: execStrategy, |
| 510 | ToolchainInputs: []string{config.JavaCmd(ctx).String()}, |
| 511 | Platform: map[string]string{remoteexec.PoolKey: pool}, |
Anas Sulaiman | 9c49364 | 2023-10-18 16:34:37 +0000 | [diff] [blame] | 512 | Compare: compare, |
| 513 | NumLocalRuns: 1, |
| 514 | NumRemoteRuns: 1, |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 515 | }) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Colin Cross | 6aa5c40 | 2021-03-24 12:28:50 -0700 | [diff] [blame] | 518 | cmd.BuiltTool("metalava").ImplicitTool(ctx.Config().HostJavaToolPath(ctx, "metalava.jar")). |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 519 | Flag(config.JavacVmFlags). |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 520 | Flag(config.MetalavaAddOpens). |
Paul Duffin | 808211e | 2023-08-09 12:36:08 +0100 | [diff] [blame] | 521 | FlagWithArg("--java-source ", javaVersion.String()). |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 522 | FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "metalava.rsp"), srcs). |
| 523 | FlagWithInput("@", srcJarList) |
| 524 | |
Paul Duffin | f8aaaa1 | 2023-08-10 15:16:35 +0100 | [diff] [blame] | 525 | // Metalava does not differentiate between bootclasspath and classpath and has not done so for |
| 526 | // years, so it is unlikely to change any time soon. |
| 527 | combinedPaths := append(([]android.Path)(nil), bootclasspath.Paths()...) |
| 528 | combinedPaths = append(combinedPaths, classpath.Paths()...) |
| 529 | if len(combinedPaths) > 0 { |
| 530 | cmd.FlagWithInputList("--classpath ", combinedPaths, ":") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 533 | cmd.Flag(config.MetalavaFlags) |
Jihoon Kang | c831389 | 2023-09-20 00:54:47 +0000 | [diff] [blame] | 534 | if ctx.DeviceConfig().HideFlaggedApis() { |
Liz Kammer | e09e20e | 2023-10-16 15:07:54 -0400 | [diff] [blame] | 535 | cmd.Flag(config.MetalavaHideFlaggedApis) |
Jihoon Kang | c831389 | 2023-09-20 00:54:47 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 538 | return cmd |
| 539 | } |
| 540 | |
| 541 | func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 542 | deps := d.Javadoc.collectDeps(ctx) |
| 543 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 544 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), android.SdkContext(d)) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 545 | |
| 546 | // Create rule for metalava |
| 547 | |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 548 | srcJarDir := android.PathForModuleOut(ctx, "metalava", "srcjars") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 549 | |
| 550 | rule := android.NewRuleBuilder(pctx, ctx) |
| 551 | |
Colin Cross | 8095c29 | 2021-03-30 16:40:48 -0700 | [diff] [blame] | 552 | rule.Sbox(android.PathForModuleOut(ctx, "metalava"), |
| 553 | android.PathForModuleOut(ctx, "metalava.sbox.textproto")). |
| 554 | SandboxInputs() |
Colin Cross | 6aa5c40 | 2021-03-24 12:28:50 -0700 | [diff] [blame] | 555 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 556 | if BoolDefault(d.properties.High_mem, false) { |
| 557 | // This metalava run uses lots of memory, restrict the number of metalava jobs that can run in parallel. |
| 558 | rule.HighMem() |
| 559 | } |
| 560 | |
| 561 | generateStubs := BoolDefault(d.properties.Generate_stubs, true) |
| 562 | var stubsDir android.OptionalPath |
| 563 | if generateStubs { |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 564 | d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-"+"stubs.srcjar") |
| 565 | stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "metalava", "stubsDir")) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 566 | rule.Command().Text("rm -rf").Text(stubsDir.String()) |
| 567 | rule.Command().Text("mkdir -p").Text(stubsDir.String()) |
| 568 | } |
| 569 | |
| 570 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) |
| 571 | |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 572 | homeDir := android.PathForModuleOut(ctx, "metalava", "home") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 573 | cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList, |
Anton Hansson | 556e814 | 2021-06-04 16:20:25 +0100 | [diff] [blame] | 574 | deps.bootClasspath, deps.classpath, homeDir) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 575 | cmd.Implicits(d.Javadoc.implicits) |
| 576 | |
| 577 | d.stubsFlags(ctx, cmd, stubsDir) |
| 578 | |
| 579 | d.annotationsFlags(ctx, cmd) |
| 580 | d.inclusionAnnotationsFlags(ctx, cmd) |
| 581 | d.apiLevelsAnnotationsFlags(ctx, cmd) |
| 582 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 583 | d.expandArgs(ctx, cmd) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 584 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 585 | for _, o := range d.Javadoc.properties.Out { |
| 586 | cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) |
| 587 | } |
| 588 | |
| 589 | // Add options for the other optional tasks: API-lint and check-released. |
| 590 | // We generate separate timestamp files for them. |
| 591 | |
| 592 | doApiLint := false |
| 593 | doCheckReleased := false |
| 594 | |
| 595 | // Add API lint options. |
| 596 | |
| 597 | if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) { |
| 598 | doApiLint = true |
| 599 | |
| 600 | newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since) |
| 601 | if newSince.Valid() { |
| 602 | cmd.FlagWithInput("--api-lint ", newSince.Path()) |
| 603 | } else { |
| 604 | cmd.Flag("--api-lint") |
| 605 | } |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 606 | d.apiLintReport = android.PathForModuleOut(ctx, "metalava", "api_lint_report.txt") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 607 | cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint" |
| 608 | |
Colin Cross | 0d53241 | 2021-03-25 09:38:45 -0700 | [diff] [blame] | 609 | // 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] | 610 | if d.Name() != "android.car-system-stubs-docs" && |
| 611 | d.Name() != "android.car-stubs-docs" { |
| 612 | cmd.Flag("--lints-as-errors") |
| 613 | cmd.Flag("--warnings-as-errors") // Most lints are actually warnings. |
| 614 | } |
| 615 | |
| 616 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file) |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 617 | updatedBaselineOutput := android.PathForModuleOut(ctx, "metalava", "api_lint_baseline.txt") |
| 618 | d.apiLintTimestamp = android.PathForModuleOut(ctx, "metalava", "api_lint.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 619 | |
| 620 | // 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] | 621 | // |
| 622 | // TODO: metalava also has a slightly different message hardcoded. Should we unify this |
| 623 | // message and metalava's one? |
| 624 | msg := `$'` + // Enclose with $' ... ' |
| 625 | `************************************************************\n` + |
| 626 | `Your API changes are triggering API Lint warnings or errors.\n` + |
| 627 | `To make these errors go away, fix the code according to the\n` + |
| 628 | `error and/or warning messages above.\n` + |
| 629 | `\n` + |
| 630 | `If it is not possible to do so, there are workarounds:\n` + |
| 631 | `\n` + |
Aurimas Liutikas | b23b745 | 2021-05-24 18:00:37 +0000 | [diff] [blame] | 632 | `1. You can suppress the errors with @SuppressLint("<id>")\n` + |
| 633 | ` 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] | 634 | |
| 635 | if baselineFile.Valid() { |
| 636 | cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path()) |
| 637 | cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput) |
| 638 | |
| 639 | msg += fmt.Sprintf(``+ |
| 640 | `2. You can update the baseline by executing the following\n`+ |
| 641 | ` command:\n`+ |
Colin Cross | 63eeda0 | 2021-04-15 19:01:57 -0700 | [diff] [blame] | 642 | ` (cd $ANDROID_BUILD_TOP && cp \\\n`+ |
| 643 | ` "%s" \\\n`+ |
| 644 | ` "%s")\n`+ |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 645 | ` To submit the revised baseline.txt to the main Android\n`+ |
| 646 | ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path()) |
| 647 | } else { |
| 648 | msg += fmt.Sprintf(``+ |
| 649 | `2. You can add a baseline file of existing lint failures\n`+ |
| 650 | ` to the build rule of %s.\n`, d.Name()) |
| 651 | } |
| 652 | // Note the message ends with a ' (single quote), to close the $' ... ' . |
| 653 | msg += `************************************************************\n'` |
| 654 | |
| 655 | cmd.FlagWithArg("--error-message:api-lint ", msg) |
| 656 | } |
| 657 | |
| 658 | // Add "check released" options. (Detect incompatible API changes from the last public release) |
| 659 | |
| 660 | if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") { |
| 661 | doCheckReleased = true |
| 662 | |
| 663 | if len(d.Javadoc.properties.Out) > 0 { |
| 664 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 665 | } |
| 666 | |
| 667 | apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file)) |
| 668 | removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file)) |
| 669 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file) |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 670 | updatedBaselineOutput := android.PathForModuleOut(ctx, "metalava", "last_released_baseline.txt") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 671 | |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 672 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_last_released_api.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 673 | |
| 674 | cmd.FlagWithInput("--check-compatibility:api:released ", apiFile) |
| 675 | cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile) |
| 676 | |
| 677 | if baselineFile.Valid() { |
| 678 | cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path()) |
| 679 | cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput) |
| 680 | } |
| 681 | |
| 682 | // Note this string includes quote ($' ... '), which decodes the "\n"s. |
| 683 | msg := `$'\n******************************\n` + |
| 684 | `You have tried to change the API from what has been previously released in\n` + |
| 685 | `an SDK. Please fix the errors listed above.\n` + |
| 686 | `******************************\n'` |
| 687 | |
| 688 | cmd.FlagWithArg("--error-message:compatibility:released ", msg) |
| 689 | } |
| 690 | |
Paul Duffin | 10a23c2 | 2023-08-11 22:47:31 +0100 | [diff] [blame] | 691 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { |
| 692 | // Pass the current API file into metalava so it can use it as the basis for determining how to |
| 693 | // generate the output signature files (both api and removed). |
| 694 | currentApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) |
| 695 | cmd.FlagWithInput("--use-same-format-as ", currentApiFile) |
| 696 | } |
| 697 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 698 | if generateStubs { |
| 699 | rule.Command(). |
| 700 | BuiltTool("soong_zip"). |
| 701 | Flag("-write_if_changed"). |
| 702 | Flag("-jar"). |
| 703 | FlagWithOutput("-o ", d.Javadoc.stubsSrcJar). |
| 704 | FlagWithArg("-C ", stubsDir.String()). |
| 705 | FlagWithArg("-D ", stubsDir.String()) |
| 706 | } |
| 707 | |
| 708 | if Bool(d.properties.Write_sdk_values) { |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 709 | d.metadataZip = android.PathForModuleOut(ctx, "metalava", ctx.ModuleName()+"-metadata.zip") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 710 | rule.Command(). |
| 711 | BuiltTool("soong_zip"). |
| 712 | Flag("-write_if_changed"). |
| 713 | Flag("-d"). |
| 714 | FlagWithOutput("-o ", d.metadataZip). |
| 715 | FlagWithArg("-C ", d.metadataDir.String()). |
| 716 | FlagWithArg("-D ", d.metadataDir.String()) |
| 717 | } |
| 718 | |
| 719 | // TODO: We don't really need two separate API files, but this is a reminiscence of how |
| 720 | // we used to run metalava separately for API lint and the "last_released" check. Unify them. |
| 721 | if doApiLint { |
| 722 | rule.Command().Text("touch").Output(d.apiLintTimestamp) |
| 723 | } |
| 724 | if doCheckReleased { |
| 725 | rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp) |
| 726 | } |
| 727 | |
Colin Cross | 6aa5c40 | 2021-03-24 12:28:50 -0700 | [diff] [blame] | 728 | // TODO(b/183630617): rewrapper doesn't support restat rules |
Colin Cross | e52c2ac | 2022-03-28 17:03:35 -0700 | [diff] [blame] | 729 | if !metalavaUseRbe(ctx) { |
| 730 | rule.Restat() |
| 731 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 732 | |
| 733 | zipSyncCleanupCmd(rule, srcJarDir) |
| 734 | |
Paul Duffin | c166b68 | 2022-05-27 12:23:08 +0000 | [diff] [blame] | 735 | rule.Build("metalava", "metalava merged") |
| 736 | |
Paul Duffin | e7a8664 | 2022-08-16 15:43:20 +0000 | [diff] [blame] | 737 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { |
| 738 | |
| 739 | if len(d.Javadoc.properties.Out) > 0 { |
| 740 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 741 | } |
| 742 | |
| 743 | apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) |
| 744 | removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) |
| 745 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) |
| 746 | |
| 747 | if baselineFile.Valid() { |
| 748 | ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) |
| 749 | } |
| 750 | |
| 751 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "check_current_api.timestamp") |
| 752 | |
| 753 | rule := android.NewRuleBuilder(pctx, ctx) |
| 754 | |
| 755 | // Diff command line. |
| 756 | // -F matches the closest "opening" line, such as "package android {" |
| 757 | // and " public class Intent {". |
| 758 | diff := `diff -u -F '{ *$'` |
| 759 | |
| 760 | rule.Command().Text("( true") |
| 761 | rule.Command(). |
| 762 | Text(diff). |
| 763 | Input(apiFile).Input(d.apiFile) |
| 764 | |
| 765 | rule.Command(). |
| 766 | Text(diff). |
| 767 | Input(removedApiFile).Input(d.removedApiFile) |
| 768 | |
| 769 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 770 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 771 | `To make these errors go away, you have two choices:\n`+ |
| 772 | ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ |
| 773 | ` to the new methods, etc. shown in the above diff.\n\n`+ |
| 774 | ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ |
| 775 | ` m %s-update-current-api\n\n`+ |
| 776 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 777 | ` you will need approval.\n`+ |
| 778 | `******************************\n`, ctx.ModuleName()) |
| 779 | |
| 780 | rule.Command(). |
| 781 | Text("touch").Output(d.checkCurrentApiTimestamp). |
| 782 | Text(") || ("). |
| 783 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 784 | Text("; exit 38"). |
| 785 | Text(")") |
| 786 | |
| 787 | rule.Build("metalavaCurrentApiCheck", "check current API") |
| 788 | |
| 789 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "metalava", "update_current_api.timestamp") |
| 790 | |
| 791 | // update API rule |
| 792 | rule = android.NewRuleBuilder(pctx, ctx) |
| 793 | |
| 794 | rule.Command().Text("( true") |
| 795 | |
| 796 | rule.Command(). |
| 797 | Text("cp").Flag("-f"). |
| 798 | Input(d.apiFile).Flag(apiFile.String()) |
| 799 | |
| 800 | rule.Command(). |
| 801 | Text("cp").Flag("-f"). |
| 802 | Input(d.removedApiFile).Flag(removedApiFile.String()) |
| 803 | |
| 804 | msg = "failed to update public API" |
| 805 | |
| 806 | rule.Command(). |
| 807 | Text("touch").Output(d.updateCurrentApiTimestamp). |
| 808 | Text(") || ("). |
| 809 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 810 | Text("; exit 38"). |
| 811 | Text(")") |
| 812 | |
| 813 | rule.Build("metalavaCurrentApiUpdate", "update current API") |
| 814 | } |
| 815 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 816 | if String(d.properties.Check_nullability_warnings) != "" { |
| 817 | if d.nullabilityWarningsFile == nil { |
| 818 | ctx.PropertyErrorf("check_nullability_warnings", |
| 819 | "Cannot specify check_nullability_warnings unless validating nullability") |
| 820 | } |
| 821 | |
| 822 | checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings)) |
| 823 | |
Colin Cross | cb77f75 | 2021-03-24 12:04:44 -0700 | [diff] [blame] | 824 | d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "metalava", "check_nullability_warnings.timestamp") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 825 | |
| 826 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 827 | `The warnings encountered during nullability annotation validation did\n`+ |
| 828 | `not match the checked in file of expected warnings. The diffs are shown\n`+ |
| 829 | `above. You have two options:\n`+ |
| 830 | ` 1. Resolve the differences by editing the nullability annotations.\n`+ |
| 831 | ` 2. Update the file of expected warnings by running:\n`+ |
| 832 | ` cp %s %s\n`+ |
| 833 | ` and submitting the updated file as part of your change.`, |
| 834 | d.nullabilityWarningsFile, checkNullabilityWarnings) |
| 835 | |
| 836 | rule := android.NewRuleBuilder(pctx, ctx) |
| 837 | |
| 838 | rule.Command(). |
| 839 | Text("("). |
| 840 | Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile). |
| 841 | Text("&&"). |
| 842 | Text("touch").Output(d.checkNullabilityWarningsTimestamp). |
| 843 | Text(") || ("). |
| 844 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 845 | Text("; exit 38"). |
| 846 | Text(")") |
| 847 | |
| 848 | rule.Build("nullabilityWarningsCheck", "nullability warnings check") |
| 849 | } |
| 850 | } |
| 851 | |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 852 | func (d *Droidstubs) createApiContribution(ctx android.DefaultableHookContext) { |
| 853 | api_file := d.properties.Check_api.Current.Api_file |
| 854 | api_surface := d.properties.Api_surface |
| 855 | |
| 856 | props := struct { |
| 857 | Name *string |
| 858 | Api_surface *string |
| 859 | Api_file *string |
Jihoon Kang | 42b589c | 2023-02-03 22:56:13 +0000 | [diff] [blame] | 860 | Visibility []string |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 861 | }{} |
| 862 | |
| 863 | props.Name = proptools.StringPtr(d.Name() + ".api.contribution") |
| 864 | props.Api_surface = api_surface |
| 865 | props.Api_file = api_file |
Jihoon Kang | 42b589c | 2023-02-03 22:56:13 +0000 | [diff] [blame] | 866 | props.Visibility = []string{"//visibility:override", "//visibility:public"} |
Jihoon Kang | 3198f3c | 2023-01-26 08:08:52 +0000 | [diff] [blame] | 867 | |
| 868 | ctx.CreateModule(ApiContributionFactory, &props) |
| 869 | } |
| 870 | |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 871 | // TODO (b/262014796): Export the API contributions of CorePlatformApi |
| 872 | // A map to populate the api surface of a droidstub from a substring appearing in its name |
| 873 | // This map assumes that droidstubs (either checked-in or created by java_sdk_library) |
| 874 | // use a strict naming convention |
| 875 | var ( |
| 876 | droidstubsModuleNamingToSdkKind = map[string]android.SdkKind{ |
| 877 | //public is commented out since the core libraries use public in their java_sdk_library names |
| 878 | "intracore": android.SdkIntraCore, |
| 879 | "intra.core": android.SdkIntraCore, |
| 880 | "system_server": android.SdkSystemServer, |
| 881 | "system-server": android.SdkSystemServer, |
| 882 | "system": android.SdkSystem, |
| 883 | "module_lib": android.SdkModule, |
| 884 | "module-lib": android.SdkModule, |
Spandan Das | da97755 | 2023-01-26 20:45:16 +0000 | [diff] [blame] | 885 | "platform.api": android.SdkCorePlatform, |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 886 | "test": android.SdkTest, |
Spandan Das | 4ac2aed | 2022-12-28 01:54:29 +0000 | [diff] [blame] | 887 | "toolchain": android.SdkToolchain, |
Spandan Das | 0b555e3 | 2022-11-28 18:48:51 +0000 | [diff] [blame] | 888 | } |
| 889 | ) |
| 890 | |
| 891 | // A helper function that returns the api surface of the corresponding java_api_contribution Bazel target |
| 892 | // The api_surface is populated using the naming convention of the droidstubs module. |
| 893 | func bazelApiSurfaceName(name string) string { |
| 894 | // Sort the keys so that longer strings appear first |
| 895 | // Otherwise substrings like system will match both system and system_server |
| 896 | sortedKeys := make([]string, 0) |
| 897 | for key := range droidstubsModuleNamingToSdkKind { |
| 898 | sortedKeys = append(sortedKeys, key) |
| 899 | } |
| 900 | sort.Slice(sortedKeys, func(i, j int) bool { |
| 901 | return len(sortedKeys[i]) > len(sortedKeys[j]) |
| 902 | }) |
| 903 | for _, sortedKey := range sortedKeys { |
| 904 | if strings.Contains(name, sortedKey) { |
| 905 | sdkKind := droidstubsModuleNamingToSdkKind[sortedKey] |
| 906 | return sdkKind.String() + "api" |
| 907 | } |
| 908 | } |
| 909 | // Default is publicapi |
| 910 | return android.SdkPublic.String() + "api" |
| 911 | } |
| 912 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 913 | func StubsDefaultsFactory() android.Module { |
| 914 | module := &DocDefaults{} |
| 915 | |
| 916 | module.AddProperties( |
| 917 | &JavadocProperties{}, |
| 918 | &DroidstubsProperties{}, |
| 919 | ) |
| 920 | |
| 921 | android.InitDefaultsModule(module) |
| 922 | |
| 923 | return module |
| 924 | } |
| 925 | |
| 926 | var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil) |
| 927 | |
| 928 | type PrebuiltStubsSourcesProperties struct { |
| 929 | Srcs []string `android:"path"` |
| 930 | } |
| 931 | |
| 932 | type PrebuiltStubsSources struct { |
| 933 | android.ModuleBase |
| 934 | android.DefaultableModuleBase |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame^] | 935 | embeddableInModuleAndImport |
| 936 | |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 937 | prebuilt android.Prebuilt |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 938 | |
| 939 | properties PrebuiltStubsSourcesProperties |
| 940 | |
kgui | 6700724 | 2022-01-25 13:50:25 +0800 | [diff] [blame] | 941 | stubsSrcJar android.Path |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) { |
| 945 | switch tag { |
| 946 | case "": |
| 947 | return android.Paths{p.stubsSrcJar}, nil |
| 948 | default: |
| 949 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | func (d *PrebuiltStubsSources) StubsSrcJar() android.Path { |
| 954 | return d.stubsSrcJar |
| 955 | } |
| 956 | |
| 957 | func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 958 | if len(p.properties.Srcs) != 1 { |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 959 | 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] | 960 | return |
| 961 | } |
| 962 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 963 | src := p.properties.Srcs[0] |
| 964 | if filepath.Ext(src) == ".srcjar" { |
| 965 | // This is a srcjar. We can use it directly. |
| 966 | p.stubsSrcJar = android.PathForModuleSrc(ctx, src) |
| 967 | } else { |
| 968 | outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 969 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 970 | // This is a directory. Glob the contents just in case the directory does not exist. |
| 971 | srcGlob := src + "/**/*" |
| 972 | srcPaths := android.PathsForModuleSrc(ctx, []string{srcGlob}) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 973 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 974 | // Although PathForModuleSrc can return nil if either the path doesn't exist or |
| 975 | // the path components are invalid it won't in this case because no components |
| 976 | // are specified and the module directory must exist in order to get this far. |
| 977 | srcDir := android.PathForModuleSrc(ctx).(android.SourcePath).Join(ctx, src) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 978 | |
Anton Hansson | 86758ac | 2021-11-03 14:44:12 +0000 | [diff] [blame] | 979 | rule := android.NewRuleBuilder(pctx, ctx) |
| 980 | rule.Command(). |
| 981 | BuiltTool("soong_zip"). |
| 982 | Flag("-write_if_changed"). |
| 983 | Flag("-jar"). |
| 984 | FlagWithOutput("-o ", outPath). |
| 985 | FlagWithArg("-C ", srcDir.String()). |
| 986 | FlagWithRspFileInputList("-r ", outPath.ReplaceExtension(ctx, "rsp"), srcPaths) |
| 987 | rule.Restat() |
| 988 | rule.Build("zip src", "Create srcjar from prebuilt source") |
| 989 | p.stubsSrcJar = outPath |
| 990 | } |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt { |
| 994 | return &p.prebuilt |
| 995 | } |
| 996 | |
| 997 | func (p *PrebuiltStubsSources) Name() string { |
| 998 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 999 | } |
| 1000 | |
| 1001 | // prebuilt_stubs_sources imports a set of java source files as if they were |
| 1002 | // generated by droidstubs. |
| 1003 | // |
| 1004 | // By default, a prebuilt_stubs_sources has a single variant that expects a |
| 1005 | // set of `.java` files generated by droidstubs. |
| 1006 | // |
| 1007 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1008 | // for host modules. |
| 1009 | // |
| 1010 | // Intended only for use by sdk snapshots. |
| 1011 | func PrebuiltStubsSourcesFactory() android.Module { |
| 1012 | module := &PrebuiltStubsSources{} |
| 1013 | |
| 1014 | module.AddProperties(&module.properties) |
Spandan Das | 2cc80ba | 2023-10-27 17:21:52 +0000 | [diff] [blame^] | 1015 | module.initModuleAndImport(module) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1016 | |
| 1017 | android.InitPrebuiltModule(module, &module.properties.Srcs) |
Colin Cross | 2207f87 | 2021-03-24 12:39:08 -0700 | [diff] [blame] | 1018 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 1019 | return module |
| 1020 | } |