blob: 2ed52c92194f186ad6a1b16029d684f0c5a922e2 [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 Zhang581fd212018-01-10 16:06:12 -0800156}
157
158type Javadoc struct {
159 android.ModuleBase
160 android.DefaultableModuleBase
161
162 properties JavadocProperties
163
164 srcJars android.Paths
165 srcFiles android.Paths
166 sourcepaths android.Paths
167
Nan Zhangccff0f72018-03-08 17:26:16 -0800168 docZip android.WritablePath
169 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800170}
171
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172func (j *Javadoc) Srcs() android.Paths {
173 return android.Paths{j.stubsSrcJar}
174}
175
176var _ android.SourceFileProducer = (*Javadoc)(nil)
177
Nan Zhang581fd212018-01-10 16:06:12 -0800178type Droiddoc struct {
179 Javadoc
180
Nan Zhang28c68b92018-03-13 16:17:01 -0700181 properties DroiddocProperties
182 apiFile android.WritablePath
183 privateApiFile android.WritablePath
184 privateDexApiFile android.WritablePath
185 removedApiFile android.WritablePath
186 exactApiFile android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800187}
188
189func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
190 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
191 android.InitDefaultableModule(module)
192}
193
194func JavadocFactory() android.Module {
195 module := &Javadoc{}
196
197 module.AddProperties(&module.properties)
198
199 InitDroiddocModule(module, android.HostAndDeviceSupported)
200 return module
201}
202
203func JavadocHostFactory() android.Module {
204 module := &Javadoc{}
205
206 module.AddProperties(&module.properties)
207
208 InitDroiddocModule(module, android.HostSupported)
209 return module
210}
211
212func DroiddocFactory() android.Module {
213 module := &Droiddoc{}
214
215 module.AddProperties(&module.properties,
216 &module.Javadoc.properties)
217
218 InitDroiddocModule(module, android.HostAndDeviceSupported)
219 return module
220}
221
222func DroiddocHostFactory() android.Module {
223 module := &Droiddoc{}
224
225 module.AddProperties(&module.properties,
226 &module.Javadoc.properties)
227
228 InitDroiddocModule(module, android.HostSupported)
229 return module
230}
231
232func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
233 if ctx.Device() {
234 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
235 if sdkDep.useDefaultLibs {
236 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800237 if Bool(j.properties.No_framework_libs) {
238 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
239 }
Nan Zhang581fd212018-01-10 16:06:12 -0800240 } else if sdkDep.useModule {
241 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
242 }
243 }
244
245 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
246
247 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
248
249 // exclude_srcs may contain filegroup or genrule.
250 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
251}
252
Nan Zhangb2b33de2018-02-23 11:18:47 -0800253func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
254 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
255 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
256 prefix := filepath.Join(dir, pkg)
257 if _, found := whitelistPathPrefixes[prefix]; !found {
258 whitelistPathPrefixes[prefix] = true
259 }
260 }
261 }
262}
263
Nan Zhang581fd212018-01-10 16:06:12 -0800264func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
265 var deps deps
266
267 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
268 if sdkDep.invalidVersion {
269 ctx.AddMissingDependencies([]string{sdkDep.module})
270 } else if sdkDep.useFiles {
271 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jar)
272 }
273
274 ctx.VisitDirectDeps(func(module android.Module) {
275 otherName := ctx.OtherModuleName(module)
276 tag := ctx.OtherModuleDependencyTag(module)
277
278 switch dep := module.(type) {
279 case Dependency:
280 switch tag {
281 case bootClasspathTag:
282 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
283 case libTag:
284 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800285 if otherName == String(j.properties.Srcs_lib) {
286 srcs := dep.(SrcDependency).CompiledSrcs()
287 whitelistPathPrefixes := make(map[string]bool)
288 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
289 for _, src := range srcs {
290 if _, ok := src.(android.WritablePath); ok { // generated sources
291 deps.srcs = append(deps.srcs, src)
292 } else { // select source path for documentation based on whitelist path prefixs.
293 for k, _ := range whitelistPathPrefixes {
294 if strings.HasPrefix(src.Rel(), k) {
295 deps.srcs = append(deps.srcs, src)
296 break
297 }
298 }
299 }
300 }
301 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
302 }
Nan Zhang581fd212018-01-10 16:06:12 -0800303 default:
304 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
305 }
306 case android.SourceFileProducer:
307 switch tag {
308 case libTag:
309 checkProducesJars(ctx, dep)
310 deps.classpath = append(deps.classpath, dep.Srcs()...)
311 case android.DefaultsDepTag, android.SourceDepTag:
312 // Nothing to do
313 default:
314 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName)
315 }
316 default:
317 switch tag {
Dan Willemsencc090972018-02-26 14:33:31 -0800318 case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag:
Nan Zhang581fd212018-01-10 16:06:12 -0800319 // Nothing to do
320 default:
321 ctx.ModuleErrorf("depends on non-java module %q", otherName)
322 }
323 }
324 })
325 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
326 // may contain filegroup or genrule.
327 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
328
329 // srcs may depend on some genrule output.
330 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800331 j.srcJars = append(j.srcJars, deps.srcJars...)
332
Nan Zhang581fd212018-01-10 16:06:12 -0800333 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800334 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800335
336 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800337 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800338
339 if j.properties.Local_sourcepaths == nil {
340 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
341 }
342 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
343 j.sourcepaths = append(j.sourcepaths, deps.bootClasspath...)
344 j.sourcepaths = append(j.sourcepaths, deps.classpath...)
345
346 return deps
347}
348
349func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
350 j.addDeps(ctx)
351}
352
353func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
354 deps := j.collectDeps(ctx)
355
356 var implicits android.Paths
357 implicits = append(implicits, deps.bootClasspath...)
358 implicits = append(implicits, deps.classpath...)
359
360 var bootClasspathArgs, classpathArgs string
361 if ctx.Config().UseOpenJDK9() {
362 if len(deps.bootClasspath) > 0 {
363 // For OpenJDK 9 we use --patch-module to define the core libraries code.
364 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
365 // modules. Here we treat all code in core libraries as being in java.base
366 // to work around the OpenJDK 9 module system. http://b/62049770
367 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
368 }
369 } else {
370 if len(deps.bootClasspath.Strings()) > 0 {
371 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
372 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
373 }
374 }
375 if len(deps.classpath.Strings()) > 0 {
376 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
377 }
378
379 implicits = append(implicits, j.srcJars...)
380
381 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
382
383 ctx.Build(pctx, android.BuildParams{
384 Rule: javadoc,
385 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800386 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800387 ImplicitOutput: j.docZip,
388 Inputs: j.srcFiles,
389 Implicits: implicits,
390 Args: map[string]string{
391 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
392 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
393 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
394 "srcJars": strings.Join(j.srcJars.Strings(), " "),
395 "opts": opts,
396 "bootClasspathArgs": bootClasspathArgs,
397 "classpathArgs": classpathArgs,
398 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
399 "docZip": j.docZip.String(),
400 },
401 })
402}
403
404func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
405 d.Javadoc.addDeps(ctx)
406
Dan Willemsencc090972018-02-26 14:33:31 -0800407 if String(d.properties.Custom_template) == "" {
408 // TODO: This is almost always droiddoc-templates-sdk
409 ctx.PropertyErrorf("custom_template", "must specify a template")
410 } else {
411 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
412 }
413
Nan Zhang581fd212018-01-10 16:06:12 -0800414 // extra_arg_files may contains filegroup or genrule.
415 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
416
417 // knowntags may contain filegroup or genrule.
418 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
419}
420
421func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
422 deps := d.Javadoc.collectDeps(ctx)
423
424 var implicits android.Paths
425 implicits = append(implicits, deps.bootClasspath...)
426 implicits = append(implicits, deps.classpath...)
427
428 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
429 argFilesMap := map[string]android.Path{}
430
431 for _, f := range argFiles {
432 implicits = append(implicits, f)
433 if _, exists := argFilesMap[f.Rel()]; !exists {
434 argFilesMap[f.Rel()] = f
435 } else {
436 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
437 f, argFilesMap[f.Rel()], f.Rel())
438 }
439 }
440
441 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
442 if strings.HasPrefix(name, "location ") {
443 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
444 if f, ok := argFilesMap[label]; ok {
445 return f.String(), nil
446 } else {
447 return "", fmt.Errorf("unknown location label %q", label)
448 }
449 } else if name == "genDir" {
450 return android.PathForModuleGen(ctx).String(), nil
451 }
452 return "", fmt.Errorf("unknown variable '$(%s)'", name)
453 })
454
455 if err != nil {
456 ctx.PropertyErrorf("extra_args", "%s", err.Error())
457 return
458 }
459
460 var bootClasspathArgs, classpathArgs string
461 if len(deps.bootClasspath.Strings()) > 0 {
462 bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":")
463 }
464 if len(deps.classpath.Strings()) > 0 {
465 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
466 }
467
Dan Willemsencc090972018-02-26 14:33:31 -0800468 var templateDir string
469 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
470 if t, ok := m.(*DroiddocTemplate); ok {
471 implicits = append(implicits, t.deps...)
472 templateDir = t.dir.String()
473 } else {
474 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
475 }
476 })
Nan Zhang581fd212018-01-10 16:06:12 -0800477
478 var htmlDirArgs string
479 if len(d.properties.Html_dirs) > 0 {
Dan Willemsencc090972018-02-26 14:33:31 -0800480 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
481 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
482 htmlDirArgs = "-htmldir " + htmlDir.String()
Nan Zhang581fd212018-01-10 16:06:12 -0800483 }
484
485 var htmlDir2Args string
486 if len(d.properties.Html_dirs) > 1 {
Dan Willemsencc090972018-02-26 14:33:31 -0800487 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
488 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
489 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
490 }
491
492 if len(d.properties.Html_dirs) > 2 {
493 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
Nan Zhang581fd212018-01-10 16:06:12 -0800494 }
495
496 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
497 implicits = append(implicits, knownTags...)
498
499 for _, kt := range knownTags {
500 args = args + " -knowntags " + kt.String()
501 }
502 for _, hdf := range d.properties.Hdf {
503 args = args + " -hdf " + hdf
504 }
505
506 if String(d.properties.Proofread_file) != "" {
507 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
508 args = args + " -proofread " + proofreadFile.String()
509 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800510
Nan Zhang581fd212018-01-10 16:06:12 -0800511 if String(d.properties.Todo_file) != "" {
512 // tricky part:
513 // we should not compute full path for todo_file through PathForModuleOut().
514 // the non-standard doclet will get the full path relative to "-o".
515 args = args + " -todo " + String(d.properties.Todo_file)
516 }
517
Nan Zhangb2b33de2018-02-23 11:18:47 -0800518 if String(d.properties.Resourcesdir) != "" {
519 // TODO: should we add files under resourcesDir to the implicits? It seems that
520 // resourcesDir is one sub dir of htmlDir
521 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
522 args = args + " -resourcesdir " + resourcesDir.String()
523 }
524
525 if String(d.properties.Resourcesoutdir) != "" {
526 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
527 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
528 }
529
Nan Zhang28c68b92018-03-13 16:17:01 -0700530 var implicitOutputs android.WritablePaths
531 if String(d.properties.Api_filename) != "" {
532 d.apiFile = android.PathForModuleOut(ctx, String(d.properties.Api_filename))
533 args = args + " -api " + d.apiFile.String()
534 implicitOutputs = append(implicitOutputs, d.apiFile)
535 }
536
537 if String(d.properties.Private_api_filename) != "" {
538 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
539 args = args + " -privateApi " + d.privateApiFile.String()
540 implicitOutputs = append(implicitOutputs, d.privateApiFile)
541 }
542
543 if String(d.properties.Private_dex_api_filename) != "" {
544 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
545 args = args + " -privateDexApi " + d.privateDexApiFile.String()
546 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
547 }
548
549 if String(d.properties.Removed_api_filename) != "" {
550 d.removedApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_api_filename))
551 args = args + " -removedApi " + d.removedApiFile.String()
552 implicitOutputs = append(implicitOutputs, d.removedApiFile)
553 }
554
555 if String(d.properties.Exact_api_filename) != "" {
556 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
557 args = args + " -exactApi " + d.exactApiFile.String()
558 implicitOutputs = append(implicitOutputs, d.exactApiFile)
559 }
560
Nan Zhang581fd212018-01-10 16:06:12 -0800561 implicits = append(implicits, d.Javadoc.srcJars...)
562
563 opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
564 "-doclet com.google.doclava.Doclava -docletpath ${config.JsilverJar}:${config.DoclavaJar} " +
Colin Cross480cd762018-02-22 14:39:17 -0800565 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800566 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
567 "-hdf page.now " + `"$$(date -d @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")"` + " " +
568 args + " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
569
Nan Zhang581fd212018-01-10 16:06:12 -0800570 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
571 for _, o := range d.properties.Out {
572 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
573 }
574
575 ctx.Build(pctx, android.BuildParams{
576 Rule: javadoc,
577 Description: "Droiddoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800578 Output: d.Javadoc.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800579 Inputs: d.Javadoc.srcFiles,
580 Implicits: implicits,
581 ImplicitOutputs: implicitOutputs,
582 Args: map[string]string{
583 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
584 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
585 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
586 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
587 "opts": opts,
588 "bootclasspathArgs": bootClasspathArgs,
589 "classpathArgs": classpathArgs,
590 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
591 "docZip": d.Javadoc.docZip.String(),
592 "JsilverJar": "${config.JsilverJar}",
593 "DoclavaJar": "${config.DoclavaJar}",
594 },
595 })
596}
Dan Willemsencc090972018-02-26 14:33:31 -0800597
598var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
599
600type DroiddocTemplateProperties struct {
601 // path to the directory containing the droiddoc templates.
602 Path *string
603}
604
605type DroiddocTemplate struct {
606 android.ModuleBase
607
608 properties DroiddocTemplateProperties
609
610 deps android.Paths
611 dir android.Path
612}
613
614func DroiddocTemplateFactory() android.Module {
615 module := &DroiddocTemplate{}
616 module.AddProperties(&module.properties)
617 android.InitAndroidModule(module)
618 return module
619}
620
621func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
622
623func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
624 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
625 d.dir = path
626 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
627}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800628
629//
630// Defaults
631//
632type DocDefaults struct {
633 android.ModuleBase
634 android.DefaultsModuleBase
635}
636
637func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
638}
639
640func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
641}
642
643func DocDefaultsFactory() android.Module {
644 module := &DocDefaults{}
645
646 module.AddProperties(
647 &JavadocProperties{},
648 &DroiddocProperties{},
649 )
650
651 android.InitDefaultsModule(module)
652
653 return module
654}