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