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 | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 22 | "strings" |
| 23 | |
| 24 | "github.com/google/blueprint" |
| 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | javadoc = pctx.AndroidStaticRule("javadoc", |
| 29 | blueprint.RuleParams{ |
| 30 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 31 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 32 | `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + |
| 33 | `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` + |
| 34 | `-d $outDir -quiet && ` + |
| 35 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
| 36 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, |
| 37 | CommandDeps: []string{ |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 38 | "${config.ZipSyncCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 39 | "${config.JavadocCmd}", |
| 40 | "${config.SoongZipCmd}", |
| 41 | "$JsilverJar", |
| 42 | "$DoclavaJar", |
| 43 | }, |
| 44 | Rspfile: "$out.rsp", |
| 45 | RspfileContent: "$in", |
| 46 | Restat: true, |
| 47 | }, |
| 48 | "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", |
| 49 | "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "JsilverJar", "DoclavaJar") |
| 50 | ) |
| 51 | |
| 52 | func init() { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 53 | android.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 54 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 55 | android.RegisterModuleType("droiddoc", DroiddocFactory) |
| 56 | android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 57 | android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 58 | android.RegisterModuleType("javadoc", JavadocFactory) |
| 59 | android.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 60 | } |
| 61 | |
| 62 | type JavadocProperties struct { |
| 63 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 64 | // or .aidl files. |
| 65 | Srcs []string `android:"arch_variant"` |
| 66 | |
| 67 | // list of directories rooted at the Android.bp file that will |
| 68 | // 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] | 69 | Local_sourcepaths []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 70 | |
| 71 | // list of source files that should not be used to build the Java module. |
| 72 | // This is most useful in the arch/multilib variants to remove non-common files |
| 73 | // filegroup or genrule can be included within this property. |
| 74 | Exclude_srcs []string `android:"arch_variant"` |
| 75 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 76 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 77 | Libs []string `android:"arch_variant"` |
| 78 | |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 79 | // don't build against the framework libraries (legacy-test, core-junit, |
| 80 | // ext, and framework for device targets) |
| 81 | No_framework_libs *bool |
| 82 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 83 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 84 | Srcs_lib *string |
| 85 | |
| 86 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 87 | Srcs_lib_whitelist_dirs []string |
| 88 | |
| 89 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 90 | Srcs_lib_whitelist_pkgs []string |
| 91 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 92 | // 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] | 93 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 94 | |
| 95 | // if not blank, set to the version of the sdk to compile against |
| 96 | Sdk_version *string `android:"arch_variant"` |
| 97 | } |
| 98 | |
| 99 | type DroiddocProperties struct { |
| 100 | // 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] | 101 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 102 | |
| 103 | // 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] | 104 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 105 | |
| 106 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 107 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 108 | |
| 109 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 110 | // suitable for spell-checking and other goodness. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 111 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 112 | |
| 113 | // a todo file lists the program elements that are missing documentation. |
| 114 | // At some point, this might be improved to show more warnings. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 115 | Todo_file *string |
| 116 | |
| 117 | // directory under current module source that provide additional resources (images). |
| 118 | Resourcesdir *string |
| 119 | |
| 120 | // resources output directory under out/soong/.intermediates. |
| 121 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 122 | |
| 123 | // local files that are used within user customized droiddoc options. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 124 | Arg_files []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 125 | |
| 126 | // user customized droiddoc args. |
| 127 | // Available variables for substitution: |
| 128 | // |
| 129 | // $(location <label>): the path to the arg_files with name <label> |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 130 | Args *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 131 | |
| 132 | // names of the output files used in args that will be generated |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 133 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 134 | |
| 135 | // a list of files under current module source dir which contains known tags in Java sources. |
| 136 | // filegroup or genrule can be included within this property. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 137 | Knowntags []string |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 138 | |
| 139 | // the tag name used to distinguish if the API files belong to public/system/test. |
| 140 | Api_tag_name *string |
| 141 | |
| 142 | // the generated public API filename by Doclava. |
| 143 | Api_filename *string |
| 144 | |
| 145 | // the generated private API filename by Doclava. |
| 146 | Private_api_filename *string |
| 147 | |
| 148 | // the generated private Dex API filename by Doclava. |
| 149 | Private_dex_api_filename *string |
| 150 | |
| 151 | // the generated removed API filename by Doclava. |
| 152 | Removed_api_filename *string |
| 153 | |
| 154 | // the generated exact API filename by Doclava. |
| 155 | Exact_api_filename *string |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame^] | 156 | |
| 157 | // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true. |
| 158 | Create_stubs *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | type Javadoc struct { |
| 162 | android.ModuleBase |
| 163 | android.DefaultableModuleBase |
| 164 | |
| 165 | properties JavadocProperties |
| 166 | |
| 167 | srcJars android.Paths |
| 168 | srcFiles android.Paths |
| 169 | sourcepaths android.Paths |
| 170 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 171 | docZip android.WritablePath |
| 172 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 175 | func (j *Javadoc) Srcs() android.Paths { |
| 176 | return android.Paths{j.stubsSrcJar} |
| 177 | } |
| 178 | |
| 179 | var _ android.SourceFileProducer = (*Javadoc)(nil) |
| 180 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 181 | type Droiddoc struct { |
| 182 | Javadoc |
| 183 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 184 | properties DroiddocProperties |
| 185 | apiFile android.WritablePath |
| 186 | privateApiFile android.WritablePath |
| 187 | privateDexApiFile android.WritablePath |
| 188 | removedApiFile android.WritablePath |
| 189 | exactApiFile android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 193 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 194 | android.InitDefaultableModule(module) |
| 195 | } |
| 196 | |
| 197 | func JavadocFactory() android.Module { |
| 198 | module := &Javadoc{} |
| 199 | |
| 200 | module.AddProperties(&module.properties) |
| 201 | |
| 202 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 203 | return module |
| 204 | } |
| 205 | |
| 206 | func JavadocHostFactory() android.Module { |
| 207 | module := &Javadoc{} |
| 208 | |
| 209 | module.AddProperties(&module.properties) |
| 210 | |
| 211 | InitDroiddocModule(module, android.HostSupported) |
| 212 | return module |
| 213 | } |
| 214 | |
| 215 | func DroiddocFactory() android.Module { |
| 216 | module := &Droiddoc{} |
| 217 | |
| 218 | module.AddProperties(&module.properties, |
| 219 | &module.Javadoc.properties) |
| 220 | |
| 221 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 222 | return module |
| 223 | } |
| 224 | |
| 225 | func DroiddocHostFactory() android.Module { |
| 226 | module := &Droiddoc{} |
| 227 | |
| 228 | module.AddProperties(&module.properties, |
| 229 | &module.Javadoc.properties) |
| 230 | |
| 231 | InitDroiddocModule(module, android.HostSupported) |
| 232 | return module |
| 233 | } |
| 234 | |
| 235 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 236 | if ctx.Device() { |
| 237 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 238 | if sdkDep.useDefaultLibs { |
| 239 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Nan Zhang | 9cbe677 | 2018-03-21 17:56:39 -0700 | [diff] [blame] | 240 | if !Bool(j.properties.No_framework_libs) { |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 241 | ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...) |
| 242 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 243 | } else if sdkDep.useModule { |
| 244 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 249 | |
| 250 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
| 251 | |
| 252 | // exclude_srcs may contain filegroup or genrule. |
| 253 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
| 254 | } |
| 255 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 256 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { |
| 257 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { |
| 258 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { |
| 259 | prefix := filepath.Join(dir, pkg) |
| 260 | if _, found := whitelistPathPrefixes[prefix]; !found { |
| 261 | whitelistPathPrefixes[prefix] = true |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 267 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 268 | var deps deps |
| 269 | |
| 270 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 271 | if sdkDep.invalidVersion { |
| 272 | ctx.AddMissingDependencies([]string{sdkDep.module}) |
| 273 | } else if sdkDep.useFiles { |
| 274 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jar) |
| 275 | } |
| 276 | |
| 277 | ctx.VisitDirectDeps(func(module android.Module) { |
| 278 | otherName := ctx.OtherModuleName(module) |
| 279 | tag := ctx.OtherModuleDependencyTag(module) |
| 280 | |
| 281 | switch dep := module.(type) { |
| 282 | case Dependency: |
| 283 | switch tag { |
| 284 | case bootClasspathTag: |
| 285 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
| 286 | case libTag: |
| 287 | deps.classpath = append(deps.classpath, dep.ImplementationJars()...) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 288 | if otherName == String(j.properties.Srcs_lib) { |
| 289 | srcs := dep.(SrcDependency).CompiledSrcs() |
| 290 | whitelistPathPrefixes := make(map[string]bool) |
| 291 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) |
| 292 | for _, src := range srcs { |
| 293 | if _, ok := src.(android.WritablePath); ok { // generated sources |
| 294 | deps.srcs = append(deps.srcs, src) |
| 295 | } else { // select source path for documentation based on whitelist path prefixs. |
| 296 | for k, _ := range whitelistPathPrefixes { |
| 297 | if strings.HasPrefix(src.Rel(), k) { |
| 298 | deps.srcs = append(deps.srcs, src) |
| 299 | break |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) |
| 305 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 306 | default: |
| 307 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 308 | } |
| 309 | case android.SourceFileProducer: |
| 310 | switch tag { |
| 311 | case libTag: |
| 312 | checkProducesJars(ctx, dep) |
| 313 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 314 | case android.DefaultsDepTag, android.SourceDepTag: |
| 315 | // Nothing to do |
| 316 | default: |
| 317 | ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName) |
| 318 | } |
| 319 | default: |
| 320 | switch tag { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 321 | case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 322 | // Nothing to do |
| 323 | default: |
| 324 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 325 | } |
| 326 | } |
| 327 | }) |
| 328 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 329 | // may contain filegroup or genrule. |
| 330 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
| 331 | |
| 332 | // srcs may depend on some genrule output. |
| 333 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 334 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 335 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 336 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 337 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 338 | |
| 339 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 340 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 341 | |
| 342 | if j.properties.Local_sourcepaths == nil { |
| 343 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") |
| 344 | } |
| 345 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 346 | |
| 347 | return deps |
| 348 | } |
| 349 | |
| 350 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 351 | j.addDeps(ctx) |
| 352 | } |
| 353 | |
| 354 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 355 | deps := j.collectDeps(ctx) |
| 356 | |
| 357 | var implicits android.Paths |
| 358 | implicits = append(implicits, deps.bootClasspath...) |
| 359 | implicits = append(implicits, deps.classpath...) |
| 360 | |
| 361 | var bootClasspathArgs, classpathArgs string |
| 362 | if ctx.Config().UseOpenJDK9() { |
| 363 | if len(deps.bootClasspath) > 0 { |
| 364 | // For OpenJDK 9 we use --patch-module to define the core libraries code. |
| 365 | // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9 |
| 366 | // modules. Here we treat all code in core libraries as being in java.base |
| 367 | // to work around the OpenJDK 9 module system. http://b/62049770 |
| 368 | bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":") |
| 369 | } |
| 370 | } else { |
| 371 | if len(deps.bootClasspath.Strings()) > 0 { |
| 372 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
| 373 | bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 374 | } |
| 375 | } |
| 376 | if len(deps.classpath.Strings()) > 0 { |
| 377 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 378 | } |
| 379 | |
| 380 | implicits = append(implicits, j.srcJars...) |
| 381 | |
| 382 | opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" |
| 383 | |
| 384 | ctx.Build(pctx, android.BuildParams{ |
| 385 | Rule: javadoc, |
| 386 | Description: "Javadoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 387 | Output: j.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 388 | ImplicitOutput: j.docZip, |
| 389 | Inputs: j.srcFiles, |
| 390 | Implicits: implicits, |
| 391 | Args: map[string]string{ |
| 392 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 393 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 394 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 395 | "srcJars": strings.Join(j.srcJars.Strings(), " "), |
| 396 | "opts": opts, |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame^] | 397 | "bootclasspathArgs": bootClasspathArgs, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 398 | "classpathArgs": classpathArgs, |
| 399 | "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"), |
| 400 | "docZip": j.docZip.String(), |
| 401 | }, |
| 402 | }) |
| 403 | } |
| 404 | |
| 405 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 406 | d.Javadoc.addDeps(ctx) |
| 407 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 408 | if String(d.properties.Custom_template) == "" { |
| 409 | // TODO: This is almost always droiddoc-templates-sdk |
| 410 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 411 | } else { |
| 412 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 413 | } |
| 414 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 415 | // extra_arg_files may contains filegroup or genrule. |
| 416 | android.ExtractSourcesDeps(ctx, d.properties.Arg_files) |
| 417 | |
| 418 | // knowntags may contain filegroup or genrule. |
| 419 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) |
| 420 | } |
| 421 | |
| 422 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 423 | deps := d.Javadoc.collectDeps(ctx) |
| 424 | |
| 425 | var implicits android.Paths |
| 426 | implicits = append(implicits, deps.bootClasspath...) |
| 427 | implicits = append(implicits, deps.classpath...) |
| 428 | |
| 429 | argFiles := ctx.ExpandSources(d.properties.Arg_files, nil) |
| 430 | argFilesMap := map[string]android.Path{} |
| 431 | |
| 432 | for _, f := range argFiles { |
| 433 | implicits = append(implicits, f) |
| 434 | if _, exists := argFilesMap[f.Rel()]; !exists { |
| 435 | argFilesMap[f.Rel()] = f |
| 436 | } else { |
| 437 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
| 438 | f, argFilesMap[f.Rel()], f.Rel()) |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) { |
| 443 | if strings.HasPrefix(name, "location ") { |
| 444 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 445 | if f, ok := argFilesMap[label]; ok { |
| 446 | return f.String(), nil |
| 447 | } else { |
| 448 | return "", fmt.Errorf("unknown location label %q", label) |
| 449 | } |
| 450 | } else if name == "genDir" { |
| 451 | return android.PathForModuleGen(ctx).String(), nil |
| 452 | } |
| 453 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 454 | }) |
| 455 | |
| 456 | if err != nil { |
| 457 | ctx.PropertyErrorf("extra_args", "%s", err.Error()) |
| 458 | return |
| 459 | } |
| 460 | |
| 461 | var bootClasspathArgs, classpathArgs string |
| 462 | if len(deps.bootClasspath.Strings()) > 0 { |
| 463 | bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":") |
| 464 | } |
| 465 | if len(deps.classpath.Strings()) > 0 { |
| 466 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 467 | } |
| 468 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 469 | var templateDir string |
| 470 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
| 471 | if t, ok := m.(*DroiddocTemplate); ok { |
| 472 | implicits = append(implicits, t.deps...) |
| 473 | templateDir = t.dir.String() |
| 474 | } else { |
| 475 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) |
| 476 | } |
| 477 | }) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 478 | |
| 479 | var htmlDirArgs string |
| 480 | if len(d.properties.Html_dirs) > 0 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 481 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 482 | implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) |
| 483 | htmlDirArgs = "-htmldir " + htmlDir.String() |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | var htmlDir2Args string |
| 487 | if len(d.properties.Html_dirs) > 1 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 488 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 489 | implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) |
| 490 | htmlDir2Args = "-htmldir2 " + htmlDir2.String() |
| 491 | } |
| 492 | |
| 493 | if len(d.properties.Html_dirs) > 2 { |
| 494 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) |
| 498 | implicits = append(implicits, knownTags...) |
| 499 | |
| 500 | for _, kt := range knownTags { |
| 501 | args = args + " -knowntags " + kt.String() |
| 502 | } |
| 503 | for _, hdf := range d.properties.Hdf { |
| 504 | args = args + " -hdf " + hdf |
| 505 | } |
| 506 | |
| 507 | if String(d.properties.Proofread_file) != "" { |
| 508 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
| 509 | args = args + " -proofread " + proofreadFile.String() |
| 510 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 511 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 512 | if String(d.properties.Todo_file) != "" { |
| 513 | // tricky part: |
| 514 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 515 | // the non-standard doclet will get the full path relative to "-o". |
| 516 | args = args + " -todo " + String(d.properties.Todo_file) |
| 517 | } |
| 518 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 519 | if String(d.properties.Resourcesdir) != "" { |
| 520 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 521 | // resourcesDir is one sub dir of htmlDir |
| 522 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
| 523 | args = args + " -resourcesdir " + resourcesDir.String() |
| 524 | } |
| 525 | |
| 526 | if String(d.properties.Resourcesoutdir) != "" { |
| 527 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
| 528 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) |
| 529 | } |
| 530 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 531 | var implicitOutputs android.WritablePaths |
| 532 | if String(d.properties.Api_filename) != "" { |
| 533 | d.apiFile = android.PathForModuleOut(ctx, String(d.properties.Api_filename)) |
| 534 | args = args + " -api " + d.apiFile.String() |
| 535 | implicitOutputs = append(implicitOutputs, d.apiFile) |
| 536 | } |
| 537 | |
| 538 | if String(d.properties.Private_api_filename) != "" { |
| 539 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) |
| 540 | args = args + " -privateApi " + d.privateApiFile.String() |
| 541 | implicitOutputs = append(implicitOutputs, d.privateApiFile) |
| 542 | } |
| 543 | |
| 544 | if String(d.properties.Private_dex_api_filename) != "" { |
| 545 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) |
| 546 | args = args + " -privateDexApi " + d.privateDexApiFile.String() |
| 547 | implicitOutputs = append(implicitOutputs, d.privateDexApiFile) |
| 548 | } |
| 549 | |
| 550 | if String(d.properties.Removed_api_filename) != "" { |
| 551 | d.removedApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_api_filename)) |
| 552 | args = args + " -removedApi " + d.removedApiFile.String() |
| 553 | implicitOutputs = append(implicitOutputs, d.removedApiFile) |
| 554 | } |
| 555 | |
| 556 | if String(d.properties.Exact_api_filename) != "" { |
| 557 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) |
| 558 | args = args + " -exactApi " + d.exactApiFile.String() |
| 559 | implicitOutputs = append(implicitOutputs, d.exactApiFile) |
| 560 | } |
| 561 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 562 | implicits = append(implicits, d.Javadoc.srcJars...) |
| 563 | |
| 564 | opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + |
| 565 | "-doclet com.google.doclava.Doclava -docletpath ${config.JsilverJar}:${config.DoclavaJar} " + |
Colin Cross | 480cd76 | 2018-02-22 14:39:17 -0800 | [diff] [blame] | 566 | "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 567 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame^] | 568 | "-hdf page.now " + `"$$(date -d @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")"` + |
| 569 | " " + args |
| 570 | if BoolDefault(d.properties.Create_stubs, true) { |
| 571 | opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String() |
| 572 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 573 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 574 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) |
| 575 | for _, o := range d.properties.Out { |
| 576 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 577 | } |
| 578 | |
| 579 | ctx.Build(pctx, android.BuildParams{ |
| 580 | Rule: javadoc, |
| 581 | Description: "Droiddoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 582 | Output: d.Javadoc.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 583 | Inputs: d.Javadoc.srcFiles, |
| 584 | Implicits: implicits, |
| 585 | ImplicitOutputs: implicitOutputs, |
| 586 | Args: map[string]string{ |
| 587 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 588 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 589 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 590 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 591 | "opts": opts, |
| 592 | "bootclasspathArgs": bootClasspathArgs, |
| 593 | "classpathArgs": classpathArgs, |
| 594 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 595 | "docZip": d.Javadoc.docZip.String(), |
| 596 | "JsilverJar": "${config.JsilverJar}", |
| 597 | "DoclavaJar": "${config.DoclavaJar}", |
| 598 | }, |
| 599 | }) |
| 600 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 601 | |
| 602 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
| 603 | |
| 604 | type DroiddocTemplateProperties struct { |
| 605 | // path to the directory containing the droiddoc templates. |
| 606 | Path *string |
| 607 | } |
| 608 | |
| 609 | type DroiddocTemplate struct { |
| 610 | android.ModuleBase |
| 611 | |
| 612 | properties DroiddocTemplateProperties |
| 613 | |
| 614 | deps android.Paths |
| 615 | dir android.Path |
| 616 | } |
| 617 | |
| 618 | func DroiddocTemplateFactory() android.Module { |
| 619 | module := &DroiddocTemplate{} |
| 620 | module.AddProperties(&module.properties) |
| 621 | android.InitAndroidModule(module) |
| 622 | return module |
| 623 | } |
| 624 | |
| 625 | func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {} |
| 626 | |
| 627 | func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 628 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) |
| 629 | d.dir = path |
| 630 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) |
| 631 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 632 | |
| 633 | // |
| 634 | // Defaults |
| 635 | // |
| 636 | type DocDefaults struct { |
| 637 | android.ModuleBase |
| 638 | android.DefaultsModuleBase |
| 639 | } |
| 640 | |
| 641 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 642 | } |
| 643 | |
| 644 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 645 | } |
| 646 | |
| 647 | func DocDefaultsFactory() android.Module { |
| 648 | module := &DocDefaults{} |
| 649 | |
| 650 | module.AddProperties( |
| 651 | &JavadocProperties{}, |
| 652 | &DroiddocProperties{}, |
| 653 | ) |
| 654 | |
| 655 | android.InitDefaultsModule(module) |
| 656 | |
| 657 | return module |
| 658 | } |