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