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