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