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