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