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