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