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 ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java/config" |
| 20 | "fmt" |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 21 | "path/filepath" |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 22 | "runtime" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | javadoc = pctx.AndroidStaticRule("javadoc", |
| 30 | blueprint.RuleParams{ |
| 31 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 32 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 33 | `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 34 | `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` + |
| 35 | `-d $outDir -quiet && ` + |
| 36 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 37 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 38 | CommandDeps: []string{ |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 39 | "${config.ZipSyncCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 40 | "${config.JavadocCmd}", |
| 41 | "${config.SoongZipCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 42 | }, |
| 43 | Rspfile: "$out.rsp", |
| 44 | RspfileContent: "$in", |
| 45 | Restat: true, |
| 46 | }, |
Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 47 | "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 48 | "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "postDoclavaCmds") |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 49 | |
| 50 | apiCheck = pctx.AndroidStaticRule("apiCheck", |
| 51 | blueprint.RuleParams{ |
| 52 | Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` + |
| 53 | `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` + |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 54 | `&& touch $out ) || (echo -e "$msg" ; exit 38)`, |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 55 | CommandDeps: []string{ |
| 56 | "${config.ApiCheckCmd}", |
| 57 | }, |
| 58 | }, |
| 59 | "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg") |
| 60 | |
| 61 | updateApi = pctx.AndroidStaticRule("updateApi", |
| 62 | blueprint.RuleParams{ |
| 63 | Command: `( ( cp -f $apiFileToCheck $apiFile && cp -f $removedApiFileToCheck $removedApiFile ) ` + |
| 64 | `&& touch $out ) || (echo failed to update public API ; exit 38)`, |
| 65 | }, |
| 66 | "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck") |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 67 | |
| 68 | metalava = pctx.AndroidStaticRule("metalava", |
| 69 | blueprint.RuleParams{ |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 70 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` + |
| 71 | `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 72 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 73 | `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + |
Nan Zhang | 16c0a31 | 2018-06-13 17:42:48 -0700 | [diff] [blame] | 74 | `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` + |
| 75 | `--stubs $stubsDir $opts && ` + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 76 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
| 77 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, |
| 78 | CommandDeps: []string{ |
| 79 | "${config.ZipSyncCmd}", |
| 80 | "${config.JavaCmd}", |
| 81 | "${config.MetalavaJar}", |
| 82 | "${config.JavadocCmd}", |
| 83 | "${config.SoongZipCmd}", |
| 84 | }, |
| 85 | Rspfile: "$out.rsp", |
| 86 | RspfileContent: "$in", |
| 87 | Restat: true, |
| 88 | }, |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 89 | "outDir", "srcJarDir", "stubsDir", "docStubsDir", "srcJars", "javaVersion", "bootclasspathArgs", |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 90 | "classpathArgs", "sourcepath", "opts", "docZip") |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 91 | |
| 92 | metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck", |
| 93 | blueprint.RuleParams{ |
| 94 | Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` + |
| 95 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
| 96 | `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + |
| 97 | `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` + |
| 98 | `$opts && touch $out ) || ` + |
| 99 | `( echo -e "$msg" ; exit 38 )`, |
| 100 | CommandDeps: []string{ |
| 101 | "${config.ZipSyncCmd}", |
| 102 | "${config.JavaCmd}", |
| 103 | "${config.MetalavaJar}", |
| 104 | }, |
| 105 | Rspfile: "$out.rsp", |
| 106 | RspfileContent: "$in", |
| 107 | }, |
| 108 | "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "msg") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 109 | ) |
| 110 | |
| 111 | func init() { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 112 | android.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 113 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 114 | android.RegisterModuleType("droiddoc", DroiddocFactory) |
| 115 | android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 116 | android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 117 | android.RegisterModuleType("javadoc", JavadocFactory) |
| 118 | android.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 119 | } |
| 120 | |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 121 | var ( |
| 122 | srcsLibTag = dependencyTag{name: "sources from javalib"} |
| 123 | ) |
| 124 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 125 | type JavadocProperties struct { |
| 126 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 127 | // or .aidl files. |
| 128 | Srcs []string `android:"arch_variant"` |
| 129 | |
| 130 | // list of directories rooted at the Android.bp file that will |
| 131 | // 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] | 132 | Local_sourcepaths []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 133 | |
| 134 | // list of source files that should not be used to build the Java module. |
| 135 | // This is most useful in the arch/multilib variants to remove non-common files |
| 136 | // filegroup or genrule can be included within this property. |
| 137 | Exclude_srcs []string `android:"arch_variant"` |
| 138 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 139 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 140 | Libs []string `android:"arch_variant"` |
| 141 | |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 142 | // don't build against the framework libraries (legacy-test, core-junit, |
| 143 | // ext, and framework for device targets) |
| 144 | No_framework_libs *bool |
| 145 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 146 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 147 | Srcs_lib *string |
| 148 | |
| 149 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 150 | Srcs_lib_whitelist_dirs []string |
| 151 | |
| 152 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 153 | Srcs_lib_whitelist_pkgs []string |
| 154 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 155 | // 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] | 156 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 157 | |
| 158 | // if not blank, set to the version of the sdk to compile against |
| 159 | Sdk_version *string `android:"arch_variant"` |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 160 | |
| 161 | Aidl struct { |
| 162 | // Top level directories to pass to aidl tool |
| 163 | Include_dirs []string |
| 164 | |
| 165 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 166 | Local_include_dirs []string |
| 167 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 168 | |
| 169 | // If not blank, set the java version passed to javadoc as -source |
| 170 | Java_version *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 173 | type ApiToCheck struct { |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 174 | // path to the API txt file that the new API extracted from source code is checked |
| 175 | // against. The path can be local to the module or from other module (via :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 176 | Api_file *string |
| 177 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 178 | // path to the API txt file that the new @removed API extractd from source code is |
| 179 | // checked against. The path can be local to the module or from other module (via |
| 180 | // :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 181 | Removed_api_file *string |
| 182 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 183 | // Arguments to the apicheck tool. |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 184 | Args *string |
| 185 | } |
| 186 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 187 | type DroiddocProperties struct { |
| 188 | // 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] | 189 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 190 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 191 | // directories under current module source which contains html/jd files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 192 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 193 | |
| 194 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 195 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 196 | |
| 197 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 198 | // suitable for spell-checking and other goodness. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 199 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 200 | |
| 201 | // a todo file lists the program elements that are missing documentation. |
| 202 | // At some point, this might be improved to show more warnings. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 203 | Todo_file *string |
| 204 | |
| 205 | // directory under current module source that provide additional resources (images). |
| 206 | Resourcesdir *string |
| 207 | |
| 208 | // resources output directory under out/soong/.intermediates. |
| 209 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 210 | |
| 211 | // local files that are used within user customized droiddoc options. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 212 | Arg_files []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 213 | |
| 214 | // user customized droiddoc args. |
| 215 | // Available variables for substitution: |
| 216 | // |
| 217 | // $(location <label>): the path to the arg_files with name <label> |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 218 | Args *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 219 | |
| 220 | // names of the output files used in args that will be generated |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 221 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 222 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 223 | // if set to true, collect the values used by the Dev tools and |
| 224 | // write them in files packaged with the SDK. Defaults to false. |
| 225 | Write_sdk_values *bool |
| 226 | |
| 227 | // index.html under current module will be copied to docs out dir, if not null. |
| 228 | Static_doc_index_redirect *string |
| 229 | |
| 230 | // source.properties under current module will be copied to docs out dir, if not null. |
| 231 | Static_doc_properties *string |
| 232 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 233 | // a list of files under current module source dir which contains known tags in Java sources. |
| 234 | // filegroup or genrule can be included within this property. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 235 | Knowntags []string |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 236 | |
| 237 | // the tag name used to distinguish if the API files belong to public/system/test. |
| 238 | Api_tag_name *string |
| 239 | |
| 240 | // the generated public API filename by Doclava. |
| 241 | Api_filename *string |
| 242 | |
David Brazdil | fbe4cc3 | 2018-05-31 13:56:46 +0100 | [diff] [blame] | 243 | // the generated public Dex API filename by Doclava. |
| 244 | Dex_api_filename *string |
| 245 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 246 | // the generated private API filename by Doclava. |
| 247 | Private_api_filename *string |
| 248 | |
| 249 | // the generated private Dex API filename by Doclava. |
| 250 | Private_dex_api_filename *string |
| 251 | |
| 252 | // the generated removed API filename by Doclava. |
| 253 | Removed_api_filename *string |
| 254 | |
David Brazdil | aac0c3c | 2018-04-24 16:23:29 +0100 | [diff] [blame] | 255 | // the generated removed Dex API filename by Doclava. |
| 256 | Removed_dex_api_filename *string |
| 257 | |
Mathew Inwood | 76c3de1 | 2018-06-22 15:28:11 +0100 | [diff] [blame] | 258 | // mapping of dex signatures to source file and line number. This is a temporary property and |
| 259 | // will be deleted; you probably shouldn't be using it. |
| 260 | Dex_mapping_filename *string |
| 261 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 262 | // the generated exact API filename by Doclava. |
| 263 | Exact_api_filename *string |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 264 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 265 | // the generated proguard filename by Doclava. |
| 266 | Proguard_filename *string |
| 267 | |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 268 | // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true. |
| 269 | Create_stubs *bool |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 270 | |
| 271 | Check_api struct { |
| 272 | Last_released ApiToCheck |
| 273 | |
| 274 | Current ApiToCheck |
| 275 | } |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 276 | |
| 277 | // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is |
| 278 | // currently still used for documentation generation, and will be replaced by Dokka soon. |
| 279 | Metalava_enabled *bool |
| 280 | |
| 281 | // user can specify the version of previous released API file in order to do compatibility check. |
| 282 | Metalava_previous_api *string |
| 283 | |
| 284 | // is set to true, Metalava will allow framework SDK to contain annotations. |
| 285 | Metalava_annotations_enabled *bool |
| 286 | |
Pete Gillin | b13a015 | 2018-07-19 17:56:49 +0100 | [diff] [blame] | 287 | // a list of top-level directories containing files to merge annotations from. |
| 288 | Metalava_merge_annotations_dirs []string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 289 | |
| 290 | // if set to true, generate docs through Dokka instead of Doclava. Valid only when |
| 291 | // metalava_enabled is set to true. |
| 292 | Dokka_enabled *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 295 | // |
| 296 | // Common flags passed down to build rule |
| 297 | // |
| 298 | type droiddocBuilderFlags struct { |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 299 | args string |
| 300 | bootClasspathArgs string |
| 301 | classpathArgs string |
| 302 | dokkaClasspathArgs string |
| 303 | aidlFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 304 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 305 | doclavaStubsFlags string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 306 | doclavaDocsFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 307 | postDoclavaCmds string |
| 308 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 309 | metalavaStubsFlags string |
| 310 | metalavaAnnotationsFlags string |
| 311 | metalavaJavadocFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 312 | |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 313 | metalavaDokkaFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 317 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 318 | android.InitDefaultableModule(module) |
| 319 | } |
| 320 | |
| 321 | // |
| 322 | // Javadoc |
| 323 | // |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 324 | type Javadoc struct { |
| 325 | android.ModuleBase |
| 326 | android.DefaultableModuleBase |
| 327 | |
| 328 | properties JavadocProperties |
| 329 | |
| 330 | srcJars android.Paths |
| 331 | srcFiles android.Paths |
| 332 | sourcepaths android.Paths |
| 333 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 334 | docZip android.WritablePath |
| 335 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 338 | func (j *Javadoc) Srcs() android.Paths { |
| 339 | return android.Paths{j.stubsSrcJar} |
| 340 | } |
| 341 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 342 | func JavadocFactory() android.Module { |
| 343 | module := &Javadoc{} |
| 344 | |
| 345 | module.AddProperties(&module.properties) |
| 346 | |
| 347 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 348 | return module |
| 349 | } |
| 350 | |
| 351 | func JavadocHostFactory() android.Module { |
| 352 | module := &Javadoc{} |
| 353 | |
| 354 | module.AddProperties(&module.properties) |
| 355 | |
| 356 | InitDroiddocModule(module, android.HostSupported) |
| 357 | return module |
| 358 | } |
| 359 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 360 | var _ android.SourceFileProducer = (*Javadoc)(nil) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 361 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 362 | func (j *Javadoc) sdkVersion() string { |
| 363 | return String(j.properties.Sdk_version) |
| 364 | } |
| 365 | |
| 366 | func (j *Javadoc) minSdkVersion() string { |
| 367 | return j.sdkVersion() |
| 368 | } |
| 369 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 370 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 371 | if ctx.Device() { |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 372 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 373 | if sdkDep.useDefaultLibs { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 374 | ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 375 | if ctx.Config().TargetOpenJDK9() { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 376 | ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 377 | } |
Nan Zhang | 9cbe677 | 2018-03-21 17:56:39 -0700 | [diff] [blame] | 378 | if !Bool(j.properties.No_framework_libs) { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 379 | ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 380 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 381 | } else if sdkDep.useModule { |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 382 | if ctx.Config().TargetOpenJDK9() { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 383 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 384 | } |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 385 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 389 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 390 | if j.properties.Srcs_lib != nil { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame^] | 391 | ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib) |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 392 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 393 | |
| 394 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
| 395 | |
| 396 | // exclude_srcs may contain filegroup or genrule. |
| 397 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
| 398 | } |
| 399 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 400 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { |
| 401 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { |
| 402 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 403 | // convert foo.bar.baz to foo/bar/baz |
| 404 | pkgAsPath := filepath.Join(strings.Split(pkg, ".")...) |
| 405 | prefix := filepath.Join(dir, pkgAsPath) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 406 | if _, found := whitelistPathPrefixes[prefix]; !found { |
| 407 | whitelistPathPrefixes[prefix] = true |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 413 | func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { |
| 414 | var flags droiddocBuilderFlags |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 415 | |
| 416 | // aidl flags. |
| 417 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
| 418 | if len(aidlFlags) > 0 { |
| 419 | // optimization. |
| 420 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 421 | flags.aidlFlags = "$aidlFlags" |
| 422 | } |
| 423 | |
| 424 | return flags |
| 425 | } |
| 426 | |
| 427 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
| 428 | aidlIncludeDirs android.Paths) []string { |
| 429 | |
| 430 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) |
| 431 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) |
| 432 | |
| 433 | var flags []string |
| 434 | if aidlPreprocess.Valid() { |
| 435 | flags = append(flags, "-p"+aidlPreprocess.String()) |
| 436 | } else { |
| 437 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
| 438 | } |
| 439 | |
| 440 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 441 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 442 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
| 443 | flags = append(flags, "-I"+src.String()) |
| 444 | } |
| 445 | |
| 446 | return flags |
| 447 | } |
| 448 | |
| 449 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 450 | flags droiddocBuilderFlags) android.Paths { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 451 | |
| 452 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 453 | |
| 454 | for _, srcFile := range srcFiles { |
| 455 | switch srcFile.Ext() { |
| 456 | case ".aidl": |
| 457 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 458 | outSrcFiles = append(outSrcFiles, javaFile) |
| 459 | default: |
| 460 | outSrcFiles = append(outSrcFiles, srcFile) |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | return outSrcFiles |
| 465 | } |
| 466 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 467 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 468 | var deps deps |
| 469 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 470 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 471 | if sdkDep.invalidVersion { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 472 | ctx.AddMissingDependencies(sdkDep.modules) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 473 | } else if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 474 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | ctx.VisitDirectDeps(func(module android.Module) { |
| 478 | otherName := ctx.OtherModuleName(module) |
| 479 | tag := ctx.OtherModuleDependencyTag(module) |
| 480 | |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 481 | switch tag { |
| 482 | case bootClasspathTag: |
| 483 | if dep, ok := module.(Dependency); ok { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 484 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 485 | } else { |
| 486 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 487 | } |
| 488 | case libTag: |
| 489 | switch dep := module.(type) { |
| 490 | case Dependency: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 491 | deps.classpath = append(deps.classpath, dep.ImplementationJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 492 | case SdkLibraryDependency: |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 493 | sdkVersion := j.sdkVersion() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 494 | linkType := javaSdk |
| 495 | if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") { |
| 496 | linkType = javaSystem |
| 497 | } else if sdkVersion == "" { |
| 498 | linkType = javaPlatform |
| 499 | } |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 500 | deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 501 | case android.SourceFileProducer: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 502 | checkProducesJars(ctx, dep) |
| 503 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 504 | default: |
| 505 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 506 | } |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 507 | case srcsLibTag: |
| 508 | switch dep := module.(type) { |
| 509 | case Dependency: |
| 510 | srcs := dep.(SrcDependency).CompiledSrcs() |
| 511 | whitelistPathPrefixes := make(map[string]bool) |
| 512 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) |
| 513 | for _, src := range srcs { |
| 514 | if _, ok := src.(android.WritablePath); ok { // generated sources |
| 515 | deps.srcs = append(deps.srcs, src) |
| 516 | } else { // select source path for documentation based on whitelist path prefixs. |
| 517 | for k, _ := range whitelistPathPrefixes { |
| 518 | if strings.HasPrefix(src.Rel(), k) { |
| 519 | deps.srcs = append(deps.srcs, src) |
| 520 | break |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) |
| 526 | default: |
| 527 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 528 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 529 | case systemModulesTag: |
| 530 | if deps.systemModules != nil { |
| 531 | panic("Found two system module dependencies") |
| 532 | } |
| 533 | sm := module.(*SystemModules) |
| 534 | if sm.outputFile == nil { |
| 535 | panic("Missing directory for system module dependency") |
| 536 | } |
| 537 | deps.systemModules = sm.outputFile |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 538 | } |
| 539 | }) |
| 540 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 541 | // may contain filegroup or genrule. |
| 542 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 543 | flags := j.collectAidlFlags(ctx, deps) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 544 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 545 | |
| 546 | // srcs may depend on some genrule output. |
| 547 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 548 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 549 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 550 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 551 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 552 | |
| 553 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 554 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 555 | |
| 556 | if j.properties.Local_sourcepaths == nil { |
| 557 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") |
| 558 | } |
| 559 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 560 | |
| 561 | return deps |
| 562 | } |
| 563 | |
| 564 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 565 | j.addDeps(ctx) |
| 566 | } |
| 567 | |
| 568 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 569 | deps := j.collectDeps(ctx) |
| 570 | |
| 571 | var implicits android.Paths |
| 572 | implicits = append(implicits, deps.bootClasspath...) |
| 573 | implicits = append(implicits, deps.classpath...) |
| 574 | |
| 575 | var bootClasspathArgs, classpathArgs string |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 576 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 577 | javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 578 | if len(deps.bootClasspath) > 0 { |
| 579 | var systemModules classpath |
| 580 | if deps.systemModules != nil { |
| 581 | systemModules = append(systemModules, deps.systemModules) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 582 | } |
Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 583 | bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device()) |
| 584 | bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=." |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 585 | } |
| 586 | if len(deps.classpath.Strings()) > 0 { |
| 587 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 588 | } |
| 589 | |
| 590 | implicits = append(implicits, j.srcJars...) |
| 591 | |
Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 592 | opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 593 | |
| 594 | ctx.Build(pctx, android.BuildParams{ |
| 595 | Rule: javadoc, |
| 596 | Description: "Javadoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 597 | Output: j.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 598 | ImplicitOutput: j.docZip, |
| 599 | Inputs: j.srcFiles, |
| 600 | Implicits: implicits, |
| 601 | Args: map[string]string{ |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 602 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 603 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 604 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 605 | "srcJars": strings.Join(j.srcJars.Strings(), " "), |
| 606 | "opts": opts, |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 607 | "bootclasspathArgs": bootClasspathArgs, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 608 | "classpathArgs": classpathArgs, |
| 609 | "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"), |
| 610 | "docZip": j.docZip.String(), |
| 611 | }, |
| 612 | }) |
| 613 | } |
| 614 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 615 | // |
| 616 | // Droiddoc |
| 617 | // |
| 618 | type Droiddoc struct { |
| 619 | Javadoc |
| 620 | |
| 621 | properties DroiddocProperties |
| 622 | apiFile android.WritablePath |
| 623 | dexApiFile android.WritablePath |
| 624 | privateApiFile android.WritablePath |
| 625 | privateDexApiFile android.WritablePath |
| 626 | removedApiFile android.WritablePath |
| 627 | removedDexApiFile android.WritablePath |
| 628 | exactApiFile android.WritablePath |
| 629 | apiMappingFile android.WritablePath |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 630 | proguardFile android.WritablePath |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 631 | |
| 632 | checkCurrentApiTimestamp android.WritablePath |
| 633 | updateCurrentApiTimestamp android.WritablePath |
| 634 | checkLastReleasedApiTimestamp android.WritablePath |
| 635 | |
| 636 | annotationsZip android.WritablePath |
| 637 | |
| 638 | apiFilePath android.Path |
| 639 | } |
| 640 | |
| 641 | type ApiFilePath interface { |
| 642 | ApiFilePath() android.Path |
| 643 | } |
| 644 | |
| 645 | func DroiddocFactory() android.Module { |
| 646 | module := &Droiddoc{} |
| 647 | |
| 648 | module.AddProperties(&module.properties, |
| 649 | &module.Javadoc.properties) |
| 650 | |
| 651 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 652 | return module |
| 653 | } |
| 654 | |
| 655 | func DroiddocHostFactory() android.Module { |
| 656 | module := &Droiddoc{} |
| 657 | |
| 658 | module.AddProperties(&module.properties, |
| 659 | &module.Javadoc.properties) |
| 660 | |
| 661 | InitDroiddocModule(module, android.HostSupported) |
| 662 | return module |
| 663 | } |
| 664 | |
| 665 | func (d *Droiddoc) ApiFilePath() android.Path { |
| 666 | return d.apiFilePath |
| 667 | } |
| 668 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 669 | func (d *Droiddoc) checkCurrentApi() bool { |
| 670 | if String(d.properties.Check_api.Current.Api_file) != "" && |
| 671 | String(d.properties.Check_api.Current.Removed_api_file) != "" { |
| 672 | return true |
| 673 | } else if String(d.properties.Check_api.Current.Api_file) != "" { |
| 674 | panic("check_api.current.removed_api_file: has to be non empty!") |
| 675 | } else if String(d.properties.Check_api.Current.Removed_api_file) != "" { |
| 676 | panic("check_api.current.api_file: has to be non empty!") |
| 677 | } |
| 678 | |
| 679 | return false |
| 680 | } |
| 681 | |
| 682 | func (d *Droiddoc) checkLastReleasedApi() bool { |
| 683 | if String(d.properties.Check_api.Last_released.Api_file) != "" && |
| 684 | String(d.properties.Check_api.Last_released.Removed_api_file) != "" { |
| 685 | return true |
| 686 | } else if String(d.properties.Check_api.Last_released.Api_file) != "" { |
| 687 | panic("check_api.last_released.removed_api_file: has to be non empty!") |
| 688 | } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" { |
| 689 | panic("check_api.last_released.api_file: has to be non empty!") |
| 690 | } |
| 691 | |
| 692 | return false |
| 693 | } |
| 694 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 695 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 696 | d.Javadoc.addDeps(ctx) |
| 697 | |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 698 | if String(d.properties.Custom_template) != "" { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 699 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 700 | } |
| 701 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 702 | // arg_files may contains filegroup or genrule. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 703 | android.ExtractSourcesDeps(ctx, d.properties.Arg_files) |
| 704 | |
| 705 | // knowntags may contain filegroup or genrule. |
| 706 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 707 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 708 | if String(d.properties.Static_doc_index_redirect) != "" { |
| 709 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect) |
| 710 | } |
| 711 | |
| 712 | if String(d.properties.Static_doc_properties) != "" { |
| 713 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties) |
| 714 | } |
| 715 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 716 | if d.checkCurrentApi() { |
| 717 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) |
| 718 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) |
| 719 | } |
| 720 | |
| 721 | if d.checkLastReleasedApi() { |
| 722 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) |
| 723 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) |
| 724 | } |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 725 | |
| 726 | if String(d.properties.Metalava_previous_api) != "" { |
| 727 | android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api) |
| 728 | } |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 729 | |
| 730 | if len(d.properties.Metalava_merge_annotations_dirs) != 0 { |
| 731 | for _, mergeAnnotationsDir := range d.properties.Metalava_merge_annotations_dirs { |
| 732 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) |
| 733 | } |
| 734 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 737 | func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, |
| 738 | deps deps) (droiddocBuilderFlags, error) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 739 | var flags droiddocBuilderFlags |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 740 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 741 | *implicits = append(*implicits, deps.bootClasspath...) |
| 742 | *implicits = append(*implicits, deps.classpath...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 743 | |
Nan Zhang | c94f9d8 | 2018-06-26 10:02:26 -0700 | [diff] [blame] | 744 | // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled |
| 745 | // since it doesn't support system modules yet. |
| 746 | if len(deps.bootClasspath.Strings()) > 0 { |
| 747 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 748 | flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 749 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 750 | flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath") |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 751 | // Dokka doesn't support boocClasspath, so combine these two classpath vars for Dokka. |
| 752 | dokkaClasspath := classpath{} |
| 753 | dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...) |
| 754 | dokkaClasspath = append(dokkaClasspath, deps.classpath...) |
| 755 | flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath") |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 756 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 757 | argFiles := ctx.ExpandSources(d.properties.Arg_files, nil) |
| 758 | argFilesMap := map[string]android.Path{} |
| 759 | |
| 760 | for _, f := range argFiles { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 761 | *implicits = append(*implicits, f) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 762 | if _, exists := argFilesMap[f.Rel()]; !exists { |
| 763 | argFilesMap[f.Rel()] = f |
| 764 | } else { |
| 765 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
| 766 | f, argFilesMap[f.Rel()], f.Rel()) |
| 767 | } |
| 768 | } |
| 769 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 770 | var err error |
| 771 | flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 772 | if strings.HasPrefix(name, "location ") { |
| 773 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 774 | if f, ok := argFilesMap[label]; ok { |
| 775 | return f.String(), nil |
| 776 | } else { |
| 777 | return "", fmt.Errorf("unknown location label %q", label) |
| 778 | } |
| 779 | } else if name == "genDir" { |
| 780 | return android.PathForModuleGen(ctx).String(), nil |
| 781 | } |
| 782 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 783 | }) |
| 784 | |
| 785 | if err != nil { |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 786 | ctx.PropertyErrorf("args", "%s", err.Error()) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 787 | return droiddocBuilderFlags{}, err |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 788 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 789 | return flags, nil |
| 790 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 791 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 792 | func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths, |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 793 | jsilver, doclava android.Path) string { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 794 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 795 | *implicits = append(*implicits, jsilver) |
| 796 | *implicits = append(*implicits, doclava) |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 797 | |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 798 | var date string |
| 799 | if runtime.GOOS == "darwin" { |
| 800 | date = `date -r` |
| 801 | } else { |
| 802 | date = `date -d` |
| 803 | } |
| 804 | |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 805 | // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9 |
| 806 | // sources, droiddoc will get sources produced by metalava which will have already stripped out the |
| 807 | // 1.9 language features. |
| 808 | args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 809 | "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 810 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 811 | `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" ` |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 812 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 813 | if String(d.properties.Custom_template) == "" { |
| 814 | // TODO: This is almost always droiddoc-templates-sdk |
| 815 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 816 | } |
| 817 | |
| 818 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 819 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 820 | *implicits = append(*implicits, t.deps...) |
| 821 | args = args + " -templatedir " + t.dir.String() |
| 822 | } else { |
| 823 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) |
| 824 | } |
| 825 | }) |
| 826 | |
| 827 | if len(d.properties.Html_dirs) > 0 { |
| 828 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 829 | *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) |
| 830 | args = args + " -htmldir " + htmlDir.String() |
| 831 | } |
| 832 | |
| 833 | if len(d.properties.Html_dirs) > 1 { |
| 834 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 835 | *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) |
| 836 | args = args + " -htmldir2 " + htmlDir2.String() |
| 837 | } |
| 838 | |
| 839 | if len(d.properties.Html_dirs) > 2 { |
| 840 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
| 841 | } |
| 842 | |
| 843 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) |
| 844 | *implicits = append(*implicits, knownTags...) |
| 845 | |
| 846 | for _, kt := range knownTags { |
| 847 | args = args + " -knowntags " + kt.String() |
| 848 | } |
| 849 | |
| 850 | for _, hdf := range d.properties.Hdf { |
| 851 | args = args + " -hdf " + hdf |
| 852 | } |
| 853 | |
| 854 | if String(d.properties.Proofread_file) != "" { |
| 855 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
| 856 | args = args + " -proofread " + proofreadFile.String() |
| 857 | } |
| 858 | |
| 859 | if String(d.properties.Todo_file) != "" { |
| 860 | // tricky part: |
| 861 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 862 | // the non-standard doclet will get the full path relative to "-o". |
| 863 | args = args + " -todo " + String(d.properties.Todo_file) |
| 864 | } |
| 865 | |
| 866 | if String(d.properties.Resourcesdir) != "" { |
| 867 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 868 | // resourcesDir is one sub dir of htmlDir |
| 869 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
| 870 | args = args + " -resourcesdir " + resourcesDir.String() |
| 871 | } |
| 872 | |
| 873 | if String(d.properties.Resourcesoutdir) != "" { |
| 874 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
| 875 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) |
| 876 | } |
| 877 | return args |
| 878 | } |
| 879 | |
| 880 | func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) { |
| 881 | var doclavaFlags, MetalavaFlags string |
| 882 | if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" { |
| 883 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") |
| 884 | doclavaFlags += " -api " + d.apiFile.String() |
| 885 | MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String() |
| 886 | *implicitOutputs = append(*implicitOutputs, d.apiFile) |
| 887 | d.apiFilePath = d.apiFile |
| 888 | } |
| 889 | |
| 890 | if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" { |
| 891 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") |
| 892 | doclavaFlags += " -removedApi " + d.removedApiFile.String() |
| 893 | MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String() |
| 894 | *implicitOutputs = append(*implicitOutputs, d.removedApiFile) |
| 895 | } |
| 896 | |
| 897 | if String(d.properties.Private_api_filename) != "" { |
| 898 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) |
| 899 | doclavaFlags += " -privateApi " + d.privateApiFile.String() |
| 900 | MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String() |
| 901 | *implicitOutputs = append(*implicitOutputs, d.privateApiFile) |
| 902 | } |
| 903 | |
| 904 | if String(d.properties.Dex_api_filename) != "" { |
| 905 | d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) |
| 906 | doclavaFlags += " -dexApi " + d.dexApiFile.String() |
Nan Zhang | aa43b94 | 2018-08-21 16:24:38 -0700 | [diff] [blame] | 907 | MetalavaFlags += " --dex-api " + d.dexApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 908 | *implicitOutputs = append(*implicitOutputs, d.dexApiFile) |
| 909 | } |
| 910 | |
| 911 | if String(d.properties.Private_dex_api_filename) != "" { |
| 912 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) |
| 913 | doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String() |
| 914 | MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String() |
| 915 | *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile) |
| 916 | } |
| 917 | |
| 918 | if String(d.properties.Removed_dex_api_filename) != "" { |
| 919 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) |
| 920 | doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String() |
| 921 | MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String() |
| 922 | *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile) |
| 923 | } |
| 924 | |
| 925 | if String(d.properties.Exact_api_filename) != "" { |
| 926 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) |
| 927 | doclavaFlags += " -exactApi " + d.exactApiFile.String() |
| 928 | MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String() |
| 929 | *implicitOutputs = append(*implicitOutputs, d.exactApiFile) |
| 930 | } |
| 931 | |
| 932 | if String(d.properties.Dex_mapping_filename) != "" { |
| 933 | d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) |
| 934 | doclavaFlags += " -apiMapping " + d.apiMappingFile.String() |
| 935 | // Omitted: metalava support |
| 936 | *implicitOutputs = append(*implicitOutputs, d.apiMappingFile) |
| 937 | } |
| 938 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 939 | if String(d.properties.Proguard_filename) != "" { |
| 940 | d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename)) |
| 941 | doclavaFlags += " -proguard " + d.proguardFile.String() |
| 942 | // Omitted: metalava support |
| 943 | *implicitOutputs = append(*implicitOutputs, d.proguardFile) |
| 944 | } |
| 945 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 946 | if BoolDefault(d.properties.Create_stubs, true) { |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 947 | doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | if Bool(d.properties.Write_sdk_values) { |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 951 | doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 952 | } |
| 953 | return doclavaFlags, MetalavaFlags |
| 954 | } |
| 955 | |
| 956 | func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string { |
| 957 | var cmds string |
| 958 | if String(d.properties.Static_doc_index_redirect) != "" { |
| 959 | static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect), |
| 960 | "static_doc_index_redirect") |
| 961 | *implicits = append(*implicits, static_doc_index_redirect) |
| 962 | cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " + |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 963 | android.PathForModuleOut(ctx, "out", "index.html").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | if String(d.properties.Static_doc_properties) != "" { |
| 967 | static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties), |
| 968 | "static_doc_properties") |
| 969 | *implicits = append(*implicits, static_doc_properties) |
| 970 | cmds = cmds + " && cp " + static_doc_properties.String() + " " + |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 971 | android.PathForModuleOut(ctx, "out", "source.properties").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 972 | } |
| 973 | return cmds |
| 974 | } |
| 975 | |
| 976 | func (d *Droiddoc) collectMetalavaAnnotationsFlags( |
| 977 | ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string { |
| 978 | var flags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 979 | if Bool(d.properties.Metalava_annotations_enabled) { |
| 980 | if String(d.properties.Metalava_previous_api) == "" { |
| 981 | ctx.PropertyErrorf("metalava_previous_api", |
| 982 | "has to be non-empty if annotations was enabled!") |
| 983 | } |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 984 | previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api), |
| 985 | "metalava_previous_api") |
| 986 | *implicits = append(*implicits, previousApi) |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 987 | |
Nan Zhang | d05a436 | 2018-08-15 13:28:54 -0700 | [diff] [blame] | 988 | flags += " --include-annotations --migrate-nullness " + previousApi.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 989 | |
| 990 | d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip") |
| 991 | *implicitOutputs = append(*implicitOutputs, d.annotationsZip) |
| 992 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 993 | flags += " --extract-annotations " + d.annotationsZip.String() |
| 994 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 995 | if len(d.properties.Metalava_merge_annotations_dirs) == 0 { |
| 996 | ctx.PropertyErrorf("metalava_merge_annotations_dirs", |
| 997 | "has to be non-empty if annotations was enabled!") |
| 998 | } |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 999 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { |
| 1000 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1001 | *implicits = append(*implicits, t.deps...) |
| 1002 | flags += " --merge-annotations " + t.dir.String() |
| 1003 | } else { |
| 1004 | ctx.PropertyErrorf("metalava_merge_annotations_dirs", |
| 1005 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 1006 | } |
| 1007 | }) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1008 | // TODO(tnorbye): find owners to fix these warnings when annotation was enabled. |
| 1009 | flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction " |
| 1010 | } |
| 1011 | |
| 1012 | return flags |
| 1013 | } |
| 1014 | |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1015 | func (d *Droiddoc) collectMetalavaJavadocFlags(ctx android.ModuleContext, |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1016 | bootClasspathArgs, classpathArgs, outDir, docStubsDir string) string { |
| 1017 | return " --doc-stubs " + docStubsDir + |
| 1018 | " --write-doc-stubs-source-list " + android.PathForModuleOut(ctx, "doc_stubs.srclist").String() + |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1019 | " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " + |
| 1020 | bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " + |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1021 | docStubsDir + " -quiet -d " + outDir |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1024 | func (d *Droiddoc) collectMetalavaDokkaFlags(ctx android.ModuleContext, implicits *android.Paths, |
| 1025 | classpathArgs, outDir, docStubsDir string) string { |
| 1026 | dokka := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "dokka.jar") |
| 1027 | *implicits = append(*implicits, dokka) |
| 1028 | |
| 1029 | return " --doc-stubs " + docStubsDir + " --write-doc-stubs-source-list " + |
| 1030 | android.PathForModuleOut(ctx, "doc_stubs.srclist").String() + |
| 1031 | " --generate-documentation ${config.JavaCmd} -jar " + dokka.String() + " " + |
| 1032 | docStubsDir + " " + classpathArgs + " -format dac -dacRoot /reference/kotlin -output " + outDir |
| 1033 | } |
| 1034 | |
| 1035 | func (d *Droiddoc) transformMetalava(ctx android.ModuleContext, implicits android.Paths, |
| 1036 | implicitOutputs android.WritablePaths, outDir, docStubsDir, javaVersion, |
| 1037 | bootclasspathArgs, classpathArgs, opts string) { |
| 1038 | ctx.Build(pctx, android.BuildParams{ |
| 1039 | Rule: metalava, |
| 1040 | Description: "Metalava", |
| 1041 | Output: d.Javadoc.stubsSrcJar, |
| 1042 | Inputs: d.Javadoc.srcFiles, |
| 1043 | Implicits: implicits, |
| 1044 | ImplicitOutputs: implicitOutputs, |
| 1045 | Args: map[string]string{ |
| 1046 | "outDir": outDir, |
| 1047 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1048 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
| 1049 | "docStubsDir": docStubsDir, |
| 1050 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1051 | "javaVersion": javaVersion, |
| 1052 | "bootclasspathArgs": bootclasspathArgs, |
| 1053 | "classpathArgs": classpathArgs, |
| 1054 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 1055 | "docZip": d.Javadoc.docZip.String(), |
| 1056 | "opts": opts, |
| 1057 | }, |
| 1058 | }) |
| 1059 | } |
| 1060 | |
| 1061 | func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths, |
| 1062 | implicitOutputs android.WritablePaths, bootclasspathArgs, classpathArgs, opts, postDoclavaCmds string) { |
| 1063 | ctx.Build(pctx, android.BuildParams{ |
| 1064 | Rule: javadoc, |
| 1065 | Description: "Doclava", |
| 1066 | Output: d.Javadoc.stubsSrcJar, |
| 1067 | Inputs: d.Javadoc.srcFiles, |
| 1068 | Implicits: implicits, |
| 1069 | ImplicitOutputs: implicitOutputs, |
| 1070 | Args: map[string]string{ |
| 1071 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 1072 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1073 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
| 1074 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1075 | "opts": opts, |
| 1076 | "bootclasspathArgs": bootclasspathArgs, |
| 1077 | "classpathArgs": classpathArgs, |
| 1078 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 1079 | "docZip": d.Javadoc.docZip.String(), |
| 1080 | "postDoclavaCmds": postDoclavaCmds, |
| 1081 | }, |
| 1082 | }) |
| 1083 | } |
| 1084 | |
| 1085 | func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path, |
| 1086 | checkApiClasspath classpath, msg, opts string, output android.WritablePath) { |
| 1087 | ctx.Build(pctx, android.BuildParams{ |
| 1088 | Rule: apiCheck, |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1089 | Description: "Doclava Check API", |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1090 | Output: output, |
| 1091 | Inputs: nil, |
| 1092 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 1093 | checkApiClasspath...), |
| 1094 | Args: map[string]string{ |
| 1095 | "classpath": checkApiClasspath.FormJavaClassPath(""), |
| 1096 | "opts": opts, |
| 1097 | "apiFile": apiFile.String(), |
| 1098 | "apiFileToCheck": d.apiFile.String(), |
| 1099 | "removedApiFile": removedApiFile.String(), |
| 1100 | "removedApiFileToCheck": d.removedApiFile.String(), |
Colin Cross | 86bc9d4 | 2018-08-29 15:36:33 -0700 | [diff] [blame] | 1101 | "msg": msg, |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1102 | }, |
| 1103 | }) |
| 1104 | } |
| 1105 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1106 | func (d *Droiddoc) transformMetalavaCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path, |
| 1107 | implicits android.Paths, javaVersion, bootclasspathArgs, classpathArgs, opts, msg string, |
| 1108 | output android.WritablePath) { |
| 1109 | ctx.Build(pctx, android.BuildParams{ |
| 1110 | Rule: metalavaApiCheck, |
| 1111 | Description: "Metalava Check API", |
| 1112 | Output: output, |
| 1113 | Inputs: d.Javadoc.srcFiles, |
| 1114 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 1115 | implicits...), |
| 1116 | Args: map[string]string{ |
| 1117 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1118 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1119 | "javaVersion": javaVersion, |
| 1120 | "bootclasspathArgs": bootclasspathArgs, |
| 1121 | "classpathArgs": classpathArgs, |
| 1122 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 1123 | "opts": opts, |
| 1124 | "msg": msg, |
| 1125 | }, |
| 1126 | }) |
| 1127 | } |
| 1128 | |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1129 | func (d *Droiddoc) transformUpdateApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path, |
| 1130 | output android.WritablePath) { |
| 1131 | ctx.Build(pctx, android.BuildParams{ |
| 1132 | Rule: updateApi, |
| 1133 | Description: "Update API", |
| 1134 | Output: output, |
| 1135 | Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile), |
| 1136 | Args: map[string]string{ |
| 1137 | "apiFile": apiFile.String(), |
| 1138 | "apiFileToCheck": d.apiFile.String(), |
| 1139 | "removedApiFile": removedApiFile.String(), |
| 1140 | "removedApiFileToCheck": d.removedApiFile.String(), |
| 1141 | }, |
| 1142 | }) |
| 1143 | } |
| 1144 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1145 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1146 | deps := d.Javadoc.collectDeps(ctx) |
| 1147 | |
| 1148 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d)) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1149 | jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") |
| 1150 | doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") |
| 1151 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 1152 | checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")} |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1153 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1154 | var implicits android.Paths |
| 1155 | implicits = append(implicits, d.Javadoc.srcJars...) |
| 1156 | |
| 1157 | var implicitOutputs android.WritablePaths |
| 1158 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) |
| 1159 | for _, o := range d.properties.Out { |
| 1160 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 1161 | } |
| 1162 | |
| 1163 | flags, err := d.initBuilderFlags(ctx, &implicits, deps) |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1164 | metalavaCheckApiImplicits := implicits |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1165 | if err != nil { |
| 1166 | return |
| 1167 | } |
| 1168 | |
| 1169 | flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs) |
| 1170 | if Bool(d.properties.Metalava_enabled) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1171 | flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs) |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1172 | outDir := android.PathForModuleOut(ctx, "out").String() |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1173 | docStubsDir := android.PathForModuleOut(ctx, "docStubsDir").String() |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1174 | // TODO(nanzhang): Add a Soong property to handle documentation args. |
| 1175 | if strings.Contains(flags.args, "--generate-documentation") { // enable docs generation |
| 1176 | if Bool(d.properties.Dokka_enabled) { |
| 1177 | flags.metalavaDokkaFlags = d.collectMetalavaDokkaFlags(ctx, &implicits, |
| 1178 | flags.dokkaClasspathArgs, outDir, docStubsDir) |
| 1179 | d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion, |
| 1180 | flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+ |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1181 | flags.metalavaAnnotationsFlags+" "+ |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1182 | strings.Split(flags.args, "--generate-documentation")[0]+ |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1183 | flags.metalavaDokkaFlags+" "+strings.Split(flags.args, "--generate-documentation")[1]) |
| 1184 | } else { |
| 1185 | flags.metalavaJavadocFlags = d.collectMetalavaJavadocFlags( |
| 1186 | ctx, flags.bootClasspathArgs, flags.classpathArgs, outDir, docStubsDir) |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 1187 | flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava) |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1188 | d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion, |
| 1189 | flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+ |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1190 | flags.metalavaAnnotationsFlags+" "+ |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1191 | strings.Split(flags.args, "--generate-documentation")[0]+ |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1192 | flags.metalavaJavadocFlags+flags.doclavaDocsFlags+ |
| 1193 | " "+strings.Split(flags.args, "--generate-documentation")[1]) |
| 1194 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1195 | } else { |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1196 | d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion, |
| 1197 | flags.bootClasspathArgs, flags.classpathArgs, |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1198 | flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+flags.args) |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 1199 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1200 | } else { |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 1201 | flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1202 | flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits) |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1203 | d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs, |
| 1204 | flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+flags.args, |
| 1205 | flags.postDoclavaCmds) |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 1206 | } |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1207 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1208 | if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1209 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), |
| 1210 | "check_api.current.api_file") |
| 1211 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), |
| 1212 | "check_api.current_removed_api_file") |
| 1213 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1214 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") |
Nan Zhang | 55e0bf4 | 2018-08-16 16:23:11 -0700 | [diff] [blame] | 1215 | if !Bool(d.properties.Metalava_enabled) { |
Nan Zhang | 55e0bf4 | 2018-08-16 16:23:11 -0700 | [diff] [blame] | 1216 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, |
| 1217 | fmt.Sprintf(`\n******************************\n`+ |
| 1218 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1219 | `To make these errors go away, you have two choices:\n`+ |
| 1220 | ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ |
| 1221 | ` errors above.\n\n`+ |
| 1222 | ` 2. You can update current.txt by executing the following command:\n`+ |
| 1223 | ` make %s-update-current-api\n\n`+ |
| 1224 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1225 | ` you will need approval.\n`+ |
| 1226 | `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args), |
| 1227 | d.checkCurrentApiTimestamp) |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1228 | } else { |
| 1229 | opts := flags.args + " --check-compatibility:api:current " + apiFile.String() + |
| 1230 | " --check-compatibility:removed:current " + removedApiFile.String() + " " |
| 1231 | |
| 1232 | d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, |
| 1233 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts, |
| 1234 | fmt.Sprintf(`\n******************************\n`+ |
| 1235 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1236 | `To make these errors go away, you have two choices:\n`+ |
| 1237 | ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ |
| 1238 | ` errors above.\n\n`+ |
| 1239 | ` 2. You can update current.txt by executing the following command:\n`+ |
| 1240 | ` make %s-update-current-api\n\n`+ |
| 1241 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1242 | ` you will need approval.\n`+ |
| 1243 | `******************************\n`, ctx.ModuleName()), |
| 1244 | d.checkCurrentApiTimestamp) |
Nan Zhang | 55e0bf4 | 2018-08-16 16:23:11 -0700 | [diff] [blame] | 1245 | } |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1246 | |
| 1247 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1248 | d.transformUpdateApi(ctx, apiFile, removedApiFile, d.updateCurrentApiTimestamp) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1249 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1250 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1251 | if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1252 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), |
| 1253 | "check_api.last_released.api_file") |
| 1254 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), |
| 1255 | "check_api.last_released.removed_api_file") |
| 1256 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1257 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1258 | if !Bool(d.properties.Metalava_enabled) { |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1259 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, |
| 1260 | `\n******************************\n`+ |
| 1261 | `You have tried to change the API from what has been previously released in\n`+ |
| 1262 | `an SDK. Please fix the errors listed above.\n`+ |
| 1263 | `******************************\n`, String(d.properties.Check_api.Last_released.Args), |
| 1264 | d.checkLastReleasedApiTimestamp) |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1265 | } else { |
| 1266 | opts := flags.args + " --check-compatibility:api:released " + apiFile.String() + |
| 1267 | " --check-compatibility:removed:released " + removedApiFile.String() + " " |
| 1268 | |
| 1269 | d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, |
| 1270 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts, |
| 1271 | `\n******************************\n`+ |
| 1272 | `You have tried to change the API from what has been previously released in\n`+ |
| 1273 | `an SDK. Please fix the errors listed above.\n`+ |
| 1274 | `******************************\n`, |
| 1275 | d.checkLastReleasedApiTimestamp) |
Nan Zhang | a05ff57 | 2018-08-20 20:33:38 -0700 | [diff] [blame] | 1276 | } |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1277 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1278 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1279 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1280 | // |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1281 | // Exported Droiddoc Directory |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1282 | // |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1283 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1284 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1285 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1286 | type ExportedDroiddocDirProperties struct { |
| 1287 | // path to the directory containing Droiddoc related files. |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1288 | Path *string |
| 1289 | } |
| 1290 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1291 | type ExportedDroiddocDir struct { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1292 | android.ModuleBase |
| 1293 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1294 | properties ExportedDroiddocDirProperties |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1295 | |
| 1296 | deps android.Paths |
| 1297 | dir android.Path |
| 1298 | } |
| 1299 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1300 | func ExportedDroiddocDirFactory() android.Module { |
| 1301 | module := &ExportedDroiddocDir{} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1302 | module.AddProperties(&module.properties) |
| 1303 | android.InitAndroidModule(module) |
| 1304 | return module |
| 1305 | } |
| 1306 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1307 | func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1308 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1309 | func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1310 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) |
| 1311 | d.dir = path |
| 1312 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) |
| 1313 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1314 | |
| 1315 | // |
| 1316 | // Defaults |
| 1317 | // |
| 1318 | type DocDefaults struct { |
| 1319 | android.ModuleBase |
| 1320 | android.DefaultsModuleBase |
| 1321 | } |
| 1322 | |
| 1323 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1324 | } |
| 1325 | |
| 1326 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1327 | } |
| 1328 | |
| 1329 | func DocDefaultsFactory() android.Module { |
| 1330 | module := &DocDefaults{} |
| 1331 | |
| 1332 | module.AddProperties( |
| 1333 | &JavadocProperties{}, |
| 1334 | &DroiddocProperties{}, |
| 1335 | ) |
| 1336 | |
| 1337 | android.InitDefaultsModule(module) |
| 1338 | |
| 1339 | return module |
| 1340 | } |