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