blob: beaec11e992d66e613e4f8dfdd12356959d5abcc [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 Zhang46130972018-06-04 11:28:01 -070022 "runtime"
Nan Zhang581fd212018-01-10 16:06:12 -080023 "strings"
24
25 "github.com/google/blueprint"
26)
27
28var (
29 javadoc = pctx.AndroidStaticRule("javadoc",
30 blueprint.RuleParams{
31 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070032 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang581fd212018-01-10 16:06:12 -080033 `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
34 `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
35 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
37 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
38 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070039 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080040 "${config.JavadocCmd}",
41 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 },
43 Rspfile: "$out.rsp",
44 RspfileContent: "$in",
45 Restat: true,
46 },
47 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang30963742018-04-23 09:59:14 -070048 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip")
Nan Zhang61819ce2018-05-04 18:49:16 -070049
50 apiCheck = pctx.AndroidStaticRule("apiCheck",
51 blueprint.RuleParams{
52 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
53 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090054 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070055 CommandDeps: []string{
56 "${config.ApiCheckCmd}",
57 },
58 },
59 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
60
61 updateApi = pctx.AndroidStaticRule("updateApi",
62 blueprint.RuleParams{
63 Command: `( ( cp -f $apiFileToCheck $apiFile && cp -f $removedApiFileToCheck $removedApiFile ) ` +
64 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
65 },
66 "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck")
Nan Zhang79614d12018-04-19 18:03:39 -070067
68 metalava = pctx.AndroidStaticRule("metalava",
69 blueprint.RuleParams{
70 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
71 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
72 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source 1.8 @$out.rsp @$srcJarDir/list ` +
73 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color ` +
74 `--stubs $stubsDir --quiet --write-stubs-source-list $outDir/stubs_src_list $opts && ` +
75 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
76 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
77 CommandDeps: []string{
78 "${config.ZipSyncCmd}",
79 "${config.JavaCmd}",
80 "${config.MetalavaJar}",
81 "${config.JavadocCmd}",
82 "${config.SoongZipCmd}",
83 },
84 Rspfile: "$out.rsp",
85 RspfileContent: "$in",
86 Restat: true,
87 },
88 "outDir", "srcJarDir", "stubsDir", "srcJars", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -080089)
90
91func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080092 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
93
Nan Zhang581fd212018-01-10 16:06:12 -080094 android.RegisterModuleType("droiddoc", DroiddocFactory)
95 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Dan Willemsencc090972018-02-26 14:33:31 -080096 android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080097 android.RegisterModuleType("javadoc", JavadocFactory)
98 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
99}
100
101type JavadocProperties struct {
102 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
103 // or .aidl files.
104 Srcs []string `android:"arch_variant"`
105
106 // list of directories rooted at the Android.bp file that will
107 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800108 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800109
110 // list of source files that should not be used to build the Java module.
111 // This is most useful in the arch/multilib variants to remove non-common files
112 // filegroup or genrule can be included within this property.
113 Exclude_srcs []string `android:"arch_variant"`
114
Nan Zhangb2b33de2018-02-23 11:18:47 -0800115 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800116 Libs []string `android:"arch_variant"`
117
Nan Zhange66c7272018-03-06 12:59:27 -0800118 // don't build against the framework libraries (legacy-test, core-junit,
119 // ext, and framework for device targets)
120 No_framework_libs *bool
121
Nan Zhangb2b33de2018-02-23 11:18:47 -0800122 // the java library (in classpath) for documentation that provides java srcs and srcjars.
123 Srcs_lib *string
124
125 // the base dirs under srcs_lib will be scanned for java srcs.
126 Srcs_lib_whitelist_dirs []string
127
128 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
129 Srcs_lib_whitelist_pkgs []string
130
Nan Zhang581fd212018-01-10 16:06:12 -0800131 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // if not blank, set to the version of the sdk to compile against
135 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900136
137 Aidl struct {
138 // Top level directories to pass to aidl tool
139 Include_dirs []string
140
141 // Directories rooted at the Android.bp file to pass to aidl tool
142 Local_include_dirs []string
143 }
Nan Zhang581fd212018-01-10 16:06:12 -0800144}
145
Nan Zhang61819ce2018-05-04 18:49:16 -0700146type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900147 // path to the API txt file that the new API extracted from source code is checked
148 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700149 Api_file *string
150
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900151 // path to the API txt file that the new @removed API extractd from source code is
152 // checked against. The path can be local to the module or from other module (via
153 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700154 Removed_api_file *string
155
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900156 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700157 Args *string
158}
159
Nan Zhang581fd212018-01-10 16:06:12 -0800160type DroiddocProperties struct {
161 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800162 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800163
164 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800165 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800166
167 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800168 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800169
170 // proofread file contains all of the text content of the javadocs concatenated into one file,
171 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800173
174 // a todo file lists the program elements that are missing documentation.
175 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800176 Todo_file *string
177
178 // directory under current module source that provide additional resources (images).
179 Resourcesdir *string
180
181 // resources output directory under out/soong/.intermediates.
182 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800183
184 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800185 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800186
187 // user customized droiddoc args.
188 // Available variables for substitution:
189 //
190 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800191 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800192
193 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800194 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800195
196 // a list of files under current module source dir which contains known tags in Java sources.
197 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800198 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700199
200 // the tag name used to distinguish if the API files belong to public/system/test.
201 Api_tag_name *string
202
203 // the generated public API filename by Doclava.
204 Api_filename *string
205
206 // the generated private API filename by Doclava.
207 Private_api_filename *string
208
209 // the generated private Dex API filename by Doclava.
210 Private_dex_api_filename *string
211
212 // the generated removed API filename by Doclava.
213 Removed_api_filename *string
214
David Brazdilaac0c3c2018-04-24 16:23:29 +0100215 // the generated removed Dex API filename by Doclava.
216 Removed_dex_api_filename *string
217
Nan Zhang28c68b92018-03-13 16:17:01 -0700218 // the generated exact API filename by Doclava.
219 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700220
221 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
222 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700223
224 Check_api struct {
225 Last_released ApiToCheck
226
227 Current ApiToCheck
228 }
Nan Zhang79614d12018-04-19 18:03:39 -0700229
230 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
231 // currently still used for documentation generation, and will be replaced by Dokka soon.
232 Metalava_enabled *bool
233
234 // user can specify the version of previous released API file in order to do compatibility check.
235 Metalava_previous_api *string
236
237 // is set to true, Metalava will allow framework SDK to contain annotations.
238 Metalava_annotations_enabled *bool
239
240 // a XML files set to merge annotations.
241 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800242}
243
244type Javadoc struct {
245 android.ModuleBase
246 android.DefaultableModuleBase
247
248 properties JavadocProperties
249
250 srcJars android.Paths
251 srcFiles android.Paths
252 sourcepaths android.Paths
253
Nan Zhangccff0f72018-03-08 17:26:16 -0800254 docZip android.WritablePath
255 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800256}
257
Nan Zhangb2b33de2018-02-23 11:18:47 -0800258func (j *Javadoc) Srcs() android.Paths {
259 return android.Paths{j.stubsSrcJar}
260}
261
262var _ android.SourceFileProducer = (*Javadoc)(nil)
263
Nan Zhang581fd212018-01-10 16:06:12 -0800264type Droiddoc struct {
265 Javadoc
266
Nan Zhang28c68b92018-03-13 16:17:01 -0700267 properties DroiddocProperties
268 apiFile android.WritablePath
269 privateApiFile android.WritablePath
270 privateDexApiFile android.WritablePath
271 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100272 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700273 exactApiFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700274
275 checkCurrentApiTimestamp android.WritablePath
276 updateCurrentApiTimestamp android.WritablePath
277 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800278}
279
280func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
281 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
282 android.InitDefaultableModule(module)
283}
284
285func JavadocFactory() android.Module {
286 module := &Javadoc{}
287
288 module.AddProperties(&module.properties)
289
290 InitDroiddocModule(module, android.HostAndDeviceSupported)
291 return module
292}
293
294func JavadocHostFactory() android.Module {
295 module := &Javadoc{}
296
297 module.AddProperties(&module.properties)
298
299 InitDroiddocModule(module, android.HostSupported)
300 return module
301}
302
303func DroiddocFactory() android.Module {
304 module := &Droiddoc{}
305
306 module.AddProperties(&module.properties,
307 &module.Javadoc.properties)
308
309 InitDroiddocModule(module, android.HostAndDeviceSupported)
310 return module
311}
312
313func DroiddocHostFactory() android.Module {
314 module := &Droiddoc{}
315
316 module.AddProperties(&module.properties,
317 &module.Javadoc.properties)
318
319 InitDroiddocModule(module, android.HostSupported)
320 return module
321}
322
323func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
324 if ctx.Device() {
325 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
326 if sdkDep.useDefaultLibs {
327 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang9cbe6772018-03-21 17:56:39 -0700328 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800329 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
330 }
Nan Zhang581fd212018-01-10 16:06:12 -0800331 } else if sdkDep.useModule {
Colin Cross86a60ae2018-05-29 14:44:55 -0700332 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800333 }
334 }
335
336 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
337
338 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
339
340 // exclude_srcs may contain filegroup or genrule.
341 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
342}
343
Nan Zhangb2b33de2018-02-23 11:18:47 -0800344func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
345 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
346 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900347 // convert foo.bar.baz to foo/bar/baz
348 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
349 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800350 if _, found := whitelistPathPrefixes[prefix]; !found {
351 whitelistPathPrefixes[prefix] = true
352 }
353 }
354 }
355}
356
Jiyong Park1e440682018-05-23 18:42:04 +0900357func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
358 var flags javaBuilderFlags
359
360 // aidl flags.
361 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
362 if len(aidlFlags) > 0 {
363 // optimization.
364 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
365 flags.aidlFlags = "$aidlFlags"
366 }
367
368 return flags
369}
370
371func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
372 aidlIncludeDirs android.Paths) []string {
373
374 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
375 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
376
377 var flags []string
378 if aidlPreprocess.Valid() {
379 flags = append(flags, "-p"+aidlPreprocess.String())
380 } else {
381 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
382 }
383
384 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
385 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
386 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
387 flags = append(flags, "-I"+src.String())
388 }
389
390 return flags
391}
392
393func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
394 flags javaBuilderFlags) android.Paths {
395
396 outSrcFiles := make(android.Paths, 0, len(srcFiles))
397
398 for _, srcFile := range srcFiles {
399 switch srcFile.Ext() {
400 case ".aidl":
401 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
402 outSrcFiles = append(outSrcFiles, javaFile)
403 default:
404 outSrcFiles = append(outSrcFiles, srcFile)
405 }
406 }
407
408 return outSrcFiles
409}
410
Nan Zhang581fd212018-01-10 16:06:12 -0800411func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
412 var deps deps
413
414 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
415 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700416 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800417 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700418 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800419 }
420
421 ctx.VisitDirectDeps(func(module android.Module) {
422 otherName := ctx.OtherModuleName(module)
423 tag := ctx.OtherModuleDependencyTag(module)
424
425 switch dep := module.(type) {
426 case Dependency:
427 switch tag {
428 case bootClasspathTag:
429 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
430 case libTag:
431 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800432 if otherName == String(j.properties.Srcs_lib) {
433 srcs := dep.(SrcDependency).CompiledSrcs()
434 whitelistPathPrefixes := make(map[string]bool)
435 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
436 for _, src := range srcs {
437 if _, ok := src.(android.WritablePath); ok { // generated sources
438 deps.srcs = append(deps.srcs, src)
439 } else { // select source path for documentation based on whitelist path prefixs.
440 for k, _ := range whitelistPathPrefixes {
441 if strings.HasPrefix(src.Rel(), k) {
442 deps.srcs = append(deps.srcs, src)
443 break
444 }
445 }
446 }
447 }
448 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
449 }
Nan Zhang581fd212018-01-10 16:06:12 -0800450 default:
451 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
452 }
Jiyong Parkc678ad32018-04-10 13:07:10 +0900453 case SdkLibraryDependency:
454 switch tag {
455 case libTag:
456 sdkVersion := String(j.properties.Sdk_version)
457 linkType := javaSdk
458 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
459 linkType = javaSystem
460 } else if sdkVersion == "" {
461 linkType = javaPlatform
462 }
463 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
464 default:
465 ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
466 }
Nan Zhang581fd212018-01-10 16:06:12 -0800467 case android.SourceFileProducer:
468 switch tag {
469 case libTag:
470 checkProducesJars(ctx, dep)
471 deps.classpath = append(deps.classpath, dep.Srcs()...)
472 case android.DefaultsDepTag, android.SourceDepTag:
473 // Nothing to do
474 default:
475 ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName)
476 }
477 default:
478 switch tag {
Dan Willemsencc090972018-02-26 14:33:31 -0800479 case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag:
Nan Zhang581fd212018-01-10 16:06:12 -0800480 // Nothing to do
481 default:
482 ctx.ModuleErrorf("depends on non-java module %q", otherName)
483 }
484 }
485 })
486 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
487 // may contain filegroup or genrule.
488 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900489 flags := j.collectBuilderFlags(ctx, deps)
490 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800491
492 // srcs may depend on some genrule output.
493 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800494 j.srcJars = append(j.srcJars, deps.srcJars...)
495
Nan Zhang581fd212018-01-10 16:06:12 -0800496 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800497 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800498
499 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800500 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800501
502 if j.properties.Local_sourcepaths == nil {
503 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
504 }
505 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800506
507 return deps
508}
509
510func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
511 j.addDeps(ctx)
512}
513
514func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
515 deps := j.collectDeps(ctx)
516
517 var implicits android.Paths
518 implicits = append(implicits, deps.bootClasspath...)
519 implicits = append(implicits, deps.classpath...)
520
521 var bootClasspathArgs, classpathArgs string
522 if ctx.Config().UseOpenJDK9() {
523 if len(deps.bootClasspath) > 0 {
524 // For OpenJDK 9 we use --patch-module to define the core libraries code.
525 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
526 // modules. Here we treat all code in core libraries as being in java.base
527 // to work around the OpenJDK 9 module system. http://b/62049770
528 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
529 }
530 } else {
531 if len(deps.bootClasspath.Strings()) > 0 {
532 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
533 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
534 }
535 }
536 if len(deps.classpath.Strings()) > 0 {
537 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
538 }
539
540 implicits = append(implicits, j.srcJars...)
541
542 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
543
544 ctx.Build(pctx, android.BuildParams{
545 Rule: javadoc,
546 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800547 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800548 ImplicitOutput: j.docZip,
549 Inputs: j.srcFiles,
550 Implicits: implicits,
551 Args: map[string]string{
552 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
553 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
554 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
555 "srcJars": strings.Join(j.srcJars.Strings(), " "),
556 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700557 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800558 "classpathArgs": classpathArgs,
559 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
560 "docZip": j.docZip.String(),
561 },
562 })
563}
564
Nan Zhang61819ce2018-05-04 18:49:16 -0700565func (d *Droiddoc) checkCurrentApi() bool {
566 if String(d.properties.Check_api.Current.Api_file) != "" &&
567 String(d.properties.Check_api.Current.Removed_api_file) != "" {
568 return true
569 } else if String(d.properties.Check_api.Current.Api_file) != "" {
570 panic("check_api.current.removed_api_file: has to be non empty!")
571 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
572 panic("check_api.current.api_file: has to be non empty!")
573 }
574
575 return false
576}
577
578func (d *Droiddoc) checkLastReleasedApi() bool {
579 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
580 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
581 return true
582 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
583 panic("check_api.last_released.removed_api_file: has to be non empty!")
584 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
585 panic("check_api.last_released.api_file: has to be non empty!")
586 }
587
588 return false
589}
590
Nan Zhang581fd212018-01-10 16:06:12 -0800591func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
592 d.Javadoc.addDeps(ctx)
593
Nan Zhang79614d12018-04-19 18:03:39 -0700594 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800595 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
596 }
597
Nan Zhang581fd212018-01-10 16:06:12 -0800598 // extra_arg_files may contains filegroup or genrule.
599 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
600
601 // knowntags may contain filegroup or genrule.
602 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700603
604 if d.checkCurrentApi() {
605 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
606 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
607 }
608
609 if d.checkLastReleasedApi() {
610 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
611 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
612 }
Nan Zhang79614d12018-04-19 18:03:39 -0700613
614 if String(d.properties.Metalava_previous_api) != "" {
615 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
616 }
Nan Zhang581fd212018-01-10 16:06:12 -0800617}
618
619func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
620 deps := d.Javadoc.collectDeps(ctx)
621
622 var implicits android.Paths
623 implicits = append(implicits, deps.bootClasspath...)
624 implicits = append(implicits, deps.classpath...)
625
Nan Zhang79614d12018-04-19 18:03:39 -0700626 bootClasspathArgs := deps.bootClasspath.FormJavaClassPath("-bootclasspath")
627 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
628
Nan Zhang581fd212018-01-10 16:06:12 -0800629 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
630 argFilesMap := map[string]android.Path{}
631
632 for _, f := range argFiles {
633 implicits = append(implicits, f)
634 if _, exists := argFilesMap[f.Rel()]; !exists {
635 argFilesMap[f.Rel()] = f
636 } else {
637 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
638 f, argFilesMap[f.Rel()], f.Rel())
639 }
640 }
641
642 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
643 if strings.HasPrefix(name, "location ") {
644 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
645 if f, ok := argFilesMap[label]; ok {
646 return f.String(), nil
647 } else {
648 return "", fmt.Errorf("unknown location label %q", label)
649 }
650 } else if name == "genDir" {
651 return android.PathForModuleGen(ctx).String(), nil
652 }
653 return "", fmt.Errorf("unknown variable '$(%s)'", name)
654 })
655
656 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700657 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800658 return
659 }
660
Nan Zhang79614d12018-04-19 18:03:39 -0700661 genDocsForMetalava := false
662 var metalavaArgs string
663 if Bool(d.properties.Metalava_enabled) {
664 if strings.Contains(args, "--generate-documentation") {
665 if !strings.Contains(args, "-nodocs") {
666 genDocsForMetalava = true
667 }
668 // TODO(nanzhang): Add a Soong property to handle documentation args.
669 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800670 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700671 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800672 }
Nan Zhang581fd212018-01-10 16:06:12 -0800673 }
674
Nan Zhang79614d12018-04-19 18:03:39 -0700675 var templateDir, htmlDirArgs, htmlDir2Args string
676 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
677 if String(d.properties.Custom_template) == "" {
678 // TODO: This is almost always droiddoc-templates-sdk
679 ctx.PropertyErrorf("custom_template", "must specify a template")
680 }
681
682 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
683 if t, ok := m.(*DroiddocTemplate); ok {
684 implicits = append(implicits, t.deps...)
685 templateDir = t.dir.String()
686 } else {
687 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
688 }
689 })
690
691 if len(d.properties.Html_dirs) > 0 {
692 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
693 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
694 htmlDirArgs = "-htmldir " + htmlDir.String()
695 }
696
697 if len(d.properties.Html_dirs) > 1 {
698 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
699 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
700 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
701 }
702
703 if len(d.properties.Html_dirs) > 2 {
704 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
705 }
706
707 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
708 implicits = append(implicits, knownTags...)
709
710 for _, kt := range knownTags {
711 args = args + " -knowntags " + kt.String()
712 }
713
714 for _, hdf := range d.properties.Hdf {
715 args = args + " -hdf " + hdf
716 }
717
718 if String(d.properties.Proofread_file) != "" {
719 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
720 args = args + " -proofread " + proofreadFile.String()
721 }
722
723 if String(d.properties.Todo_file) != "" {
724 // tricky part:
725 // we should not compute full path for todo_file through PathForModuleOut().
726 // the non-standard doclet will get the full path relative to "-o".
727 args = args + " -todo " + String(d.properties.Todo_file)
728 }
729
730 if String(d.properties.Resourcesdir) != "" {
731 // TODO: should we add files under resourcesDir to the implicits? It seems that
732 // resourcesDir is one sub dir of htmlDir
733 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
734 args = args + " -resourcesdir " + resourcesDir.String()
735 }
736
737 if String(d.properties.Resourcesoutdir) != "" {
738 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
739 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
740 }
Dan Willemsencc090972018-02-26 14:33:31 -0800741 }
742
Nan Zhang79614d12018-04-19 18:03:39 -0700743 var docArgsForMetalava string
744 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
745 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800746 }
747
Nan Zhang28c68b92018-03-13 16:17:01 -0700748 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700749
750 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
751 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700752 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700753 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700754 implicitOutputs = append(implicitOutputs, d.apiFile)
755 }
756
Nan Zhang61819ce2018-05-04 18:49:16 -0700757 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
758 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
759 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700760 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700761 implicitOutputs = append(implicitOutputs, d.removedApiFile)
762 }
763
Nan Zhang28c68b92018-03-13 16:17:01 -0700764 if String(d.properties.Private_api_filename) != "" {
765 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
766 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700767 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700768 implicitOutputs = append(implicitOutputs, d.privateApiFile)
769 }
770
771 if String(d.properties.Private_dex_api_filename) != "" {
772 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
773 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700774 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700775 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
776 }
777
David Brazdilaac0c3c2018-04-24 16:23:29 +0100778 if String(d.properties.Removed_dex_api_filename) != "" {
779 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
780 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700781 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100782 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
783 }
784
Nan Zhang28c68b92018-03-13 16:17:01 -0700785 if String(d.properties.Exact_api_filename) != "" {
786 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
787 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700788 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700789 implicitOutputs = append(implicitOutputs, d.exactApiFile)
790 }
791
Nan Zhang581fd212018-01-10 16:06:12 -0800792 implicits = append(implicits, d.Javadoc.srcJars...)
793
Nan Zhang79614d12018-04-19 18:03:39 -0700794 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
795 for _, o := range d.properties.Out {
796 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
797 }
798
Nan Zhang30963742018-04-23 09:59:14 -0700799 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
800 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700801
Nan Zhang46130972018-06-04 11:28:01 -0700802 var date string
803 if runtime.GOOS == "darwin" {
804 date = `date -r`
805 } else {
806 date = `date -d`
807 }
808
Nan Zhang79614d12018-04-19 18:03:39 -0700809 doclavaOpts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700810 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800811 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800812 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700813 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700814
Nan Zhang79614d12018-04-19 18:03:39 -0700815 if !Bool(d.properties.Metalava_enabled) {
816 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800817
Nan Zhang79614d12018-04-19 18:03:39 -0700818 implicits = append(implicits, jsilver)
819 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800820
Nan Zhang79614d12018-04-19 18:03:39 -0700821 if BoolDefault(d.properties.Create_stubs, true) {
822 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
823 }
824
825 ctx.Build(pctx, android.BuildParams{
826 Rule: javadoc,
827 Description: "Droiddoc",
828 Output: d.Javadoc.stubsSrcJar,
829 Inputs: d.Javadoc.srcFiles,
830 Implicits: implicits,
831 ImplicitOutputs: implicitOutputs,
832 Args: map[string]string{
833 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
834 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
835 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
836 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
837 "opts": opts,
838 "bootclasspathArgs": bootClasspathArgs,
839 "classpathArgs": classpathArgs,
840 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
841 "docZip": d.Javadoc.docZip.String(),
842 },
843 })
844 } else {
845 opts := metalavaArgs
846
847 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800848 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
849 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
850 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
851 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang581fd212018-01-10 16:06:12 -0800852 "bootclasspathArgs": bootClasspathArgs,
853 "classpathArgs": classpathArgs,
854 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
855 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700856 }
857
858 var previousApi android.Path
859 if String(d.properties.Metalava_previous_api) != "" {
860 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
861 "metalava_previous_api")
862 opts += " --check-compatibility --previous-api " + previousApi.String()
863 implicits = append(implicits, previousApi)
864 }
865
866 if Bool(d.properties.Metalava_annotations_enabled) {
867 if String(d.properties.Metalava_previous_api) == "" {
868 ctx.PropertyErrorf("metalava_previous_api",
869 "has to be non-empty if annotations was enabled!")
870 }
871 opts += " --include-annotations --migrate-nullness"
872
873 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
874 implicitOutputs = append(implicitOutputs, annotationsZip)
875
876 if String(d.properties.Metalava_merge_annotations_dir) == "" {
877 ctx.PropertyErrorf("metalava_merge_annotations",
878 "has to be non-empty if annotations was enabled!")
879 }
880
881 mergeAnnotationsDir := android.PathForModuleSrc(ctx,
882 String(d.properties.Metalava_merge_annotations_dir))
883 implicits = append(implicits, ctx.Glob(mergeAnnotationsDir.Join(ctx, "**/*").String(), nil)...)
884
885 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
886 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
887 opts += "--hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
888 }
889
890 if genDocsForMetalava {
891 opts += " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 STUBS_SOURCE_LIST " +
892 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
893 strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + " -quiet -d $outDir "
894 implicits = append(implicits, jsilver)
895 implicits = append(implicits, doclava)
896 }
897
898 buildArgs["opts"] = opts
899 ctx.Build(pctx, android.BuildParams{
900 Rule: metalava,
901 Description: "Metalava",
902 Output: d.Javadoc.stubsSrcJar,
903 Inputs: d.Javadoc.srcFiles,
904 Implicits: implicits,
905 ImplicitOutputs: implicitOutputs,
906 Args: buildArgs,
907 })
908 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700909
910 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
911
912 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
913
914 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
915 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
916
917 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
918 "check_api.current.api_file")
919 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
920 "check_api.current_removed_api_file")
921
922 ctx.Build(pctx, android.BuildParams{
923 Rule: apiCheck,
924 Description: "Current API check",
925 Output: d.checkCurrentApiTimestamp,
926 Inputs: nil,
927 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
928 checkApiClasspath...),
929 Args: map[string]string{
930 "classpath": checkApiClasspath.FormJavaClassPath(""),
931 "opts": String(d.properties.Check_api.Current.Args),
932 "apiFile": apiFile.String(),
933 "apiFileToCheck": d.apiFile.String(),
934 "removedApiFile": removedApiFile.String(),
935 "removedApiFileToCheck": d.removedApiFile.String(),
936 "msg": fmt.Sprintf(`\n******************************\n`+
937 `You have tried to change the API from what has been previously approved.\n\n`+
938 `To make these errors go away, you have two choices:\n`+
939 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
940 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900941 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700942 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900943 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700944 ` you will need approval.\n`+
945 `******************************\n`, ctx.ModuleName()),
946 },
947 })
948
949 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
950
951 ctx.Build(pctx, android.BuildParams{
952 Rule: updateApi,
953 Description: "update current API",
954 Output: d.updateCurrentApiTimestamp,
955 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
956 Args: map[string]string{
957 "apiFile": apiFile.String(),
958 "apiFileToCheck": d.apiFile.String(),
959 "removedApiFile": removedApiFile.String(),
960 "removedApiFileToCheck": d.removedApiFile.String(),
961 },
962 })
963 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700964 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
965 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
966
967 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
968 "check_api.last_released.api_file")
969 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
970 "check_api.last_released.removed_api_file")
971
972 ctx.Build(pctx, android.BuildParams{
973 Rule: apiCheck,
974 Description: "Last Released API check",
975 Output: d.checkLastReleasedApiTimestamp,
976 Inputs: nil,
977 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
978 checkApiClasspath...),
979 Args: map[string]string{
980 "classpath": checkApiClasspath.FormJavaClassPath(""),
981 "opts": String(d.properties.Check_api.Last_released.Args),
982 "apiFile": apiFile.String(),
983 "apiFileToCheck": d.apiFile.String(),
984 "removedApiFile": removedApiFile.String(),
985 "removedApiFileToCheck": d.removedApiFile.String(),
986 "msg": `\n******************************\n` +
987 `You have tried to change the API from what has been previously released in\n` +
988 `an SDK. Please fix the errors listed above.\n` +
989 `******************************\n`,
990 },
991 })
992 }
Nan Zhang581fd212018-01-10 16:06:12 -0800993}
Dan Willemsencc090972018-02-26 14:33:31 -0800994
995var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
996
997type DroiddocTemplateProperties struct {
998 // path to the directory containing the droiddoc templates.
999 Path *string
1000}
1001
1002type DroiddocTemplate struct {
1003 android.ModuleBase
1004
1005 properties DroiddocTemplateProperties
1006
1007 deps android.Paths
1008 dir android.Path
1009}
1010
1011func DroiddocTemplateFactory() android.Module {
1012 module := &DroiddocTemplate{}
1013 module.AddProperties(&module.properties)
1014 android.InitAndroidModule(module)
1015 return module
1016}
1017
1018func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1019
1020func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1021 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1022 d.dir = path
1023 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1024}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001025
1026//
1027// Defaults
1028//
1029type DocDefaults struct {
1030 android.ModuleBase
1031 android.DefaultsModuleBase
1032}
1033
1034func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1035}
1036
1037func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1038}
1039
1040func DocDefaultsFactory() android.Module {
1041 module := &DocDefaults{}
1042
1043 module.AddProperties(
1044 &JavadocProperties{},
1045 &DroiddocProperties{},
1046 )
1047
1048 android.InitDefaultsModule(module)
1049
1050 return module
1051}