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