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