blob: a29f0ba7baad655a6aa5470e63fccf6c6a067768 [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}",
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
52func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080053 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
54
Nan Zhang581fd212018-01-10 16:06:12 -080055 android.RegisterModuleType("droiddoc", DroiddocFactory)
56 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Dan Willemsencc090972018-02-26 14:33:31 -080057 android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080058 android.RegisterModuleType("javadoc", JavadocFactory)
59 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
60}
61
62type 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 Zhangb2b33de2018-02-23 11:18:47 -080069 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080070
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 Zhangb2b33de2018-02-23 11:18:47 -080076 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080077 Libs []string `android:"arch_variant"`
78
Nan Zhange66c7272018-03-06 12:59:27 -080079 // 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 Zhangb2b33de2018-02-23 11:18:47 -080083 // 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 Zhang581fd212018-01-10 16:06:12 -080092 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080093 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080094
95 // if not blank, set to the version of the sdk to compile against
96 Sdk_version *string `android:"arch_variant"`
97}
98
99type DroiddocProperties struct {
100 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800101 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800102
103 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800104 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800105
106 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800107 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800108
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 Zhangb2b33de2018-02-23 11:18:47 -0800111 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800112
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 Zhangb2b33de2018-02-23 11:18:47 -0800115 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 Zhang581fd212018-01-10 16:06:12 -0800122
123 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800124 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800125
126 // user customized droiddoc args.
127 // Available variables for substitution:
128 //
129 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800130 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800131
132 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800133 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800134
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 Zhangb2b33de2018-02-23 11:18:47 -0800137 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700138
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 Zhang853f4202018-04-12 16:55:56 -0700156
157 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
158 Create_stubs *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800159}
160
161type 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 Zhangccff0f72018-03-08 17:26:16 -0800171 docZip android.WritablePath
172 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800173}
174
Nan Zhangb2b33de2018-02-23 11:18:47 -0800175func (j *Javadoc) Srcs() android.Paths {
176 return android.Paths{j.stubsSrcJar}
177}
178
179var _ android.SourceFileProducer = (*Javadoc)(nil)
180
Nan Zhang581fd212018-01-10 16:06:12 -0800181type Droiddoc struct {
182 Javadoc
183
Nan Zhang28c68b92018-03-13 16:17:01 -0700184 properties DroiddocProperties
185 apiFile android.WritablePath
186 privateApiFile android.WritablePath
187 privateDexApiFile android.WritablePath
188 removedApiFile android.WritablePath
189 exactApiFile android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800190}
191
192func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
193 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
194 android.InitDefaultableModule(module)
195}
196
197func JavadocFactory() android.Module {
198 module := &Javadoc{}
199
200 module.AddProperties(&module.properties)
201
202 InitDroiddocModule(module, android.HostAndDeviceSupported)
203 return module
204}
205
206func JavadocHostFactory() android.Module {
207 module := &Javadoc{}
208
209 module.AddProperties(&module.properties)
210
211 InitDroiddocModule(module, android.HostSupported)
212 return module
213}
214
215func 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
225func 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
235func (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 Zhang9cbe6772018-03-21 17:56:39 -0700240 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800241 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
242 }
Nan Zhang581fd212018-01-10 16:06:12 -0800243 } 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 Zhangb2b33de2018-02-23 11:18:47 -0800256func (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 {
Jiyong Park82484c02018-04-23 21:41:26 +0900259 // convert foo.bar.baz to foo/bar/baz
260 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
261 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800262 if _, found := whitelistPathPrefixes[prefix]; !found {
263 whitelistPathPrefixes[prefix] = true
264 }
265 }
266 }
267}
268
Nan Zhang581fd212018-01-10 16:06:12 -0800269func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
270 var deps deps
271
272 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
273 if sdkDep.invalidVersion {
274 ctx.AddMissingDependencies([]string{sdkDep.module})
275 } else if sdkDep.useFiles {
276 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jar)
277 }
278
279 ctx.VisitDirectDeps(func(module android.Module) {
280 otherName := ctx.OtherModuleName(module)
281 tag := ctx.OtherModuleDependencyTag(module)
282
283 switch dep := module.(type) {
284 case Dependency:
285 switch tag {
286 case bootClasspathTag:
287 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
288 case libTag:
289 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800290 if otherName == String(j.properties.Srcs_lib) {
291 srcs := dep.(SrcDependency).CompiledSrcs()
292 whitelistPathPrefixes := make(map[string]bool)
293 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
294 for _, src := range srcs {
295 if _, ok := src.(android.WritablePath); ok { // generated sources
296 deps.srcs = append(deps.srcs, src)
297 } else { // select source path for documentation based on whitelist path prefixs.
298 for k, _ := range whitelistPathPrefixes {
299 if strings.HasPrefix(src.Rel(), k) {
300 deps.srcs = append(deps.srcs, src)
301 break
302 }
303 }
304 }
305 }
306 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
307 }
Nan Zhang581fd212018-01-10 16:06:12 -0800308 default:
309 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
310 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900311 case SdkLibraryDependency:
312 switch tag {
313 case libTag:
314 sdkVersion := String(j.properties.Sdk_version)
315 linkType := javaSdk
316 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
317 linkType = javaSystem
318 } else if sdkVersion == "" {
319 linkType = javaPlatform
320 }
321 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
322 default:
323 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
324 }
Nan Zhang581fd212018-01-10 16:06:12 -0800325 case android.SourceFileProducer:
326 switch tag {
327 case libTag:
328 checkProducesJars(ctx, dep)
329 deps.classpath = append(deps.classpath, dep.Srcs()...)
330 case android.DefaultsDepTag, android.SourceDepTag:
331 // Nothing to do
332 default:
333 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName)
334 }
335 default:
336 switch tag {
Dan Willemsencc090972018-02-26 14:33:31 -0800337 case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag:
Nan Zhang581fd212018-01-10 16:06:12 -0800338 // Nothing to do
339 default:
340 ctx.ModuleErrorf("depends on non-java module %q", otherName)
341 }
342 }
343 })
344 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
345 // may contain filegroup or genrule.
346 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
347
348 // srcs may depend on some genrule output.
349 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800350 j.srcJars = append(j.srcJars, deps.srcJars...)
351
Nan Zhang581fd212018-01-10 16:06:12 -0800352 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800353 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800354
355 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800356 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800357
358 if j.properties.Local_sourcepaths == nil {
359 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
360 }
361 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800362
363 return deps
364}
365
366func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
367 j.addDeps(ctx)
368}
369
370func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
371 deps := j.collectDeps(ctx)
372
373 var implicits android.Paths
374 implicits = append(implicits, deps.bootClasspath...)
375 implicits = append(implicits, deps.classpath...)
376
377 var bootClasspathArgs, classpathArgs string
378 if ctx.Config().UseOpenJDK9() {
379 if len(deps.bootClasspath) > 0 {
380 // For OpenJDK 9 we use --patch-module to define the core libraries code.
381 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
382 // modules. Here we treat all code in core libraries as being in java.base
383 // to work around the OpenJDK 9 module system. http://b/62049770
384 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
385 }
386 } else {
387 if len(deps.bootClasspath.Strings()) > 0 {
388 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
389 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
390 }
391 }
392 if len(deps.classpath.Strings()) > 0 {
393 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
394 }
395
396 implicits = append(implicits, j.srcJars...)
397
398 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
399
400 ctx.Build(pctx, android.BuildParams{
401 Rule: javadoc,
402 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800403 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800404 ImplicitOutput: j.docZip,
405 Inputs: j.srcFiles,
406 Implicits: implicits,
407 Args: map[string]string{
408 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
409 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
410 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
411 "srcJars": strings.Join(j.srcJars.Strings(), " "),
412 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700413 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800414 "classpathArgs": classpathArgs,
415 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
416 "docZip": j.docZip.String(),
417 },
418 })
419}
420
421func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
422 d.Javadoc.addDeps(ctx)
423
Dan Willemsencc090972018-02-26 14:33:31 -0800424 if String(d.properties.Custom_template) == "" {
425 // TODO: This is almost always droiddoc-templates-sdk
426 ctx.PropertyErrorf("custom_template", "must specify a template")
427 } else {
428 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
429 }
430
Nan Zhang581fd212018-01-10 16:06:12 -0800431 // extra_arg_files may contains filegroup or genrule.
432 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
433
434 // knowntags may contain filegroup or genrule.
435 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
436}
437
438func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
439 deps := d.Javadoc.collectDeps(ctx)
440
441 var implicits android.Paths
442 implicits = append(implicits, deps.bootClasspath...)
443 implicits = append(implicits, deps.classpath...)
444
445 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
446 argFilesMap := map[string]android.Path{}
447
448 for _, f := range argFiles {
449 implicits = append(implicits, f)
450 if _, exists := argFilesMap[f.Rel()]; !exists {
451 argFilesMap[f.Rel()] = f
452 } else {
453 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
454 f, argFilesMap[f.Rel()], f.Rel())
455 }
456 }
457
458 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
459 if strings.HasPrefix(name, "location ") {
460 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
461 if f, ok := argFilesMap[label]; ok {
462 return f.String(), nil
463 } else {
464 return "", fmt.Errorf("unknown location label %q", label)
465 }
466 } else if name == "genDir" {
467 return android.PathForModuleGen(ctx).String(), nil
468 }
469 return "", fmt.Errorf("unknown variable '$(%s)'", name)
470 })
471
472 if err != nil {
473 ctx.PropertyErrorf("extra_args", "%s", err.Error())
474 return
475 }
476
477 var bootClasspathArgs, classpathArgs string
478 if len(deps.bootClasspath.Strings()) > 0 {
479 bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":")
480 }
481 if len(deps.classpath.Strings()) > 0 {
482 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
483 }
484
Dan Willemsencc090972018-02-26 14:33:31 -0800485 var templateDir string
486 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
487 if t, ok := m.(*DroiddocTemplate); ok {
488 implicits = append(implicits, t.deps...)
489 templateDir = t.dir.String()
490 } else {
491 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
492 }
493 })
Nan Zhang581fd212018-01-10 16:06:12 -0800494
495 var htmlDirArgs string
496 if len(d.properties.Html_dirs) > 0 {
Dan Willemsencc090972018-02-26 14:33:31 -0800497 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
498 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
499 htmlDirArgs = "-htmldir " + htmlDir.String()
Nan Zhang581fd212018-01-10 16:06:12 -0800500 }
501
502 var htmlDir2Args string
503 if len(d.properties.Html_dirs) > 1 {
Dan Willemsencc090972018-02-26 14:33:31 -0800504 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
505 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
506 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
507 }
508
509 if len(d.properties.Html_dirs) > 2 {
510 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
Nan Zhang581fd212018-01-10 16:06:12 -0800511 }
512
513 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
514 implicits = append(implicits, knownTags...)
515
516 for _, kt := range knownTags {
517 args = args + " -knowntags " + kt.String()
518 }
519 for _, hdf := range d.properties.Hdf {
520 args = args + " -hdf " + hdf
521 }
522
523 if String(d.properties.Proofread_file) != "" {
524 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
525 args = args + " -proofread " + proofreadFile.String()
526 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800527
Nan Zhang581fd212018-01-10 16:06:12 -0800528 if String(d.properties.Todo_file) != "" {
529 // tricky part:
530 // we should not compute full path for todo_file through PathForModuleOut().
531 // the non-standard doclet will get the full path relative to "-o".
532 args = args + " -todo " + String(d.properties.Todo_file)
533 }
534
Nan Zhangb2b33de2018-02-23 11:18:47 -0800535 if String(d.properties.Resourcesdir) != "" {
536 // TODO: should we add files under resourcesDir to the implicits? It seems that
537 // resourcesDir is one sub dir of htmlDir
538 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
539 args = args + " -resourcesdir " + resourcesDir.String()
540 }
541
542 if String(d.properties.Resourcesoutdir) != "" {
543 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
544 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
545 }
546
Nan Zhang28c68b92018-03-13 16:17:01 -0700547 var implicitOutputs android.WritablePaths
548 if String(d.properties.Api_filename) != "" {
549 d.apiFile = android.PathForModuleOut(ctx, String(d.properties.Api_filename))
550 args = args + " -api " + d.apiFile.String()
551 implicitOutputs = append(implicitOutputs, d.apiFile)
552 }
553
554 if String(d.properties.Private_api_filename) != "" {
555 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
556 args = args + " -privateApi " + d.privateApiFile.String()
557 implicitOutputs = append(implicitOutputs, d.privateApiFile)
558 }
559
560 if String(d.properties.Private_dex_api_filename) != "" {
561 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
562 args = args + " -privateDexApi " + d.privateDexApiFile.String()
563 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
564 }
565
566 if String(d.properties.Removed_api_filename) != "" {
567 d.removedApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_api_filename))
568 args = args + " -removedApi " + d.removedApiFile.String()
569 implicitOutputs = append(implicitOutputs, d.removedApiFile)
570 }
571
572 if String(d.properties.Exact_api_filename) != "" {
573 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
574 args = args + " -exactApi " + d.exactApiFile.String()
575 implicitOutputs = append(implicitOutputs, d.exactApiFile)
576 }
577
Nan Zhang581fd212018-01-10 16:06:12 -0800578 implicits = append(implicits, d.Javadoc.srcJars...)
579
580 opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
581 "-doclet com.google.doclava.Doclava -docletpath ${config.JsilverJar}:${config.DoclavaJar} " +
Colin Cross480cd762018-02-22 14:39:17 -0800582 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800583 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang853f4202018-04-12 16:55:56 -0700584 "-hdf page.now " + `"$$(date -d @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")"` +
585 " " + args
586 if BoolDefault(d.properties.Create_stubs, true) {
587 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
588 }
Nan Zhang581fd212018-01-10 16:06:12 -0800589
Nan Zhang581fd212018-01-10 16:06:12 -0800590 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
591 for _, o := range d.properties.Out {
592 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
593 }
594
595 ctx.Build(pctx, android.BuildParams{
596 Rule: javadoc,
597 Description: "Droiddoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800598 Output: d.Javadoc.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800599 Inputs: d.Javadoc.srcFiles,
600 Implicits: implicits,
601 ImplicitOutputs: implicitOutputs,
602 Args: map[string]string{
603 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
604 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
605 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
606 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
607 "opts": opts,
608 "bootclasspathArgs": bootClasspathArgs,
609 "classpathArgs": classpathArgs,
610 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
611 "docZip": d.Javadoc.docZip.String(),
612 "JsilverJar": "${config.JsilverJar}",
613 "DoclavaJar": "${config.DoclavaJar}",
614 },
615 })
616}
Dan Willemsencc090972018-02-26 14:33:31 -0800617
618var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
619
620type DroiddocTemplateProperties struct {
621 // path to the directory containing the droiddoc templates.
622 Path *string
623}
624
625type DroiddocTemplate struct {
626 android.ModuleBase
627
628 properties DroiddocTemplateProperties
629
630 deps android.Paths
631 dir android.Path
632}
633
634func DroiddocTemplateFactory() android.Module {
635 module := &DroiddocTemplate{}
636 module.AddProperties(&module.properties)
637 android.InitAndroidModule(module)
638 return module
639}
640
641func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
642
643func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
644 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
645 d.dir = path
646 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
647}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800648
649//
650// Defaults
651//
652type DocDefaults struct {
653 android.ModuleBase
654 android.DefaultsModuleBase
655}
656
657func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
658}
659
660func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
661}
662
663func DocDefaultsFactory() android.Module {
664 module := &DocDefaults{}
665
666 module.AddProperties(
667 &JavadocProperties{},
668 &DroiddocProperties{},
669 )
670
671 android.InitDefaultsModule(module)
672
673 return module
674}