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