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