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