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