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