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