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