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