Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 18 | "fmt" |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 19 | "path/filepath" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 20 | "strings" |
| 21 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 22 | "github.com/google/blueprint" |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 24 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 25 | "android/soong/android" |
| 26 | "android/soong/java/config" |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 27 | "android/soong/remoteexec" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | func init() { |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 31 | RegisterDocsBuildComponents(android.InitRegistrationContext) |
| 32 | RegisterStubsBuildComponents(android.InitRegistrationContext) |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 33 | |
| 34 | // Register sdk member type. |
| 35 | android.RegisterSdkMemberType(&droidStubsSdkMemberType{ |
| 36 | SdkMemberTypeBase: android.SdkMemberTypeBase{ |
| 37 | PropertyName: "stubs_sources", |
Paul Duffin | e602918 | 2019-12-16 17:43:48 +0000 | [diff] [blame] | 38 | // stubs_sources can be used with sdk to provide the source stubs for APIs provided by |
| 39 | // the APEX. |
| 40 | SupportsSdk: true, |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 41 | }, |
| 42 | }) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 45 | func RegisterDocsBuildComponents(ctx android.RegistrationContext) { |
| 46 | ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 47 | |
| 48 | ctx.RegisterModuleType("droiddoc", DroiddocFactory) |
| 49 | ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
| 50 | ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory) |
| 51 | ctx.RegisterModuleType("javadoc", JavadocFactory) |
| 52 | ctx.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 53 | } |
| 54 | |
| 55 | func RegisterStubsBuildComponents(ctx android.RegistrationContext) { |
| 56 | ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory) |
| 57 | |
| 58 | ctx.RegisterModuleType("droidstubs", DroidstubsFactory) |
| 59 | ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) |
| 60 | |
| 61 | ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory) |
| 62 | } |
| 63 | |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 64 | var ( |
| 65 | srcsLibTag = dependencyTag{name: "sources from javalib"} |
| 66 | ) |
| 67 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 68 | type JavadocProperties struct { |
| 69 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 70 | // or .aidl files. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 71 | Srcs []string `android:"path,arch_variant"` |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 72 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 73 | // list of source files that should not be used to build the Java module. |
| 74 | // This is most useful in the arch/multilib variants to remove non-common files |
| 75 | // filegroup or genrule can be included within this property. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 76 | Exclude_srcs []string `android:"path,arch_variant"` |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 77 | |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 78 | // list of package names that should actually be used. If this property is left unspecified, |
| 79 | // all the sources from the srcs property is used. |
| 80 | Filter_packages []string |
| 81 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 82 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 83 | Libs []string `android:"arch_variant"` |
| 84 | |
| 85 | // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 86 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 87 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 88 | // if not blank, set to the version of the sdk to compile against. |
| 89 | // Defaults to compiling against the current platform. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 90 | Sdk_version *string `android:"arch_variant"` |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 91 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 92 | // When targeting 1.9 and above, override the modules to use with --system, |
| 93 | // otherwise provides defaults libraries to add to the bootclasspath. |
| 94 | // Defaults to "none" |
| 95 | System_modules *string |
| 96 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 97 | Aidl struct { |
| 98 | // Top level directories to pass to aidl tool |
| 99 | Include_dirs []string |
| 100 | |
| 101 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 102 | Local_include_dirs []string |
| 103 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 104 | |
| 105 | // If not blank, set the java version passed to javadoc as -source |
| 106 | Java_version *string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 107 | |
| 108 | // local files that are used within user customized droiddoc options. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 109 | Arg_files []string `android:"path"` |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 110 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 111 | // user customized droiddoc args. Deprecated, use flags instead. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 112 | // Available variables for substitution: |
| 113 | // |
| 114 | // $(location <label>): the path to the arg_files with name <label> |
Colin Cross | e4a0584 | 2019-05-28 10:17:14 -0700 | [diff] [blame] | 115 | // $$: a literal $ |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 116 | Args *string |
| 117 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 118 | // user customized droiddoc args. Not compatible with property args. |
| 119 | // Available variables for substitution: |
| 120 | // |
| 121 | // $(location <label>): the path to the arg_files with name <label> |
| 122 | // $$: a literal $ |
| 123 | Flags []string |
| 124 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 125 | // names of the output files used in args that will be generated |
| 126 | Out []string |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 127 | |
| 128 | // If set, metalava is sandboxed to only read files explicitly specified on the command |
| 129 | // line. Defaults to false. |
| 130 | Sandbox *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 133 | type ApiToCheck struct { |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 134 | // path to the API txt file that the new API extracted from source code is checked |
| 135 | // against. The path can be local to the module or from other module (via :module syntax). |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 136 | Api_file *string `android:"path"` |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 137 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 138 | // path to the API txt file that the new @removed API extractd from source code is |
| 139 | // checked against. The path can be local to the module or from other module (via |
| 140 | // :module syntax). |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 141 | Removed_api_file *string `android:"path"` |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 142 | |
Adrian Roos | 14f75a9 | 2019-08-12 17:54:09 +0200 | [diff] [blame] | 143 | // If not blank, path to the baseline txt file for approved API check violations. |
| 144 | Baseline_file *string `android:"path"` |
| 145 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 146 | // Arguments to the apicheck tool. |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 147 | Args *string |
| 148 | } |
| 149 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 150 | type DroiddocProperties struct { |
| 151 | // directory relative to top of the source tree that contains doc templates files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 152 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 153 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 154 | // directories under current module source which contains html/jd files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 155 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 156 | |
| 157 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 158 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 159 | |
| 160 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 161 | // suitable for spell-checking and other goodness. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 162 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 163 | |
| 164 | // a todo file lists the program elements that are missing documentation. |
| 165 | // At some point, this might be improved to show more warnings. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 166 | Todo_file *string `android:"path"` |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 167 | |
| 168 | // directory under current module source that provide additional resources (images). |
| 169 | Resourcesdir *string |
| 170 | |
| 171 | // resources output directory under out/soong/.intermediates. |
| 172 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 173 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 174 | // index.html under current module will be copied to docs out dir, if not null. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 175 | Static_doc_index_redirect *string `android:"path"` |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 176 | |
| 177 | // source.properties under current module will be copied to docs out dir, if not null. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 178 | Static_doc_properties *string `android:"path"` |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 179 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 180 | // a list of files under current module source dir which contains known tags in Java sources. |
| 181 | // filegroup or genrule can be included within this property. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 182 | Knowntags []string `android:"path"` |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 183 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 184 | // if set to true, generate docs through Dokka instead of Doclava. |
| 185 | Dokka_enabled *bool |
Mathew Inwood | abd49ab | 2019-12-19 14:27:08 +0000 | [diff] [blame] | 186 | |
| 187 | // Compat config XML. Generates compat change documentation if set. |
| 188 | Compat_config *string `android:"path"` |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | type DroidstubsProperties struct { |
Liz Kammer | 9ed7915 | 2020-08-24 15:56:32 -0700 | [diff] [blame^] | 192 | // The generated public API filename by Metalava, defaults to <module>_api.txt |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 193 | Api_filename *string |
| 194 | |
Liz Kammer | 9ed7915 | 2020-08-24 15:56:32 -0700 | [diff] [blame^] | 195 | // the generated removed API filename by Metalava, defaults to <module>_removed.txt |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 196 | Removed_api_filename *string |
| 197 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 198 | // the generated removed Dex API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 199 | Removed_dex_api_filename *string |
| 200 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 201 | Check_api struct { |
| 202 | Last_released ApiToCheck |
| 203 | |
| 204 | Current ApiToCheck |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 205 | |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 206 | // The java_sdk_library module generates references to modules (i.e. filegroups) |
| 207 | // from which information about the latest API version can be obtained. As those |
| 208 | // modules may not exist (e.g. because a previous version has not been released) it |
| 209 | // sets ignore_missing_latest_api=true on the droidstubs modules it creates so |
| 210 | // that droidstubs can ignore those references if the modules do not yet exist. |
| 211 | // |
| 212 | // If true then this will ignore module references for modules that do not exist |
| 213 | // in properties that supply the previous version of the API. |
| 214 | // |
| 215 | // There are two sets of those: |
| 216 | // * Api_file, Removed_api_file in check_api.last_released |
| 217 | // * New_since in check_api.api_lint.new_since |
| 218 | // |
| 219 | // The first two must be set as a pair, so either they should both exist or neither |
| 220 | // should exist - in which case when this property is true they are ignored. If one |
| 221 | // exists and the other does not then it is an error. |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 222 | Ignore_missing_latest_api *bool `blueprint:"mutated"` |
Adrian Roos | 075eedc | 2019-10-10 12:07:03 +0200 | [diff] [blame] | 223 | |
| 224 | Api_lint struct { |
| 225 | Enabled *bool |
| 226 | |
| 227 | // If set, performs api_lint on any new APIs not found in the given signature file |
| 228 | New_since *string `android:"path"` |
| 229 | |
| 230 | // If not blank, path to the baseline txt file for approved API lint violations. |
| 231 | Baseline_file *string `android:"path"` |
| 232 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 233 | } |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 234 | |
| 235 | // user can specify the version of previous released API file in order to do compatibility check. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 236 | Previous_api *string `android:"path"` |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 237 | |
| 238 | // is set to true, Metalava will allow framework SDK to contain annotations. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 239 | Annotations_enabled *bool |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 240 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 241 | // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 242 | Merge_annotations_dirs []string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 243 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 244 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 245 | Merge_inclusion_annotations_dirs []string |
| 246 | |
Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 247 | // a file containing a list of classes to do nullability validation for. |
| 248 | Validate_nullability_from_list *string |
| 249 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 250 | // a file containing expected warnings produced by validation of nullability annotations. |
| 251 | Check_nullability_warnings *string |
| 252 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 253 | // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. |
| 254 | Create_doc_stubs *bool |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 255 | |
Paul Duffin | 3ae2951 | 2020-04-08 18:18:03 +0100 | [diff] [blame] | 256 | // if set to false then do not write out stubs. Defaults to true. |
| 257 | // |
| 258 | // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately. |
| 259 | Generate_stubs *bool |
| 260 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 261 | // is set to true, Metalava will allow framework SDK to contain API levels annotations. |
| 262 | Api_levels_annotations_enabled *bool |
| 263 | |
| 264 | // the dirs which Metalava extracts API levels annotations from. |
| 265 | Api_levels_annotations_dirs []string |
| 266 | |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 267 | // the filename which Metalava extracts API levels annotations from. Defaults to android.jar. |
| 268 | Api_levels_jar_filename *string |
| 269 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 270 | // if set to true, collect the values used by the Dev tools and |
| 271 | // write them in files packaged with the SDK. Defaults to false. |
| 272 | Write_sdk_values *bool |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 273 | |
| 274 | // If set to true, .xml based public API file will be also generated, and |
| 275 | // JDiff tool will be invoked to genreate javadoc files. Defaults to false. |
| 276 | Jdiff_enabled *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 279 | // |
| 280 | // Common flags passed down to build rule |
| 281 | // |
| 282 | type droiddocBuilderFlags struct { |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 283 | bootClasspathArgs string |
| 284 | classpathArgs string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 285 | sourcepathArgs string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 286 | dokkaClasspathArgs string |
| 287 | aidlFlags string |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 288 | aidlDeps android.Paths |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 289 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 290 | doclavaStubsFlags string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 291 | doclavaDocsFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 292 | postDoclavaCmds string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 296 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 297 | android.InitDefaultableModule(module) |
| 298 | } |
| 299 | |
Luca Stefani | d63ea0a | 2019-09-01 21:49:45 +0200 | [diff] [blame] | 300 | func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool { |
| 301 | if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") { |
| 302 | return false |
| 303 | } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 304 | return true |
| 305 | } else if String(apiToCheck.Api_file) != "" { |
| 306 | panic("for " + apiVersionTag + " removed_api_file has to be non-empty!") |
| 307 | } else if String(apiToCheck.Removed_api_file) != "" { |
| 308 | panic("for " + apiVersionTag + " api_file has to be non-empty!") |
| 309 | } |
| 310 | |
| 311 | return false |
| 312 | } |
| 313 | |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 314 | func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) { |
| 315 | api_file := String(apiToCheck.Api_file) |
| 316 | removed_api_file := String(apiToCheck.Removed_api_file) |
| 317 | |
| 318 | api_module := android.SrcIsModule(api_file) |
| 319 | removed_api_module := android.SrcIsModule(removed_api_file) |
| 320 | |
| 321 | if api_module == "" || removed_api_module == "" { |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) { |
| 326 | return |
| 327 | } |
| 328 | |
| 329 | apiToCheck.Api_file = nil |
| 330 | apiToCheck.Removed_api_file = nil |
| 331 | } |
| 332 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 333 | // Used by xsd_config |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 334 | type ApiFilePath interface { |
| 335 | ApiFilePath() android.Path |
| 336 | } |
| 337 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 338 | type ApiStubsSrcProvider interface { |
| 339 | StubsSrcJar() android.Path |
| 340 | } |
| 341 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 342 | // Provider of information about API stubs, used by java_sdk_library. |
| 343 | type ApiStubsProvider interface { |
| 344 | ApiFilePath |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 345 | RemovedApiFilePath() android.Path |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 346 | |
| 347 | ApiStubsSrcProvider |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 350 | // |
| 351 | // Javadoc |
| 352 | // |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 353 | type Javadoc struct { |
| 354 | android.ModuleBase |
| 355 | android.DefaultableModuleBase |
| 356 | |
| 357 | properties JavadocProperties |
| 358 | |
| 359 | srcJars android.Paths |
| 360 | srcFiles android.Paths |
| 361 | sourcepaths android.Paths |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 362 | argFiles android.Paths |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 363 | implicits android.Paths |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 364 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 365 | args []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 366 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 367 | docZip android.WritablePath |
| 368 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 371 | func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) { |
| 372 | switch tag { |
| 373 | case "": |
| 374 | return android.Paths{j.stubsSrcJar}, nil |
Colin Cross | e68e554 | 2019-08-12 13:11:40 -0700 | [diff] [blame] | 375 | case ".docs.zip": |
| 376 | return android.Paths{j.docZip}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 377 | default: |
| 378 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 379 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 382 | // javadoc converts .java source files to documentation using javadoc. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 383 | func JavadocFactory() android.Module { |
| 384 | module := &Javadoc{} |
| 385 | |
| 386 | module.AddProperties(&module.properties) |
| 387 | |
| 388 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 389 | return module |
| 390 | } |
| 391 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 392 | // javadoc_host converts .java source files to documentation using javadoc. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 393 | func JavadocHostFactory() android.Module { |
| 394 | module := &Javadoc{} |
| 395 | |
| 396 | module.AddProperties(&module.properties) |
| 397 | |
| 398 | InitDroiddocModule(module, android.HostSupported) |
| 399 | return module |
| 400 | } |
| 401 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 402 | var _ android.OutputFileProducer = (*Javadoc)(nil) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 403 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 404 | func (j *Javadoc) sdkVersion() sdkSpec { |
| 405 | return sdkSpecFrom(String(j.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 408 | func (j *Javadoc) systemModules() string { |
| 409 | return proptools.String(j.properties.System_modules) |
| 410 | } |
| 411 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 412 | func (j *Javadoc) minSdkVersion() sdkSpec { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 413 | return j.sdkVersion() |
| 414 | } |
| 415 | |
Jiyong Park | 6a927c4 | 2020-01-21 02:03:43 +0900 | [diff] [blame] | 416 | func (j *Javadoc) targetSdkVersion() sdkSpec { |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 417 | return j.sdkVersion() |
| 418 | } |
| 419 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 420 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 421 | if ctx.Device() { |
Paul Duffin | 250e619 | 2019-06-07 10:44:37 +0100 | [diff] [blame] | 422 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 423 | if sdkDep.useModule { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 424 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 425 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 426 | ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 427 | ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 431 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 434 | func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { |
| 435 | var flags droiddocBuilderFlags |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 436 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 437 | flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 438 | |
| 439 | return flags |
| 440 | } |
| 441 | |
| 442 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 443 | aidlIncludeDirs android.Paths) (string, android.Paths) { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 444 | |
| 445 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) |
| 446 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) |
| 447 | |
| 448 | var flags []string |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 449 | var deps android.Paths |
| 450 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 451 | if aidlPreprocess.Valid() { |
| 452 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 453 | deps = append(deps, aidlPreprocess.Path()) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 454 | } else { |
| 455 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
| 456 | } |
| 457 | |
| 458 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 459 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 460 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
| 461 | flags = append(flags, "-I"+src.String()) |
| 462 | } |
| 463 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 464 | return strings.Join(flags, " "), deps |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 465 | } |
| 466 | |
Jiyong Park | d90d741 | 2019-08-20 22:49:19 +0900 | [diff] [blame] | 467 | // TODO: remove the duplication between this and the one in gen.go |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 468 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 469 | flags droiddocBuilderFlags) android.Paths { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 470 | |
| 471 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 472 | var aidlSrcs android.Paths |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 473 | |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 474 | aidlIncludeFlags := genAidlIncludeFlags(srcFiles) |
| 475 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 476 | for _, srcFile := range srcFiles { |
| 477 | switch srcFile.Ext() { |
| 478 | case ".aidl": |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 479 | aidlSrcs = append(aidlSrcs, srcFile) |
Jiyong Park | d90d741 | 2019-08-20 22:49:19 +0900 | [diff] [blame] | 480 | case ".logtags": |
| 481 | javaFile := genLogtags(ctx, srcFile) |
| 482 | outSrcFiles = append(outSrcFiles, javaFile) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 483 | default: |
| 484 | outSrcFiles = append(outSrcFiles, srcFile) |
| 485 | } |
| 486 | } |
| 487 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 488 | // Process all aidl files together to support sharding them into one or more rules that produce srcjars. |
| 489 | if len(aidlSrcs) > 0 { |
| 490 | srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps) |
| 491 | outSrcFiles = append(outSrcFiles, srcJarFiles...) |
| 492 | } |
| 493 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 494 | return outSrcFiles |
| 495 | } |
| 496 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 497 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 498 | var deps deps |
| 499 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 500 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 501 | if sdkDep.invalidVersion { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 502 | ctx.AddMissingDependencies(sdkDep.bootclasspath) |
| 503 | ctx.AddMissingDependencies(sdkDep.java9Classpath) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 504 | } else if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 505 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) |
Anton Hansson | 26bf49b | 2020-02-08 20:26:29 +0000 | [diff] [blame] | 506 | deps.aidlPreprocess = sdkDep.aidl |
| 507 | } else { |
| 508 | deps.aidlPreprocess = sdkDep.aidl |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | ctx.VisitDirectDeps(func(module android.Module) { |
| 512 | otherName := ctx.OtherModuleName(module) |
| 513 | tag := ctx.OtherModuleDependencyTag(module) |
| 514 | |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 515 | switch tag { |
| 516 | case bootClasspathTag: |
| 517 | if dep, ok := module.(Dependency); ok { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 518 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 519 | } else if sm, ok := module.(SystemModulesProvider); ok { |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 520 | // A system modules dependency has been added to the bootclasspath |
| 521 | // so add its libs to the bootclasspath. |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 522 | deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 523 | } else { |
| 524 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 525 | } |
| 526 | case libTag: |
| 527 | switch dep := module.(type) { |
Colin Cross | 897d2ed | 2019-02-11 14:03:51 -0800 | [diff] [blame] | 528 | case SdkLibraryDependency: |
Paul Duffin | 649dadf | 2020-05-26 11:42:13 +0100 | [diff] [blame] | 529 | deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 530 | case Dependency: |
Sundong Ahn | ba49360 | 2018-11-20 17:36:35 +0900 | [diff] [blame] | 531 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) |
Jiyong Park | 19a7f25 | 2019-07-10 16:59:31 +0900 | [diff] [blame] | 532 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 533 | case android.SourceFileProducer: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 534 | checkProducesJars(ctx, dep) |
| 535 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 536 | default: |
| 537 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 538 | } |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 539 | case java9LibTag: |
| 540 | switch dep := module.(type) { |
| 541 | case Dependency: |
| 542 | deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...) |
| 543 | default: |
| 544 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 545 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 546 | case systemModulesTag: |
| 547 | if deps.systemModules != nil { |
| 548 | panic("Found two system module dependencies") |
| 549 | } |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 550 | sm := module.(SystemModulesProvider) |
| 551 | outputDir, outputDeps := sm.OutputDirAndDeps() |
| 552 | deps.systemModules = &systemModules{outputDir, outputDeps} |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 553 | } |
| 554 | }) |
| 555 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 556 | // may contain filegroup or genrule. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 557 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 558 | j.implicits = append(j.implicits, srcFiles...) |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 559 | |
| 560 | filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path { |
| 561 | if filterPackages == nil { |
| 562 | return srcs |
| 563 | } |
| 564 | filtered := []android.Path{} |
| 565 | for _, src := range srcs { |
| 566 | if src.Ext() != ".java" { |
| 567 | // Don't filter-out non-Java (=generated sources) by package names. This is not ideal, |
| 568 | // but otherwise metalava emits stub sources having references to the generated AIDL classes |
| 569 | // in filtered-out pacages (e.g. com.android.internal.*). |
| 570 | // TODO(b/141149570) We need to fix this by introducing default private constructors or |
| 571 | // fixing metalava to not emit constructors having references to unknown classes. |
| 572 | filtered = append(filtered, src) |
| 573 | continue |
| 574 | } |
| 575 | packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".") |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 576 | if android.HasAnyPrefix(packageName, filterPackages) { |
| 577 | filtered = append(filtered, src) |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | return filtered |
| 581 | } |
| 582 | srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages) |
| 583 | |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 584 | // While metalava needs package html files, it does not need them to be explicit on the command |
| 585 | // line. More importantly, the metalava rsp file is also used by the subsequent jdiff action if |
| 586 | // jdiff_enabled=true. javadoc complains if it receives html files on the command line. The filter |
| 587 | // below excludes html files from the rsp file for both metalava and jdiff. Note that the html |
| 588 | // files are still included as implicit inputs for successful remote execution and correct |
| 589 | // incremental builds. |
| 590 | filterHtml := func(srcs []android.Path) []android.Path { |
| 591 | filtered := []android.Path{} |
| 592 | for _, src := range srcs { |
| 593 | if src.Ext() == ".html" { |
| 594 | continue |
| 595 | } |
| 596 | filtered = append(filtered, src) |
| 597 | } |
| 598 | return filtered |
| 599 | } |
| 600 | srcFiles = filterHtml(srcFiles) |
| 601 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 602 | aidlFlags := j.collectAidlFlags(ctx, deps) |
| 603 | srcFiles = j.genSources(ctx, srcFiles, aidlFlags) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 604 | |
| 605 | // srcs may depend on some genrule output. |
| 606 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 607 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 608 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 609 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 610 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 611 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 612 | if len(j.srcFiles) > 0 { |
| 613 | j.sourcepaths = android.PathsForModuleSrc(ctx, []string{"."}) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 614 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 615 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 616 | j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files) |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 617 | argFilesMap := map[string]string{} |
| 618 | argFileLabels := []string{} |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 619 | |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 620 | for _, label := range j.properties.Arg_files { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 621 | var paths = android.PathsForModuleSrc(ctx, []string{label}) |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 622 | if _, exists := argFilesMap[label]; !exists { |
| 623 | argFilesMap[label] = strings.Join(paths.Strings(), " ") |
| 624 | argFileLabels = append(argFileLabels, label) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 625 | } else { |
| 626 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 627 | label, argFilesMap[label], paths) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 631 | var argsPropertyName string |
| 632 | flags := make([]string, 0) |
| 633 | if j.properties.Args != nil && j.properties.Flags != nil { |
| 634 | ctx.PropertyErrorf("args", "flags is set. Cannot set args") |
| 635 | } else if args := proptools.String(j.properties.Args); args != "" { |
| 636 | flags = append(flags, args) |
| 637 | argsPropertyName = "args" |
| 638 | } else { |
| 639 | flags = append(flags, j.properties.Flags...) |
| 640 | argsPropertyName = "flags" |
| 641 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 642 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 643 | for _, flag := range flags { |
| 644 | args, err := android.Expand(flag, func(name string) (string, error) { |
| 645 | if strings.HasPrefix(name, "location ") { |
| 646 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 647 | if paths, ok := argFilesMap[label]; ok { |
| 648 | return paths, nil |
| 649 | } else { |
| 650 | return "", fmt.Errorf("unknown location label %q, expecting one of %q", |
| 651 | label, strings.Join(argFileLabels, ", ")) |
| 652 | } |
| 653 | } else if name == "genDir" { |
| 654 | return android.PathForModuleGen(ctx).String(), nil |
| 655 | } |
| 656 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 657 | }) |
| 658 | |
| 659 | if err != nil { |
| 660 | ctx.PropertyErrorf(argsPropertyName, "%s", err.Error()) |
| 661 | } |
| 662 | j.args = append(j.args, args) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 665 | return deps |
| 666 | } |
| 667 | |
| 668 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 669 | j.addDeps(ctx) |
| 670 | } |
| 671 | |
| 672 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 673 | deps := j.collectDeps(ctx) |
| 674 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 675 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 676 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 677 | outDir := android.PathForModuleOut(ctx, "out") |
| 678 | srcJarDir := android.PathForModuleOut(ctx, "srcjars") |
| 679 | |
| 680 | j.stubsSrcJar = nil |
| 681 | |
| 682 | rule := android.NewRuleBuilder() |
| 683 | |
| 684 | rule.Command().Text("rm -rf").Text(outDir.String()) |
| 685 | rule.Command().Text("mkdir -p").Text(outDir.String()) |
| 686 | |
| 687 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 688 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 689 | javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 690 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 691 | cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList, |
| 692 | deps.systemModules, deps.classpath, j.sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 693 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 694 | cmd.FlagWithArg("-source ", javaVersion.String()). |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 695 | Flag("-J-Xmx1024m"). |
| 696 | Flag("-XDignore.symbol.file"). |
| 697 | Flag("-Xdoclint:none") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 698 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 699 | rule.Command(). |
| 700 | BuiltTool(ctx, "soong_zip"). |
| 701 | Flag("-write_if_changed"). |
| 702 | Flag("-d"). |
| 703 | FlagWithOutput("-o ", j.docZip). |
| 704 | FlagWithArg("-C ", outDir.String()). |
| 705 | FlagWithArg("-D ", outDir.String()) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 706 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 707 | rule.Restat() |
| 708 | |
| 709 | zipSyncCleanupCmd(rule, srcJarDir) |
| 710 | |
| 711 | rule.Build(pctx, ctx, "javadoc", "javadoc") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 714 | // |
| 715 | // Droiddoc |
| 716 | // |
| 717 | type Droiddoc struct { |
| 718 | Javadoc |
| 719 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 720 | properties DroiddocProperties |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 723 | // droiddoc converts .java source files to documentation using doclava or dokka. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 724 | func DroiddocFactory() android.Module { |
| 725 | module := &Droiddoc{} |
| 726 | |
| 727 | module.AddProperties(&module.properties, |
| 728 | &module.Javadoc.properties) |
| 729 | |
| 730 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 731 | return module |
| 732 | } |
| 733 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 734 | // droiddoc_host converts .java source files to documentation using doclava or dokka. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 735 | func DroiddocHostFactory() android.Module { |
| 736 | module := &Droiddoc{} |
| 737 | |
| 738 | module.AddProperties(&module.properties, |
| 739 | &module.Javadoc.properties) |
| 740 | |
| 741 | InitDroiddocModule(module, android.HostSupported) |
| 742 | return module |
| 743 | } |
| 744 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 745 | func (d *Droiddoc) OutputFiles(tag string) (android.Paths, error) { |
| 746 | switch tag { |
| 747 | case "", ".docs.zip": |
| 748 | return android.Paths{d.Javadoc.docZip}, nil |
| 749 | default: |
| 750 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 751 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 754 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 755 | d.Javadoc.addDeps(ctx) |
| 756 | |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 757 | if String(d.properties.Custom_template) != "" { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 758 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 759 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 762 | func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) { |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 763 | buildNumberFile := ctx.Config().BuildNumberFile(ctx) |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 764 | // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9 |
| 765 | // sources, droiddoc will get sources produced by metalava which will have already stripped out the |
| 766 | // 1.9 language features. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 767 | cmd.FlagWithArg("-source ", "1.8"). |
| 768 | Flag("-J-Xmx1600m"). |
| 769 | Flag("-J-XX:-OmitStackTraceInFastThrow"). |
| 770 | Flag("-XDignore.symbol.file"). |
| 771 | FlagWithArg("-doclet ", "com.google.doclava.Doclava"). |
| 772 | FlagWithInputList("-docletpath ", docletPath.Paths(), ":"). |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 773 | FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile). |
Elliott Hughes | 26bce34 | 2019-09-12 15:05:13 -0700 | [diff] [blame] | 774 | FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `) |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 775 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 776 | if String(d.properties.Custom_template) == "" { |
| 777 | // TODO: This is almost always droiddoc-templates-sdk |
| 778 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 779 | } |
| 780 | |
| 781 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 782 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 783 | cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 784 | } else { |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 785 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m)) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 786 | } |
| 787 | }) |
| 788 | |
| 789 | if len(d.properties.Html_dirs) > 0 { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 790 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 791 | cmd.FlagWithArg("-htmldir ", htmlDir.String()). |
| 792 | Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | if len(d.properties.Html_dirs) > 1 { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 796 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 797 | cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()). |
| 798 | Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")})) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | if len(d.properties.Html_dirs) > 2 { |
| 802 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
| 803 | } |
| 804 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 805 | knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 806 | cmd.FlagForEachInput("-knowntags ", knownTags) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 807 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 808 | cmd.FlagForEachArg("-hdf ", d.properties.Hdf) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 809 | |
| 810 | if String(d.properties.Proofread_file) != "" { |
| 811 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 812 | cmd.FlagWithOutput("-proofread ", proofreadFile) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | if String(d.properties.Todo_file) != "" { |
| 816 | // tricky part: |
| 817 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 818 | // the non-standard doclet will get the full path relative to "-o". |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 819 | cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)). |
| 820 | ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file))) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | if String(d.properties.Resourcesdir) != "" { |
| 824 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 825 | // resourcesDir is one sub dir of htmlDir |
| 826 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 827 | cmd.FlagWithArg("-resourcesdir ", resourcesDir.String()) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if String(d.properties.Resourcesoutdir) != "" { |
| 831 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 832 | cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir)) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 833 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 836 | func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 837 | if String(d.properties.Static_doc_index_redirect) != "" { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 838 | staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect)) |
| 839 | rule.Command().Text("cp"). |
| 840 | Input(staticDocIndexRedirect). |
| 841 | Output(android.PathForModuleOut(ctx, "out", "index.html")) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | if String(d.properties.Static_doc_properties) != "" { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 845 | staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties)) |
| 846 | rule.Command().Text("cp"). |
| 847 | Input(staticDocProperties). |
| 848 | Output(android.PathForModuleOut(ctx, "out", "source.properties")) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 849 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 852 | func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 853 | outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 854 | |
| 855 | cmd := rule.Command(). |
| 856 | BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)). |
| 857 | Flag(config.JavacVmFlags). |
| 858 | FlagWithArg("-encoding ", "UTF-8"). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 859 | FlagWithRspFileInputList("@", srcs). |
| 860 | FlagWithInput("@", srcJarList) |
| 861 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 862 | // TODO(ccross): Remove this if- statement once we finish migration for all Doclava |
| 863 | // based stubs generation. |
| 864 | // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar |
| 865 | // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out |
| 866 | // the correct package name base path. |
| 867 | if len(sourcepaths) > 0 { |
| 868 | cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":") |
| 869 | } else { |
| 870 | cmd.FlagWithArg("-sourcepath ", srcJarDir.String()) |
| 871 | } |
| 872 | |
| 873 | cmd.FlagWithArg("-d ", outDir.String()). |
| 874 | Flag("-quiet") |
| 875 | |
| 876 | return cmd |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 879 | func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
| 880 | outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules, |
| 881 | classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand { |
| 882 | |
| 883 | cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths) |
| 884 | |
| 885 | flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device()) |
| 886 | cmd.Flag(flag).Implicits(deps) |
| 887 | |
| 888 | cmd.FlagWithArg("--patch-module ", "java.base=.") |
| 889 | |
| 890 | if len(classpath) > 0 { |
| 891 | cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":") |
| 892 | } |
| 893 | |
| 894 | return cmd |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 897 | func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
| 898 | outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath, |
| 899 | sourcepaths android.Paths) *android.RuleBuilderCommand { |
| 900 | |
| 901 | cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths) |
| 902 | |
| 903 | if len(bootclasspath) == 0 && ctx.Device() { |
| 904 | // explicitly specify -bootclasspath "" if the bootclasspath is empty to |
| 905 | // ensure java does not fall back to the default bootclasspath. |
| 906 | cmd.FlagWithArg("-bootclasspath ", `""`) |
| 907 | } else if len(bootclasspath) > 0 { |
| 908 | cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":") |
| 909 | } |
| 910 | |
| 911 | if len(classpath) > 0 { |
| 912 | cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":") |
| 913 | } |
| 914 | |
| 915 | return cmd |
| 916 | } |
| 917 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 918 | func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
| 919 | outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 920 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 921 | // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka. |
| 922 | dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...) |
| 923 | |
| 924 | return rule.Command(). |
| 925 | BuiltTool(ctx, "dokka"). |
| 926 | Flag(config.JavacVmFlags). |
| 927 | Flag(srcJarDir.String()). |
| 928 | FlagWithInputList("-classpath ", dokkaClasspath, ":"). |
| 929 | FlagWithArg("-format ", "dac"). |
| 930 | FlagWithArg("-dacRoot ", "/reference/kotlin"). |
| 931 | FlagWithArg("-output ", outDir.String()) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 935 | deps := d.Javadoc.collectDeps(ctx) |
| 936 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 937 | d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 938 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 939 | jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") |
| 940 | doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 941 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 942 | outDir := android.PathForModuleOut(ctx, "out") |
| 943 | srcJarDir := android.PathForModuleOut(ctx, "srcjars") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 944 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 945 | rule := android.NewRuleBuilder() |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 946 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 947 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) |
| 948 | |
| 949 | var cmd *android.RuleBuilderCommand |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 950 | if Bool(d.properties.Dokka_enabled) { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 951 | cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 952 | } else { |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 953 | cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList, |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 954 | deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 957 | cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 958 | |
Mathew Inwood | abd49ab | 2019-12-19 14:27:08 +0000 | [diff] [blame] | 959 | if d.properties.Compat_config != nil { |
| 960 | compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config)) |
| 961 | cmd.FlagWithInput("-compatconfig ", compatConfig) |
| 962 | } |
| 963 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 964 | var desc string |
| 965 | if Bool(d.properties.Dokka_enabled) { |
| 966 | desc = "dokka" |
| 967 | } else { |
| 968 | d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava}) |
| 969 | |
| 970 | for _, o := range d.Javadoc.properties.Out { |
| 971 | cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) |
| 972 | } |
| 973 | |
| 974 | d.postDoclavaCmds(ctx, rule) |
| 975 | desc = "doclava" |
| 976 | } |
| 977 | |
| 978 | rule.Command(). |
| 979 | BuiltTool(ctx, "soong_zip"). |
| 980 | Flag("-write_if_changed"). |
| 981 | Flag("-d"). |
| 982 | FlagWithOutput("-o ", d.docZip). |
| 983 | FlagWithArg("-C ", outDir.String()). |
| 984 | FlagWithArg("-D ", outDir.String()) |
| 985 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 986 | rule.Restat() |
| 987 | |
| 988 | zipSyncCleanupCmd(rule, srcJarDir) |
| 989 | |
| 990 | rule.Build(pctx, ctx, "javadoc", desc) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | // |
| 994 | // Droidstubs |
| 995 | // |
| 996 | type Droidstubs struct { |
| 997 | Javadoc |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 998 | android.SdkBase |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 999 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1000 | properties DroidstubsProperties |
| 1001 | apiFile android.WritablePath |
| 1002 | apiXmlFile android.WritablePath |
| 1003 | lastReleasedApiXmlFile android.WritablePath |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1004 | privateApiFile android.WritablePath |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1005 | removedApiFile android.WritablePath |
| 1006 | removedDexApiFile android.WritablePath |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1007 | nullabilityWarningsFile android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1008 | |
| 1009 | checkCurrentApiTimestamp android.WritablePath |
| 1010 | updateCurrentApiTimestamp android.WritablePath |
| 1011 | checkLastReleasedApiTimestamp android.WritablePath |
Adrian Roos | 075eedc | 2019-10-10 12:07:03 +0200 | [diff] [blame] | 1012 | apiLintTimestamp android.WritablePath |
Adrian Roos | 3b8f1cd | 2019-11-01 13:42:39 +0100 | [diff] [blame] | 1013 | apiLintReport android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1014 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1015 | checkNullabilityWarningsTimestamp android.WritablePath |
| 1016 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1017 | annotationsZip android.WritablePath |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1018 | apiVersionsXml android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1019 | |
| 1020 | apiFilePath android.Path |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1021 | |
| 1022 | jdiffDocZip android.WritablePath |
| 1023 | jdiffStubsSrcJar android.WritablePath |
Jerome Gaillard | 0f59903 | 2019-10-10 19:29:11 +0100 | [diff] [blame] | 1024 | |
| 1025 | metadataZip android.WritablePath |
| 1026 | metadataDir android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 1029 | // droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be |
| 1030 | // documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to |
| 1031 | // a droiddoc module to generate documentation. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1032 | func DroidstubsFactory() android.Module { |
| 1033 | module := &Droidstubs{} |
| 1034 | |
| 1035 | module.AddProperties(&module.properties, |
| 1036 | &module.Javadoc.properties) |
| 1037 | |
| 1038 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1039 | android.InitSdkAwareModule(module) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1040 | return module |
| 1041 | } |
| 1042 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 1043 | // droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API |
| 1044 | // to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be |
| 1045 | // passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs |
| 1046 | // module when symbols needed by the source files are provided by java_library_host modules. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1047 | func DroidstubsHostFactory() android.Module { |
| 1048 | module := &Droidstubs{} |
| 1049 | |
| 1050 | module.AddProperties(&module.properties, |
| 1051 | &module.Javadoc.properties) |
| 1052 | |
| 1053 | InitDroiddocModule(module, android.HostSupported) |
| 1054 | return module |
| 1055 | } |
| 1056 | |
Colin Cross | 014489c | 2020-06-02 20:09:13 -0700 | [diff] [blame] | 1057 | func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) { |
| 1058 | switch tag { |
| 1059 | case "": |
| 1060 | return android.Paths{d.stubsSrcJar}, nil |
| 1061 | case ".docs.zip": |
| 1062 | return android.Paths{d.docZip}, nil |
| 1063 | case ".annotations.zip": |
| 1064 | return android.Paths{d.annotationsZip}, nil |
| 1065 | case ".api_versions.xml": |
| 1066 | return android.Paths{d.apiVersionsXml}, nil |
| 1067 | default: |
| 1068 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1069 | } |
| 1070 | } |
| 1071 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1072 | func (d *Droidstubs) ApiFilePath() android.Path { |
| 1073 | return d.apiFilePath |
| 1074 | } |
| 1075 | |
Paul Duffin | 1fd005d | 2020-04-09 01:08:11 +0100 | [diff] [blame] | 1076 | func (d *Droidstubs) RemovedApiFilePath() android.Path { |
| 1077 | return d.removedApiFile |
| 1078 | } |
| 1079 | |
Paul Duffin | 3d1248c | 2020-04-09 00:10:17 +0100 | [diff] [blame] | 1080 | func (d *Droidstubs) StubsSrcJar() android.Path { |
| 1081 | return d.stubsSrcJar |
| 1082 | } |
| 1083 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1084 | func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1085 | d.Javadoc.addDeps(ctx) |
| 1086 | |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1087 | // If requested clear any properties that provide information about the latest version |
| 1088 | // of an API and which reference non-existent modules. |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 1089 | if Bool(d.properties.Check_api.Ignore_missing_latest_api) { |
| 1090 | ignoreMissingModules(ctx, &d.properties.Check_api.Last_released) |
Paul Duffin | 160fe41 | 2020-05-10 19:32:20 +0100 | [diff] [blame] | 1091 | |
| 1092 | // If the new_since references a module, e.g. :module-latest-api and the module |
| 1093 | // does not exist then clear it. |
| 1094 | newSinceSrc := d.properties.Check_api.Api_lint.New_since |
| 1095 | newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc)) |
| 1096 | if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) { |
| 1097 | d.properties.Check_api.Api_lint.New_since = nil |
| 1098 | } |
Inseob Kim | 38449af | 2019-02-28 14:24:05 +0900 | [diff] [blame] | 1099 | } |
| 1100 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1101 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 1102 | for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs { |
| 1103 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) |
| 1104 | } |
| 1105 | } |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1106 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1107 | if len(d.properties.Merge_inclusion_annotations_dirs) != 0 { |
| 1108 | for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs { |
| 1109 | ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir) |
| 1110 | } |
| 1111 | } |
| 1112 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1113 | if len(d.properties.Api_levels_annotations_dirs) != 0 { |
| 1114 | for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs { |
| 1115 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir) |
| 1116 | } |
| 1117 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Paul Duffin | 3ae2951 | 2020-04-08 18:18:03 +0100 | [diff] [blame] | 1120 | func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) { |
Luca Stefani | d63ea0a | 2019-09-01 21:49:45 +0200 | [diff] [blame] | 1121 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || |
| 1122 | apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1123 | String(d.properties.Api_filename) != "" { |
Liz Kammer | 9ed7915 | 2020-08-24 15:56:32 -0700 | [diff] [blame^] | 1124 | filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") |
| 1125 | d.apiFile = android.PathForModuleOut(ctx, filename) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1126 | cmd.FlagWithOutput("--api ", d.apiFile) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1127 | d.apiFilePath = d.apiFile |
| 1128 | } |
| 1129 | |
Luca Stefani | d63ea0a | 2019-09-01 21:49:45 +0200 | [diff] [blame] | 1130 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") || |
| 1131 | apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") || |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1132 | String(d.properties.Removed_api_filename) != "" { |
Liz Kammer | 9ed7915 | 2020-08-24 15:56:32 -0700 | [diff] [blame^] | 1133 | filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") |
| 1134 | d.removedApiFile = android.PathForModuleOut(ctx, filename) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1135 | cmd.FlagWithOutput("--removed-api ", d.removedApiFile) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1138 | if String(d.properties.Removed_dex_api_filename) != "" { |
| 1139 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1140 | cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1143 | if Bool(d.properties.Write_sdk_values) { |
Jerome Gaillard | 0f59903 | 2019-10-10 19:29:11 +0100 | [diff] [blame] | 1144 | d.metadataDir = android.PathForModuleOut(ctx, "metadata") |
| 1145 | cmd.FlagWithArg("--sdk-values ", d.metadataDir.String()) |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Paul Duffin | 3ae2951 | 2020-04-08 18:18:03 +0100 | [diff] [blame] | 1148 | if stubsDir.Valid() { |
| 1149 | if Bool(d.properties.Create_doc_stubs) { |
| 1150 | cmd.FlagWithArg("--doc-stubs ", stubsDir.String()) |
| 1151 | } else { |
| 1152 | cmd.FlagWithArg("--stubs ", stubsDir.String()) |
| 1153 | cmd.Flag("--exclude-documentation-from-stubs") |
| 1154 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1155 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1158 | func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1159 | if Bool(d.properties.Annotations_enabled) { |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1160 | cmd.Flag("--include-annotations") |
| 1161 | |
Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1162 | validatingNullability := |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1163 | android.InList("--validate-nullability-from-merged-stubs", d.Javadoc.args) || |
Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1164 | String(d.properties.Validate_nullability_from_list) != "" |
Paul Duffin | 13a9dd6 | 2019-11-04 10:26:47 +0000 | [diff] [blame] | 1165 | |
Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1166 | migratingNullability := String(d.properties.Previous_api) != "" |
Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1167 | if migratingNullability { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1168 | previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api)) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1169 | cmd.FlagWithInput("--migrate-nullness ", previousApi) |
Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1170 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1171 | |
Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1172 | if s := String(d.properties.Validate_nullability_from_list); s != "" { |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1173 | cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s)) |
Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1174 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1175 | |
Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1176 | if validatingNullability { |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1177 | d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1178 | cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile) |
Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1179 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1180 | |
| 1181 | d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1182 | cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip) |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1183 | |
Anton Hansson | 9d7c3fb | 2020-05-21 10:11:31 +0100 | [diff] [blame] | 1184 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 1185 | d.mergeAnnoDirFlags(ctx, cmd) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1186 | } |
Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1187 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1188 | // TODO(tnorbye): find owners to fix these warnings when annotation was enabled. |
| 1189 | cmd.FlagWithArg("--hide ", "HiddenTypedefConstant"). |
| 1190 | FlagWithArg("--hide ", "SuperfluousPrefix"). |
| 1191 | FlagWithArg("--hide ", "AnnotationExtraction") |
| 1192 | } |
Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1195 | func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 1196 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { |
| 1197 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1198 | cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps) |
| 1199 | } else { |
| 1200 | ctx.PropertyErrorf("merge_annotations_dirs", |
| 1201 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 1202 | } |
| 1203 | }) |
| 1204 | } |
| 1205 | |
| 1206 | func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1207 | ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) { |
| 1208 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1209 | cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps) |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1210 | } else { |
| 1211 | ctx.PropertyErrorf("merge_inclusion_annotations_dirs", |
| 1212 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 1213 | } |
| 1214 | }) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1217 | func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1218 | if !Bool(d.properties.Api_levels_annotations_enabled) { |
| 1219 | return |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1220 | } |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1221 | |
| 1222 | d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml") |
| 1223 | |
| 1224 | if len(d.properties.Api_levels_annotations_dirs) == 0 { |
| 1225 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 1226 | "has to be non-empty if api levels annotations was enabled!") |
| 1227 | } |
| 1228 | |
| 1229 | cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml) |
| 1230 | cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml) |
| 1231 | cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion()) |
| 1232 | cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) |
| 1233 | |
| 1234 | filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar") |
| 1235 | |
| 1236 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) { |
| 1237 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1238 | for _, dep := range t.deps { |
| 1239 | if strings.HasSuffix(dep.String(), filename) { |
| 1240 | cmd.Implicit(dep) |
| 1241 | } |
| 1242 | } |
| 1243 | cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/"+filename) |
| 1244 | } else { |
| 1245 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 1246 | "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m)) |
| 1247 | } |
| 1248 | }) |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1251 | func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1252 | if Bool(d.properties.Jdiff_enabled) && d.apiFile != nil { |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1253 | if d.apiFile.String() == "" { |
| 1254 | ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.") |
| 1255 | } |
| 1256 | |
| 1257 | d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1258 | cmd.FlagWithOutput("--api-xml ", d.apiXmlFile) |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1259 | |
| 1260 | if String(d.properties.Check_api.Last_released.Api_file) == "" { |
| 1261 | ctx.PropertyErrorf("check_api.last_released.api_file", |
| 1262 | "has to be non-empty if jdiff was enabled!") |
| 1263 | } |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1264 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1265 | lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file)) |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1266 | d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1267 | cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile) |
| 1268 | } |
| 1269 | } |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1270 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1271 | func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths, |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1272 | srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicitsRsp android.WritablePath, sandbox bool) *android.RuleBuilderCommand { |
Colin Cross | 8b8bec3 | 2019-11-15 13:18:43 -0800 | [diff] [blame] | 1273 | // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel. |
| 1274 | rule.HighMem() |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1275 | cmd := rule.Command() |
Ramy Medhat | 16f23a4 | 2020-09-03 01:29:49 -0400 | [diff] [blame] | 1276 | if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA") { |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1277 | rule.Remoteable(android.RemoteRuleSupports{RBE: true}) |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1278 | pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava") |
| 1279 | execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy) |
| 1280 | labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"} |
| 1281 | if !sandbox { |
| 1282 | execStrategy = remoteexec.LocalExecStrategy |
| 1283 | labels["shallow"] = "true" |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1284 | } |
| 1285 | inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()} |
| 1286 | if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" { |
| 1287 | inputs = append(inputs, strings.Split(v, ",")...) |
| 1288 | } |
| 1289 | cmd.Text((&remoteexec.REParams{ |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1290 | Labels: labels, |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1291 | ExecStrategy: execStrategy, |
| 1292 | Inputs: inputs, |
Ramy Medhat | c8d60bc | 2020-06-04 01:54:07 -0400 | [diff] [blame] | 1293 | RSPFile: implicitsRsp.String(), |
Ramy Medhat | 427683c | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1294 | ToolchainInputs: []string{config.JavaCmd(ctx).String()}, |
| 1295 | Platform: map[string]string{remoteexec.PoolKey: pool}, |
| 1296 | }).NoVarTemplate(ctx.Config())) |
| 1297 | } |
| 1298 | |
| 1299 | cmd.BuiltTool(ctx, "metalava"). |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1300 | Flag(config.JavacVmFlags). |
| 1301 | FlagWithArg("-encoding ", "UTF-8"). |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 1302 | FlagWithArg("-source ", javaVersion.String()). |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1303 | FlagWithRspFileInputList("@", srcs). |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1304 | FlagWithInput("@", srcJarList) |
| 1305 | |
| 1306 | if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" { |
| 1307 | cmd.Implicit(android.PathForSource(ctx, javaHome)) |
| 1308 | } |
| 1309 | |
| 1310 | if sandbox { |
| 1311 | cmd.FlagWithOutput("--strict-input-files ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) |
| 1312 | } else { |
| 1313 | cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt")) |
| 1314 | } |
Ramy Medhat | c8d60bc | 2020-06-04 01:54:07 -0400 | [diff] [blame] | 1315 | |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1316 | if implicitsRsp != nil { |
Ramy Medhat | c8d60bc | 2020-06-04 01:54:07 -0400 | [diff] [blame] | 1317 | cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String()) |
| 1318 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1319 | |
| 1320 | if len(bootclasspath) > 0 { |
| 1321 | cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":") |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1324 | if len(classpath) > 0 { |
| 1325 | cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":") |
| 1326 | } |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1327 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1328 | if len(sourcepaths) > 0 { |
| 1329 | cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":") |
| 1330 | } else { |
| 1331 | cmd.FlagWithArg("-sourcepath ", `""`) |
| 1332 | } |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1333 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1334 | cmd.Flag("--no-banner"). |
| 1335 | Flag("--color"). |
| 1336 | Flag("--quiet"). |
Makoto Onuki | 0df103a | 2020-07-17 15:11:24 -0700 | [diff] [blame] | 1337 | Flag("--format=v2"). |
| 1338 | FlagWithArg("--repeat-errors-max ", "10"). |
| 1339 | FlagWithArg("--hide ", "UnresolvedImport") |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1340 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1341 | return cmd |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1344 | func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1345 | deps := d.Javadoc.collectDeps(ctx) |
| 1346 | |
| 1347 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1348 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1349 | // Create rule for metalava |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1350 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1351 | srcJarDir := android.PathForModuleOut(ctx, "srcjars") |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1352 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1353 | rule := android.NewRuleBuilder() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1354 | |
Paul Duffin | 3ae2951 | 2020-04-08 18:18:03 +0100 | [diff] [blame] | 1355 | generateStubs := BoolDefault(d.properties.Generate_stubs, true) |
| 1356 | var stubsDir android.OptionalPath |
| 1357 | if generateStubs { |
| 1358 | d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
| 1359 | stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir")) |
| 1360 | rule.Command().Text("rm -rf").Text(stubsDir.String()) |
| 1361 | rule.Command().Text("mkdir -p").Text(stubsDir.String()) |
| 1362 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1363 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1364 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) |
| 1365 | |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1366 | implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp") |
| 1367 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1368 | cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList, |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1369 | deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp, |
| 1370 | Bool(d.Javadoc.properties.Sandbox)) |
| 1371 | cmd.Implicits(d.Javadoc.implicits) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1372 | |
| 1373 | d.stubsFlags(ctx, cmd, stubsDir) |
| 1374 | |
| 1375 | d.annotationsFlags(ctx, cmd) |
| 1376 | d.inclusionAnnotationsFlags(ctx, cmd) |
| 1377 | d.apiLevelsAnnotationsFlags(ctx, cmd) |
| 1378 | d.apiToXmlFlags(ctx, cmd) |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1379 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1380 | if android.InList("--generate-documentation", d.Javadoc.args) { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1381 | // Currently Metalava have the ability to invoke Javadoc in a seperate process. |
| 1382 | // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives |
| 1383 | // "--generate-documentation" arg. This is not needed when Metalava removes this feature. |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1384 | d.Javadoc.args = append(d.Javadoc.args, "-nodocs") |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 1385 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1386 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1387 | cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1388 | for _, o := range d.Javadoc.properties.Out { |
| 1389 | cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) |
| 1390 | } |
| 1391 | |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1392 | // Add options for the other optional tasks: API-lint and check-released. |
| 1393 | // We generate separate timestamp files for them. |
| 1394 | |
| 1395 | doApiLint := false |
| 1396 | doCheckReleased := false |
| 1397 | |
| 1398 | // Add API lint options. |
| 1399 | |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1400 | if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) { |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1401 | doApiLint = true |
| 1402 | |
| 1403 | newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since) |
| 1404 | if newSince.Valid() { |
| 1405 | cmd.FlagWithInput("--api-lint ", newSince.Path()) |
| 1406 | } else { |
| 1407 | cmd.Flag("--api-lint") |
| 1408 | } |
| 1409 | d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt") |
| 1410 | cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint" |
| 1411 | |
Makoto Onuki | 194c43f | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1412 | // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released. |
| 1413 | if d.Name() != "android.car-system-stubs-docs" && |
| 1414 | d.Name() != "android.car-stubs-docs" && |
| 1415 | d.Name() != "system-api-stubs-docs" && |
| 1416 | d.Name() != "test-api-stubs-docs" { |
| 1417 | cmd.Flag("--lints-as-errors") |
| 1418 | cmd.Flag("--warnings-as-errors") // Most lints are actually warnings. |
| 1419 | } |
| 1420 | |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1421 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file) |
| 1422 | updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt") |
| 1423 | d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp") |
| 1424 | |
| 1425 | // Note this string includes a special shell quote $' ... ', which decodes the "\n"s. |
| 1426 | // However, because $' ... ' doesn't expand environmental variables, we can't just embed |
| 1427 | // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again, |
| 1428 | // which is why we have '"$PWD"$' in it. |
| 1429 | // |
| 1430 | // TODO: metalava also has a slightly different message hardcoded. Should we unify this |
| 1431 | // message and metalava's one? |
| 1432 | msg := `$'` + // Enclose with $' ... ' |
| 1433 | `************************************************************\n` + |
| 1434 | `Your API changes are triggering API Lint warnings or errors.\n` + |
| 1435 | `To make these errors go away, fix the code according to the\n` + |
| 1436 | `error and/or warning messages above.\n` + |
| 1437 | `\n` + |
| 1438 | `If it is not possible to do so, there are workarounds:\n` + |
| 1439 | `\n` + |
| 1440 | `1. You can suppress the errors with @SuppressLint("<id>")\n` |
| 1441 | |
| 1442 | if baselineFile.Valid() { |
| 1443 | cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path()) |
| 1444 | cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput) |
| 1445 | |
| 1446 | msg += fmt.Sprintf(``+ |
| 1447 | `2. You can update the baseline by executing the following\n`+ |
| 1448 | ` command:\n`+ |
Anton Hansson | 3361a29 | 2020-05-11 15:38:31 +0100 | [diff] [blame] | 1449 | ` cp \\\n`+ |
| 1450 | ` "'"$PWD"$'/%s" \\\n`+ |
| 1451 | ` "'"$PWD"$'/%s"\n`+ |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1452 | ` To submit the revised baseline.txt to the main Android\n`+ |
| 1453 | ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path()) |
| 1454 | } else { |
| 1455 | msg += fmt.Sprintf(``+ |
| 1456 | `2. You can add a baseline file of existing lint failures\n`+ |
| 1457 | ` to the build rule of %s.\n`, d.Name()) |
| 1458 | } |
| 1459 | // Note the message ends with a ' (single quote), to close the $' ... ' . |
| 1460 | msg += `************************************************************\n'` |
| 1461 | |
| 1462 | cmd.FlagWithArg("--error-message:api-lint ", msg) |
| 1463 | } |
| 1464 | |
| 1465 | // Add "check released" options. (Detect incompatible API changes from the last public release) |
| 1466 | |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1467 | if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") { |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1468 | doCheckReleased = true |
| 1469 | |
| 1470 | if len(d.Javadoc.properties.Out) > 0 { |
| 1471 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 1472 | } |
| 1473 | |
| 1474 | apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file)) |
| 1475 | removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file)) |
| 1476 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file) |
| 1477 | updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt") |
| 1478 | |
| 1479 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") |
| 1480 | |
| 1481 | cmd.FlagWithInput("--check-compatibility:api:released ", apiFile) |
| 1482 | cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile) |
| 1483 | |
| 1484 | if baselineFile.Valid() { |
| 1485 | cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path()) |
| 1486 | cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput) |
| 1487 | } |
| 1488 | |
| 1489 | // Note this string includes quote ($' ... '), which decodes the "\n"s. |
| 1490 | msg := `$'\n******************************\n` + |
| 1491 | `You have tried to change the API from what has been previously released in\n` + |
| 1492 | `an SDK. Please fix the errors listed above.\n` + |
| 1493 | `******************************\n'` |
| 1494 | |
| 1495 | cmd.FlagWithArg("--error-message:compatibility:released ", msg) |
| 1496 | } |
| 1497 | |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1498 | impRule := android.NewRuleBuilder() |
| 1499 | impCmd := impRule.Command() |
Liz Kammer | 20ebfb4 | 2020-07-28 11:32:07 -0700 | [diff] [blame] | 1500 | // An action that copies the ninja generated rsp file to a new location. This allows us to |
Ramy Medhat | 2f99eec | 2020-06-13 17:38:27 -0400 | [diff] [blame] | 1501 | // add a large number of inputs to a file without exceeding bash command length limits (which |
| 1502 | // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the |
| 1503 | // rsp file to be ${output}.rsp. |
| 1504 | impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp) |
| 1505 | impRule.Build(pctx, ctx, "implicitsGen", "implicits generation") |
| 1506 | cmd.Implicit(implicitsRsp) |
| 1507 | |
Paul Duffin | 3ae2951 | 2020-04-08 18:18:03 +0100 | [diff] [blame] | 1508 | if generateStubs { |
| 1509 | rule.Command(). |
| 1510 | BuiltTool(ctx, "soong_zip"). |
| 1511 | Flag("-write_if_changed"). |
| 1512 | Flag("-jar"). |
| 1513 | FlagWithOutput("-o ", d.Javadoc.stubsSrcJar). |
| 1514 | FlagWithArg("-C ", stubsDir.String()). |
| 1515 | FlagWithArg("-D ", stubsDir.String()) |
| 1516 | } |
Jerome Gaillard | 0f59903 | 2019-10-10 19:29:11 +0100 | [diff] [blame] | 1517 | |
| 1518 | if Bool(d.properties.Write_sdk_values) { |
| 1519 | d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip") |
| 1520 | rule.Command(). |
| 1521 | BuiltTool(ctx, "soong_zip"). |
| 1522 | Flag("-write_if_changed"). |
| 1523 | Flag("-d"). |
| 1524 | FlagWithOutput("-o ", d.metadataZip). |
| 1525 | FlagWithArg("-C ", d.metadataDir.String()). |
| 1526 | FlagWithArg("-D ", d.metadataDir.String()) |
| 1527 | } |
| 1528 | |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1529 | // TODO: We don't really need two separate API files, but this is a reminiscence of how |
| 1530 | // we used to run metalava separately for API lint and the "last_released" check. Unify them. |
| 1531 | if doApiLint { |
| 1532 | rule.Command().Text("touch").Output(d.apiLintTimestamp) |
| 1533 | } |
| 1534 | if doCheckReleased { |
| 1535 | rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp) |
| 1536 | } |
| 1537 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1538 | rule.Restat() |
| 1539 | |
| 1540 | zipSyncCleanupCmd(rule, srcJarDir) |
| 1541 | |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1542 | rule.Build(pctx, ctx, "metalava", "metalava merged") |
Adrian Roos | 075eedc | 2019-10-10 12:07:03 +0200 | [diff] [blame] | 1543 | |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1544 | if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") { |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1545 | |
| 1546 | if len(d.Javadoc.properties.Out) > 0 { |
| 1547 | ctx.PropertyErrorf("out", "out property may not be combined with check_api") |
| 1548 | } |
| 1549 | |
| 1550 | apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file)) |
| 1551 | removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file)) |
Adrian Roos | 14f75a9 | 2019-08-12 17:54:09 +0200 | [diff] [blame] | 1552 | baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file) |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1553 | |
| 1554 | if baselineFile.Valid() { |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1555 | ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName()) |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1556 | } |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1557 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1558 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1559 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1560 | rule := android.NewRuleBuilder() |
| 1561 | |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1562 | // Diff command line. |
Makoto Onuki | 88b9905 | 2020-04-27 17:22:16 -0700 | [diff] [blame] | 1563 | // -F matches the closest "opening" line, such as "package android {" |
| 1564 | // and " public class Intent {". |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1565 | diff := `diff -u -F '{ *$'` |
| 1566 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1567 | rule.Command().Text("( true") |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1568 | rule.Command(). |
| 1569 | Text(diff). |
| 1570 | Input(apiFile).Input(d.apiFile) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1571 | |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1572 | rule.Command(). |
| 1573 | Text(diff). |
| 1574 | Input(removedApiFile).Input(d.removedApiFile) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1575 | |
| 1576 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 1577 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1578 | `To make these errors go away, you have two choices:\n`+ |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1579 | ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+ |
| 1580 | ` to the new methods, etc. shown in the above diff.\n\n`+ |
| 1581 | ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+ |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1582 | ` make %s-update-current-api\n\n`+ |
| 1583 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1584 | ` you will need approval.\n`+ |
| 1585 | `******************************\n`, ctx.ModuleName()) |
| 1586 | |
| 1587 | rule.Command(). |
| 1588 | Text("touch").Output(d.checkCurrentApiTimestamp). |
| 1589 | Text(") || ("). |
| 1590 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1591 | Text("; exit 38"). |
| 1592 | Text(")") |
| 1593 | |
Makoto Onuki | 5405a73 | 2020-04-16 17:02:40 -0700 | [diff] [blame] | 1594 | rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API") |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1595 | |
| 1596 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1597 | |
| 1598 | // update API rule |
| 1599 | rule = android.NewRuleBuilder() |
| 1600 | |
| 1601 | rule.Command().Text("( true") |
| 1602 | |
| 1603 | rule.Command(). |
| 1604 | Text("cp").Flag("-f"). |
| 1605 | Input(d.apiFile).Flag(apiFile.String()) |
| 1606 | |
| 1607 | rule.Command(). |
| 1608 | Text("cp").Flag("-f"). |
| 1609 | Input(d.removedApiFile).Flag(removedApiFile.String()) |
| 1610 | |
| 1611 | msg = "failed to update public API" |
| 1612 | |
| 1613 | rule.Command(). |
| 1614 | Text("touch").Output(d.updateCurrentApiTimestamp). |
| 1615 | Text(") || ("). |
| 1616 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1617 | Text("; exit 38"). |
| 1618 | Text(")") |
| 1619 | |
| 1620 | rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API") |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1621 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1622 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1623 | if String(d.properties.Check_nullability_warnings) != "" { |
| 1624 | if d.nullabilityWarningsFile == nil { |
| 1625 | ctx.PropertyErrorf("check_nullability_warnings", |
| 1626 | "Cannot specify check_nullability_warnings unless validating nullability") |
| 1627 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1628 | |
| 1629 | checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings)) |
| 1630 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1631 | d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp") |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1632 | |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1633 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 1634 | `The warnings encountered during nullability annotation validation did\n`+ |
| 1635 | `not match the checked in file of expected warnings. The diffs are shown\n`+ |
| 1636 | `above. You have two options:\n`+ |
| 1637 | ` 1. Resolve the differences by editing the nullability annotations.\n`+ |
| 1638 | ` 2. Update the file of expected warnings by running:\n`+ |
| 1639 | ` cp %s %s\n`+ |
| 1640 | ` and submitting the updated file as part of your change.`, |
| 1641 | d.nullabilityWarningsFile, checkNullabilityWarnings) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1642 | |
| 1643 | rule := android.NewRuleBuilder() |
| 1644 | |
| 1645 | rule.Command(). |
| 1646 | Text("("). |
| 1647 | Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile). |
| 1648 | Text("&&"). |
| 1649 | Text("touch").Output(d.checkNullabilityWarningsTimestamp). |
| 1650 | Text(") || ("). |
| 1651 | Text("echo").Flag("-e").Flag(`"` + msg + `"`). |
| 1652 | Text("; exit 38"). |
| 1653 | Text(")") |
| 1654 | |
| 1655 | rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check") |
Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
Dan Willemsen | 9f43597 | 2020-05-28 15:28:00 -0700 | [diff] [blame] | 1658 | if Bool(d.properties.Jdiff_enabled) { |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1659 | if len(d.Javadoc.properties.Out) > 0 { |
| 1660 | ctx.PropertyErrorf("out", "out property may not be combined with jdiff") |
| 1661 | } |
| 1662 | |
| 1663 | outDir := android.PathForModuleOut(ctx, "jdiff-out") |
| 1664 | srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars") |
| 1665 | stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir") |
| 1666 | |
| 1667 | rule := android.NewRuleBuilder() |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1668 | |
Nan Zhang | 86b0620 | 2018-09-21 17:09:21 -0700 | [diff] [blame] | 1669 | // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below |
| 1670 | // since there's cron job downstream that fetch this .zip file periodically. |
| 1671 | // See b/116221385 for reference. |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1672 | d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip") |
| 1673 | d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar") |
| 1674 | |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1675 | jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar") |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1676 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1677 | rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String()) |
| 1678 | rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String()) |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1679 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1680 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) |
| 1681 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 1682 | cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList, |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 1683 | deps.bootClasspath, deps.classpath, d.sourcepaths) |
| 1684 | |
| 1685 | cmd.Flag("-J-Xmx1600m"). |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1686 | Flag("-XDignore.symbol.file"). |
| 1687 | FlagWithArg("-doclet ", "jdiff.JDiff"). |
| 1688 | FlagWithInput("-docletpath ", jdiff). |
Paul Duffin | 10269f1 | 2020-06-19 18:39:55 +0100 | [diff] [blame] | 1689 | Flag("-quiet") |
| 1690 | |
| 1691 | if d.apiXmlFile != nil { |
| 1692 | cmd.FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())). |
| 1693 | FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())). |
| 1694 | Implicit(d.apiXmlFile) |
| 1695 | } |
| 1696 | |
| 1697 | if d.lastReleasedApiXmlFile != nil { |
| 1698 | cmd.FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())). |
| 1699 | FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())). |
| 1700 | Implicit(d.lastReleasedApiXmlFile) |
| 1701 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1702 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1703 | rule.Command(). |
| 1704 | BuiltTool(ctx, "soong_zip"). |
| 1705 | Flag("-write_if_changed"). |
| 1706 | Flag("-d"). |
| 1707 | FlagWithOutput("-o ", d.jdiffDocZip). |
| 1708 | FlagWithArg("-C ", outDir.String()). |
| 1709 | FlagWithArg("-D ", outDir.String()) |
| 1710 | |
| 1711 | rule.Command(). |
| 1712 | BuiltTool(ctx, "soong_zip"). |
| 1713 | Flag("-write_if_changed"). |
| 1714 | Flag("-jar"). |
| 1715 | FlagWithOutput("-o ", d.jdiffStubsSrcJar). |
| 1716 | FlagWithArg("-C ", stubsDir.String()). |
| 1717 | FlagWithArg("-D ", stubsDir.String()) |
| 1718 | |
| 1719 | rule.Restat() |
| 1720 | |
| 1721 | zipSyncCleanupCmd(rule, srcJarDir) |
| 1722 | |
| 1723 | rule.Build(pctx, ctx, "jdiff", "jdiff") |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1724 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1725 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1726 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1727 | // |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1728 | // Exported Droiddoc Directory |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1729 | // |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1730 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1731 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1732 | var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"} |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1733 | var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1734 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1735 | type ExportedDroiddocDirProperties struct { |
| 1736 | // path to the directory containing Droiddoc related files. |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1737 | Path *string |
| 1738 | } |
| 1739 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1740 | type ExportedDroiddocDir struct { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1741 | android.ModuleBase |
| 1742 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1743 | properties ExportedDroiddocDirProperties |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1744 | |
| 1745 | deps android.Paths |
| 1746 | dir android.Path |
| 1747 | } |
| 1748 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 1749 | // droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava. |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1750 | func ExportedDroiddocDirFactory() android.Module { |
| 1751 | module := &ExportedDroiddocDir{} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1752 | module.AddProperties(&module.properties) |
| 1753 | android.InitAndroidModule(module) |
| 1754 | return module |
| 1755 | } |
| 1756 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1757 | func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1758 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1759 | func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 1760 | path := String(d.properties.Path) |
| 1761 | d.dir = android.PathForModuleSrc(ctx, path) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 1762 | d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")}) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1763 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1764 | |
| 1765 | // |
| 1766 | // Defaults |
| 1767 | // |
| 1768 | type DocDefaults struct { |
| 1769 | android.ModuleBase |
| 1770 | android.DefaultsModuleBase |
| 1771 | } |
| 1772 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1773 | func DocDefaultsFactory() android.Module { |
| 1774 | module := &DocDefaults{} |
| 1775 | |
| 1776 | module.AddProperties( |
| 1777 | &JavadocProperties{}, |
| 1778 | &DroiddocProperties{}, |
| 1779 | ) |
| 1780 | |
| 1781 | android.InitDefaultsModule(module) |
| 1782 | |
| 1783 | return module |
| 1784 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1785 | |
| 1786 | func StubsDefaultsFactory() android.Module { |
| 1787 | module := &DocDefaults{} |
| 1788 | |
| 1789 | module.AddProperties( |
| 1790 | &JavadocProperties{}, |
| 1791 | &DroidstubsProperties{}, |
| 1792 | ) |
| 1793 | |
| 1794 | android.InitDefaultsModule(module) |
| 1795 | |
| 1796 | return module |
| 1797 | } |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 1798 | |
| 1799 | func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
| 1800 | srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath { |
| 1801 | |
| 1802 | rule.Command().Text("rm -rf").Text(srcJarDir.String()) |
| 1803 | rule.Command().Text("mkdir -p").Text(srcJarDir.String()) |
| 1804 | srcJarList := srcJarDir.Join(ctx, "list") |
| 1805 | |
| 1806 | rule.Temporary(srcJarList) |
| 1807 | |
| 1808 | rule.Command().BuiltTool(ctx, "zipsync"). |
| 1809 | FlagWithArg("-d ", srcJarDir.String()). |
| 1810 | FlagWithOutput("-l ", srcJarList). |
| 1811 | FlagWithArg("-f ", `"*.java"`). |
| 1812 | Inputs(srcJars) |
| 1813 | |
| 1814 | return srcJarList |
| 1815 | } |
| 1816 | |
| 1817 | func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) { |
| 1818 | rule.Command().Text("rm -rf").Text(srcJarDir.String()) |
| 1819 | } |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1820 | |
| 1821 | var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil) |
| 1822 | |
| 1823 | type PrebuiltStubsSourcesProperties struct { |
| 1824 | Srcs []string `android:"path"` |
| 1825 | } |
| 1826 | |
| 1827 | type PrebuiltStubsSources struct { |
| 1828 | android.ModuleBase |
| 1829 | android.DefaultableModuleBase |
| 1830 | prebuilt android.Prebuilt |
| 1831 | android.SdkBase |
| 1832 | |
| 1833 | properties PrebuiltStubsSourcesProperties |
| 1834 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 1835 | // The source directories containing stubs source files. |
| 1836 | srcDirs android.Paths |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1837 | stubsSrcJar android.ModuleOutPath |
| 1838 | } |
| 1839 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 1840 | func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) { |
| 1841 | switch tag { |
| 1842 | case "": |
| 1843 | return android.Paths{p.stubsSrcJar}, nil |
| 1844 | default: |
| 1845 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 1846 | } |
| 1847 | } |
| 1848 | |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 1849 | func (d *PrebuiltStubsSources) StubsSrcJar() android.Path { |
| 1850 | return d.stubsSrcJar |
| 1851 | } |
| 1852 | |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1853 | func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 1854 | p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
| 1855 | |
| 1856 | p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs) |
| 1857 | |
| 1858 | rule := android.NewRuleBuilder() |
| 1859 | command := rule.Command(). |
| 1860 | BuiltTool(ctx, "soong_zip"). |
| 1861 | Flag("-write_if_changed"). |
| 1862 | Flag("-jar"). |
| 1863 | FlagWithOutput("-o ", p.stubsSrcJar) |
| 1864 | |
| 1865 | for _, d := range p.srcDirs { |
| 1866 | dir := d.String() |
| 1867 | command. |
| 1868 | FlagWithArg("-C ", dir). |
| 1869 | FlagWithInput("-D ", d) |
| 1870 | } |
| 1871 | |
| 1872 | rule.Restat() |
| 1873 | |
| 1874 | rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source") |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt { |
| 1878 | return &p.prebuilt |
| 1879 | } |
| 1880 | |
| 1881 | func (p *PrebuiltStubsSources) Name() string { |
| 1882 | return p.prebuilt.Name(p.ModuleBase.Name()) |
| 1883 | } |
| 1884 | |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1885 | // prebuilt_stubs_sources imports a set of java source files as if they were |
| 1886 | // generated by droidstubs. |
| 1887 | // |
| 1888 | // By default, a prebuilt_stubs_sources has a single variant that expects a |
| 1889 | // set of `.java` files generated by droidstubs. |
| 1890 | // |
| 1891 | // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one |
| 1892 | // for host modules. |
| 1893 | // |
| 1894 | // Intended only for use by sdk snapshots. |
| 1895 | func PrebuiltStubsSourcesFactory() android.Module { |
| 1896 | module := &PrebuiltStubsSources{} |
| 1897 | |
| 1898 | module.AddProperties(&module.properties) |
| 1899 | |
| 1900 | android.InitPrebuiltModule(module, &module.properties.Srcs) |
| 1901 | android.InitSdkAwareModule(module) |
| 1902 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 1903 | return module |
| 1904 | } |
| 1905 | |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1906 | type droidStubsSdkMemberType struct { |
Paul Duffin | 255f18e | 2019-12-13 11:22:16 +0000 | [diff] [blame] | 1907 | android.SdkMemberTypeBase |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { |
| 1911 | mctx.AddVariationDependencies(nil, dependencyTag, names...) |
| 1912 | } |
| 1913 | |
| 1914 | func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool { |
| 1915 | _, ok := module.(*Droidstubs) |
| 1916 | return ok |
| 1917 | } |
| 1918 | |
Paul Duffin | 495ffb9 | 2020-03-20 13:35:40 +0000 | [diff] [blame] | 1919 | func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { |
| 1920 | return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources") |
| 1921 | } |
| 1922 | |
| 1923 | func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { |
| 1924 | return &droidStubsInfoProperties{} |
| 1925 | } |
| 1926 | |
| 1927 | type droidStubsInfoProperties struct { |
| 1928 | android.SdkMemberPropertiesBase |
| 1929 | |
| 1930 | StubsSrcJar android.Path |
| 1931 | } |
| 1932 | |
| 1933 | func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { |
| 1934 | droidstubs := variant.(*Droidstubs) |
| 1935 | p.StubsSrcJar = droidstubs.stubsSrcJar |
| 1936 | } |
| 1937 | |
| 1938 | func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { |
| 1939 | if p.StubsSrcJar != nil { |
| 1940 | builder := ctx.SnapshotBuilder() |
| 1941 | |
| 1942 | snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources") |
| 1943 | |
| 1944 | builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir) |
| 1945 | |
| 1946 | propertySet.AddProperty("srcs", []string{snapshotRelativeDir}) |
Paul Duffin | 1387957 | 2019-11-28 14:31:38 +0000 | [diff] [blame] | 1947 | } |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 1948 | } |