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