blob: 07042a115ba5b95524ec9084a6acdc5e2e82c789 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// 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
15package java
16
17import (
18 "android/soong/android"
19 "android/soong/java/config"
20 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080021 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080022 "strings"
23
24 "github.com/google/blueprint"
25)
26
27var (
28 javadoc = pctx.AndroidStaticRule("javadoc",
29 blueprint.RuleParams{
30 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070031 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang581fd212018-01-10 16:06:12 -080032 `${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 Cross436b7652018-03-15 16:24:10 -070038 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080039 "${config.JavadocCmd}",
40 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080041 },
42 Rspfile: "$out.rsp",
43 RspfileContent: "$in",
44 Restat: true,
45 },
46 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang30963742018-04-23 09:59:14 -070047 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -080048)
49
50func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080051 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
52
Nan Zhang581fd212018-01-10 16:06:12 -080053 android.RegisterModuleType("droiddoc", DroiddocFactory)
54 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Dan Willemsencc090972018-02-26 14:33:31 -080055 android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080056 android.RegisterModuleType("javadoc", JavadocFactory)
57 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
58}
59
60type JavadocProperties struct {
61 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
62 // or .aidl files.
63 Srcs []string `android:"arch_variant"`
64
65 // list of directories rooted at the Android.bp file that will
66 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080067 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080068
69 // list of source files that should not be used to build the Java module.
70 // This is most useful in the arch/multilib variants to remove non-common files
71 // filegroup or genrule can be included within this property.
72 Exclude_srcs []string `android:"arch_variant"`
73
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080075 Libs []string `android:"arch_variant"`
76
Nan Zhange66c7272018-03-06 12:59:27 -080077 // don't build against the framework libraries (legacy-test, core-junit,
78 // ext, and framework for device targets)
79 No_framework_libs *bool
80
Nan Zhangb2b33de2018-02-23 11:18:47 -080081 // the java library (in classpath) for documentation that provides java srcs and srcjars.
82 Srcs_lib *string
83
84 // the base dirs under srcs_lib will be scanned for java srcs.
85 Srcs_lib_whitelist_dirs []string
86
87 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
88 Srcs_lib_whitelist_pkgs []string
89
Nan Zhang581fd212018-01-10 16:06:12 -080090 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080091 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080092
93 // if not blank, set to the version of the sdk to compile against
94 Sdk_version *string `android:"arch_variant"`
95}
96
97type DroiddocProperties struct {
98 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -080099 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800100
101 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800102 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800103
104 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800105 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800106
107 // proofread file contains all of the text content of the javadocs concatenated into one file,
108 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800109 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800110
111 // a todo file lists the program elements that are missing documentation.
112 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800113 Todo_file *string
114
115 // directory under current module source that provide additional resources (images).
116 Resourcesdir *string
117
118 // resources output directory under out/soong/.intermediates.
119 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800120
121 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800122 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800123
124 // user customized droiddoc args.
125 // Available variables for substitution:
126 //
127 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800128 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800129
130 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800131 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800132
133 // a list of files under current module source dir which contains known tags in Java sources.
134 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800135 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700136
137 // the tag name used to distinguish if the API files belong to public/system/test.
138 Api_tag_name *string
139
140 // the generated public API filename by Doclava.
141 Api_filename *string
142
143 // the generated private API filename by Doclava.
144 Private_api_filename *string
145
146 // the generated private Dex API filename by Doclava.
147 Private_dex_api_filename *string
148
149 // the generated removed API filename by Doclava.
150 Removed_api_filename *string
151
David Brazdilaac0c3c2018-04-24 16:23:29 +0100152 // the generated removed Dex API filename by Doclava.
153 Removed_dex_api_filename *string
154
Nan Zhang28c68b92018-03-13 16:17:01 -0700155 // the generated exact API filename by Doclava.
156 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700157
158 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
159 Create_stubs *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800160}
161
162type Javadoc struct {
163 android.ModuleBase
164 android.DefaultableModuleBase
165
166 properties JavadocProperties
167
168 srcJars android.Paths
169 srcFiles android.Paths
170 sourcepaths android.Paths
171
Nan Zhangccff0f72018-03-08 17:26:16 -0800172 docZip android.WritablePath
173 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800174}
175
Nan Zhangb2b33de2018-02-23 11:18:47 -0800176func (j *Javadoc) Srcs() android.Paths {
177 return android.Paths{j.stubsSrcJar}
178}
179
180var _ android.SourceFileProducer = (*Javadoc)(nil)
181
Nan Zhang581fd212018-01-10 16:06:12 -0800182type Droiddoc struct {
183 Javadoc
184
Nan Zhang28c68b92018-03-13 16:17:01 -0700185 properties DroiddocProperties
186 apiFile android.WritablePath
187 privateApiFile android.WritablePath
188 privateDexApiFile android.WritablePath
189 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100190 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700191 exactApiFile android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800192}
193
194func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
195 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
196 android.InitDefaultableModule(module)
197}
198
199func JavadocFactory() android.Module {
200 module := &Javadoc{}
201
202 module.AddProperties(&module.properties)
203
204 InitDroiddocModule(module, android.HostAndDeviceSupported)
205 return module
206}
207
208func JavadocHostFactory() android.Module {
209 module := &Javadoc{}
210
211 module.AddProperties(&module.properties)
212
213 InitDroiddocModule(module, android.HostSupported)
214 return module
215}
216
217func DroiddocFactory() android.Module {
218 module := &Droiddoc{}
219
220 module.AddProperties(&module.properties,
221 &module.Javadoc.properties)
222
223 InitDroiddocModule(module, android.HostAndDeviceSupported)
224 return module
225}
226
227func DroiddocHostFactory() android.Module {
228 module := &Droiddoc{}
229
230 module.AddProperties(&module.properties,
231 &module.Javadoc.properties)
232
233 InitDroiddocModule(module, android.HostSupported)
234 return module
235}
236
237func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
238 if ctx.Device() {
239 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
240 if sdkDep.useDefaultLibs {
241 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang9cbe6772018-03-21 17:56:39 -0700242 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800243 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
244 }
Nan Zhang581fd212018-01-10 16:06:12 -0800245 } else if sdkDep.useModule {
246 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
247 }
248 }
249
250 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
251
252 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
253
254 // exclude_srcs may contain filegroup or genrule.
255 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
256}
257
Nan Zhangb2b33de2018-02-23 11:18:47 -0800258func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
259 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
260 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900261 // convert foo.bar.baz to foo/bar/baz
262 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
263 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800264 if _, found := whitelistPathPrefixes[prefix]; !found {
265 whitelistPathPrefixes[prefix] = true
266 }
267 }
268 }
269}
270
Nan Zhang581fd212018-01-10 16:06:12 -0800271func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
272 var deps deps
273
274 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
275 if sdkDep.invalidVersion {
276 ctx.AddMissingDependencies([]string{sdkDep.module})
277 } else if sdkDep.useFiles {
278 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jar)
279 }
280
281 ctx.VisitDirectDeps(func(module android.Module) {
282 otherName := ctx.OtherModuleName(module)
283 tag := ctx.OtherModuleDependencyTag(module)
284
285 switch dep := module.(type) {
286 case Dependency:
287 switch tag {
288 case bootClasspathTag:
289 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
290 case libTag:
291 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800292 if otherName == String(j.properties.Srcs_lib) {
293 srcs := dep.(SrcDependency).CompiledSrcs()
294 whitelistPathPrefixes := make(map[string]bool)
295 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
296 for _, src := range srcs {
297 if _, ok := src.(android.WritablePath); ok { // generated sources
298 deps.srcs = append(deps.srcs, src)
299 } else { // select source path for documentation based on whitelist path prefixs.
300 for k, _ := range whitelistPathPrefixes {
301 if strings.HasPrefix(src.Rel(), k) {
302 deps.srcs = append(deps.srcs, src)
303 break
304 }
305 }
306 }
307 }
308 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
309 }
Nan Zhang581fd212018-01-10 16:06:12 -0800310 default:
311 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
312 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900313 case SdkLibraryDependency:
314 switch tag {
315 case libTag:
316 sdkVersion := String(j.properties.Sdk_version)
317 linkType := javaSdk
318 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
319 linkType = javaSystem
320 } else if sdkVersion == "" {
321 linkType = javaPlatform
322 }
323 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
324 default:
325 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
326 }
Nan Zhang581fd212018-01-10 16:06:12 -0800327 case android.SourceFileProducer:
328 switch tag {
329 case libTag:
330 checkProducesJars(ctx, dep)
331 deps.classpath = append(deps.classpath, dep.Srcs()...)
332 case android.DefaultsDepTag, android.SourceDepTag:
333 // Nothing to do
334 default:
335 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName)
336 }
337 default:
338 switch tag {
Dan Willemsencc090972018-02-26 14:33:31 -0800339 case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag:
Nan Zhang581fd212018-01-10 16:06:12 -0800340 // Nothing to do
341 default:
342 ctx.ModuleErrorf("depends on non-java module %q", otherName)
343 }
344 }
345 })
346 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
347 // may contain filegroup or genrule.
348 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
349
350 // srcs may depend on some genrule output.
351 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800352 j.srcJars = append(j.srcJars, deps.srcJars...)
353
Nan Zhang581fd212018-01-10 16:06:12 -0800354 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800355 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800356
357 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800358 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800359
360 if j.properties.Local_sourcepaths == nil {
361 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
362 }
363 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800364
365 return deps
366}
367
368func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
369 j.addDeps(ctx)
370}
371
372func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
373 deps := j.collectDeps(ctx)
374
375 var implicits android.Paths
376 implicits = append(implicits, deps.bootClasspath...)
377 implicits = append(implicits, deps.classpath...)
378
379 var bootClasspathArgs, classpathArgs string
380 if ctx.Config().UseOpenJDK9() {
381 if len(deps.bootClasspath) > 0 {
382 // For OpenJDK 9 we use --patch-module to define the core libraries code.
383 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
384 // modules. Here we treat all code in core libraries as being in java.base
385 // to work around the OpenJDK 9 module system. http://b/62049770
386 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
387 }
388 } else {
389 if len(deps.bootClasspath.Strings()) > 0 {
390 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
391 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
392 }
393 }
394 if len(deps.classpath.Strings()) > 0 {
395 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
396 }
397
398 implicits = append(implicits, j.srcJars...)
399
400 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
401
402 ctx.Build(pctx, android.BuildParams{
403 Rule: javadoc,
404 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800405 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800406 ImplicitOutput: j.docZip,
407 Inputs: j.srcFiles,
408 Implicits: implicits,
409 Args: map[string]string{
410 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
411 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
412 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
413 "srcJars": strings.Join(j.srcJars.Strings(), " "),
414 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700415 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800416 "classpathArgs": classpathArgs,
417 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
418 "docZip": j.docZip.String(),
419 },
420 })
421}
422
423func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
424 d.Javadoc.addDeps(ctx)
425
Dan Willemsencc090972018-02-26 14:33:31 -0800426 if String(d.properties.Custom_template) == "" {
427 // TODO: This is almost always droiddoc-templates-sdk
428 ctx.PropertyErrorf("custom_template", "must specify a template")
429 } else {
430 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
431 }
432
Nan Zhang581fd212018-01-10 16:06:12 -0800433 // extra_arg_files may contains filegroup or genrule.
434 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
435
436 // knowntags may contain filegroup or genrule.
437 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
438}
439
440func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
441 deps := d.Javadoc.collectDeps(ctx)
442
443 var implicits android.Paths
444 implicits = append(implicits, deps.bootClasspath...)
445 implicits = append(implicits, deps.classpath...)
446
447 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
448 argFilesMap := map[string]android.Path{}
449
450 for _, f := range argFiles {
451 implicits = append(implicits, f)
452 if _, exists := argFilesMap[f.Rel()]; !exists {
453 argFilesMap[f.Rel()] = f
454 } else {
455 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
456 f, argFilesMap[f.Rel()], f.Rel())
457 }
458 }
459
460 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
461 if strings.HasPrefix(name, "location ") {
462 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
463 if f, ok := argFilesMap[label]; ok {
464 return f.String(), nil
465 } else {
466 return "", fmt.Errorf("unknown location label %q", label)
467 }
468 } else if name == "genDir" {
469 return android.PathForModuleGen(ctx).String(), nil
470 }
471 return "", fmt.Errorf("unknown variable '$(%s)'", name)
472 })
473
474 if err != nil {
475 ctx.PropertyErrorf("extra_args", "%s", err.Error())
476 return
477 }
478
479 var bootClasspathArgs, classpathArgs string
480 if len(deps.bootClasspath.Strings()) > 0 {
481 bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":")
482 }
483 if len(deps.classpath.Strings()) > 0 {
484 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
485 }
486
Dan Willemsencc090972018-02-26 14:33:31 -0800487 var templateDir string
488 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
489 if t, ok := m.(*DroiddocTemplate); ok {
490 implicits = append(implicits, t.deps...)
491 templateDir = t.dir.String()
492 } else {
493 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
494 }
495 })
Nan Zhang581fd212018-01-10 16:06:12 -0800496
497 var htmlDirArgs string
498 if len(d.properties.Html_dirs) > 0 {
Dan Willemsencc090972018-02-26 14:33:31 -0800499 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
500 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
501 htmlDirArgs = "-htmldir " + htmlDir.String()
Nan Zhang581fd212018-01-10 16:06:12 -0800502 }
503
504 var htmlDir2Args string
505 if len(d.properties.Html_dirs) > 1 {
Dan Willemsencc090972018-02-26 14:33:31 -0800506 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
507 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
508 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
509 }
510
511 if len(d.properties.Html_dirs) > 2 {
512 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
Nan Zhang581fd212018-01-10 16:06:12 -0800513 }
514
515 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
516 implicits = append(implicits, knownTags...)
517
518 for _, kt := range knownTags {
519 args = args + " -knowntags " + kt.String()
520 }
521 for _, hdf := range d.properties.Hdf {
522 args = args + " -hdf " + hdf
523 }
524
525 if String(d.properties.Proofread_file) != "" {
526 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
527 args = args + " -proofread " + proofreadFile.String()
528 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800529
Nan Zhang581fd212018-01-10 16:06:12 -0800530 if String(d.properties.Todo_file) != "" {
531 // tricky part:
532 // we should not compute full path for todo_file through PathForModuleOut().
533 // the non-standard doclet will get the full path relative to "-o".
534 args = args + " -todo " + String(d.properties.Todo_file)
535 }
536
Nan Zhangb2b33de2018-02-23 11:18:47 -0800537 if String(d.properties.Resourcesdir) != "" {
538 // TODO: should we add files under resourcesDir to the implicits? It seems that
539 // resourcesDir is one sub dir of htmlDir
540 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
541 args = args + " -resourcesdir " + resourcesDir.String()
542 }
543
544 if String(d.properties.Resourcesoutdir) != "" {
545 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
546 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
547 }
548
Nan Zhang28c68b92018-03-13 16:17:01 -0700549 var implicitOutputs android.WritablePaths
550 if String(d.properties.Api_filename) != "" {
551 d.apiFile = android.PathForModuleOut(ctx, String(d.properties.Api_filename))
552 args = args + " -api " + d.apiFile.String()
553 implicitOutputs = append(implicitOutputs, d.apiFile)
554 }
555
556 if String(d.properties.Private_api_filename) != "" {
557 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
558 args = args + " -privateApi " + d.privateApiFile.String()
559 implicitOutputs = append(implicitOutputs, d.privateApiFile)
560 }
561
562 if String(d.properties.Private_dex_api_filename) != "" {
563 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
564 args = args + " -privateDexApi " + d.privateDexApiFile.String()
565 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
566 }
567
568 if String(d.properties.Removed_api_filename) != "" {
569 d.removedApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_api_filename))
570 args = args + " -removedApi " + d.removedApiFile.String()
571 implicitOutputs = append(implicitOutputs, d.removedApiFile)
572 }
573
David Brazdilaac0c3c2018-04-24 16:23:29 +0100574 if String(d.properties.Removed_dex_api_filename) != "" {
575 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
576 args = args + " -removedDexApi " + d.removedDexApiFile.String()
577 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
578 }
579
Nan Zhang28c68b92018-03-13 16:17:01 -0700580 if String(d.properties.Exact_api_filename) != "" {
581 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
582 args = args + " -exactApi " + d.exactApiFile.String()
583 implicitOutputs = append(implicitOutputs, d.exactApiFile)
584 }
585
Nan Zhang581fd212018-01-10 16:06:12 -0800586 implicits = append(implicits, d.Javadoc.srcJars...)
587
Nan Zhang30963742018-04-23 09:59:14 -0700588 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
589 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
590 implicits = append(implicits, jsilver)
591 implicits = append(implicits, doclava)
592
Nan Zhang581fd212018-01-10 16:06:12 -0800593 opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700594 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800595 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800596 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang853f4202018-04-12 16:55:56 -0700597 "-hdf page.now " + `"$$(date -d @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")"` +
598 " " + args
599 if BoolDefault(d.properties.Create_stubs, true) {
600 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
601 }
Nan Zhang581fd212018-01-10 16:06:12 -0800602
Nan Zhang581fd212018-01-10 16:06:12 -0800603 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
604 for _, o := range d.properties.Out {
605 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
606 }
607
608 ctx.Build(pctx, android.BuildParams{
609 Rule: javadoc,
610 Description: "Droiddoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800611 Output: d.Javadoc.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800612 Inputs: d.Javadoc.srcFiles,
613 Implicits: implicits,
614 ImplicitOutputs: implicitOutputs,
615 Args: map[string]string{
616 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
617 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
618 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
619 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
620 "opts": opts,
621 "bootclasspathArgs": bootClasspathArgs,
622 "classpathArgs": classpathArgs,
623 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
624 "docZip": d.Javadoc.docZip.String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800625 },
626 })
627}
Dan Willemsencc090972018-02-26 14:33:31 -0800628
629var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
630
631type DroiddocTemplateProperties struct {
632 // path to the directory containing the droiddoc templates.
633 Path *string
634}
635
636type DroiddocTemplate struct {
637 android.ModuleBase
638
639 properties DroiddocTemplateProperties
640
641 deps android.Paths
642 dir android.Path
643}
644
645func DroiddocTemplateFactory() android.Module {
646 module := &DroiddocTemplate{}
647 module.AddProperties(&module.properties)
648 android.InitAndroidModule(module)
649 return module
650}
651
652func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
653
654func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
655 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
656 d.dir = path
657 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
658}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800659
660//
661// Defaults
662//
663type DocDefaults struct {
664 android.ModuleBase
665 android.DefaultsModuleBase
666}
667
668func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
669}
670
671func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
672}
673
674func DocDefaultsFactory() android.Module {
675 module := &DocDefaults{}
676
677 module.AddProperties(
678 &JavadocProperties{},
679 &DroiddocProperties{},
680 )
681
682 android.InitDefaultsModule(module)
683
684 return module
685}