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