blob: ca99e76f34ea2477d602c467fe8a013b59799f2d [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
David Brazdilfbe4cc32018-05-31 13:56:46 +0100206 // the generated public Dex API filename by Doclava.
207 Dex_api_filename *string
208
Nan Zhang28c68b92018-03-13 16:17:01 -0700209 // the generated private API filename by Doclava.
210 Private_api_filename *string
211
212 // the generated private Dex API filename by Doclava.
213 Private_dex_api_filename *string
214
215 // the generated removed API filename by Doclava.
216 Removed_api_filename *string
217
David Brazdilaac0c3c2018-04-24 16:23:29 +0100218 // the generated removed Dex API filename by Doclava.
219 Removed_dex_api_filename *string
220
Nan Zhang28c68b92018-03-13 16:17:01 -0700221 // the generated exact API filename by Doclava.
222 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700223
224 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
225 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700226
227 Check_api struct {
228 Last_released ApiToCheck
229
230 Current ApiToCheck
231 }
Nan Zhang79614d12018-04-19 18:03:39 -0700232
233 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
234 // currently still used for documentation generation, and will be replaced by Dokka soon.
235 Metalava_enabled *bool
236
237 // user can specify the version of previous released API file in order to do compatibility check.
238 Metalava_previous_api *string
239
240 // is set to true, Metalava will allow framework SDK to contain annotations.
241 Metalava_annotations_enabled *bool
242
243 // a XML files set to merge annotations.
244 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800245}
246
247type Javadoc struct {
248 android.ModuleBase
249 android.DefaultableModuleBase
250
251 properties JavadocProperties
252
253 srcJars android.Paths
254 srcFiles android.Paths
255 sourcepaths android.Paths
256
Nan Zhangccff0f72018-03-08 17:26:16 -0800257 docZip android.WritablePath
258 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800259}
260
Nan Zhangb2b33de2018-02-23 11:18:47 -0800261func (j *Javadoc) Srcs() android.Paths {
262 return android.Paths{j.stubsSrcJar}
263}
264
265var _ android.SourceFileProducer = (*Javadoc)(nil)
266
Nan Zhang581fd212018-01-10 16:06:12 -0800267type Droiddoc struct {
268 Javadoc
269
Nan Zhang28c68b92018-03-13 16:17:01 -0700270 properties DroiddocProperties
271 apiFile android.WritablePath
David Brazdilfbe4cc32018-05-31 13:56:46 +0100272 dexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700273 privateApiFile android.WritablePath
274 privateDexApiFile android.WritablePath
275 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100276 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700277 exactApiFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700278
279 checkCurrentApiTimestamp android.WritablePath
280 updateCurrentApiTimestamp android.WritablePath
281 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800282}
283
284func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
285 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
286 android.InitDefaultableModule(module)
287}
288
289func JavadocFactory() android.Module {
290 module := &Javadoc{}
291
292 module.AddProperties(&module.properties)
293
294 InitDroiddocModule(module, android.HostAndDeviceSupported)
295 return module
296}
297
298func JavadocHostFactory() android.Module {
299 module := &Javadoc{}
300
301 module.AddProperties(&module.properties)
302
303 InitDroiddocModule(module, android.HostSupported)
304 return module
305}
306
307func DroiddocFactory() android.Module {
308 module := &Droiddoc{}
309
310 module.AddProperties(&module.properties,
311 &module.Javadoc.properties)
312
313 InitDroiddocModule(module, android.HostAndDeviceSupported)
314 return module
315}
316
317func DroiddocHostFactory() android.Module {
318 module := &Droiddoc{}
319
320 module.AddProperties(&module.properties,
321 &module.Javadoc.properties)
322
323 InitDroiddocModule(module, android.HostSupported)
324 return module
325}
326
327func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
328 if ctx.Device() {
329 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
330 if sdkDep.useDefaultLibs {
331 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang9cbe6772018-03-21 17:56:39 -0700332 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800333 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
334 }
Nan Zhang581fd212018-01-10 16:06:12 -0800335 } else if sdkDep.useModule {
Colin Cross86a60ae2018-05-29 14:44:55 -0700336 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800337 }
338 }
339
340 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
341
342 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
343
344 // exclude_srcs may contain filegroup or genrule.
345 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
346}
347
Nan Zhangb2b33de2018-02-23 11:18:47 -0800348func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
349 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
350 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900351 // convert foo.bar.baz to foo/bar/baz
352 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
353 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800354 if _, found := whitelistPathPrefixes[prefix]; !found {
355 whitelistPathPrefixes[prefix] = true
356 }
357 }
358 }
359}
360
Jiyong Park1e440682018-05-23 18:42:04 +0900361func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
362 var flags javaBuilderFlags
363
364 // aidl flags.
365 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
366 if len(aidlFlags) > 0 {
367 // optimization.
368 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
369 flags.aidlFlags = "$aidlFlags"
370 }
371
372 return flags
373}
374
375func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
376 aidlIncludeDirs android.Paths) []string {
377
378 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
379 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
380
381 var flags []string
382 if aidlPreprocess.Valid() {
383 flags = append(flags, "-p"+aidlPreprocess.String())
384 } else {
385 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
386 }
387
388 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
389 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
390 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
391 flags = append(flags, "-I"+src.String())
392 }
393
394 return flags
395}
396
397func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
398 flags javaBuilderFlags) android.Paths {
399
400 outSrcFiles := make(android.Paths, 0, len(srcFiles))
401
402 for _, srcFile := range srcFiles {
403 switch srcFile.Ext() {
404 case ".aidl":
405 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
406 outSrcFiles = append(outSrcFiles, javaFile)
407 default:
408 outSrcFiles = append(outSrcFiles, srcFile)
409 }
410 }
411
412 return outSrcFiles
413}
414
Nan Zhang581fd212018-01-10 16:06:12 -0800415func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
416 var deps deps
417
418 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
419 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700420 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800421 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700422 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800423 }
424
425 ctx.VisitDirectDeps(func(module android.Module) {
426 otherName := ctx.OtherModuleName(module)
427 tag := ctx.OtherModuleDependencyTag(module)
428
Colin Cross2d24c1b2018-05-23 10:59:18 -0700429 switch tag {
430 case bootClasspathTag:
431 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800432 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700433 } else {
434 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
435 }
436 case libTag:
437 switch dep := module.(type) {
438 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800439 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800440 if otherName == String(j.properties.Srcs_lib) {
441 srcs := dep.(SrcDependency).CompiledSrcs()
442 whitelistPathPrefixes := make(map[string]bool)
443 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
444 for _, src := range srcs {
445 if _, ok := src.(android.WritablePath); ok { // generated sources
446 deps.srcs = append(deps.srcs, src)
447 } else { // select source path for documentation based on whitelist path prefixs.
448 for k, _ := range whitelistPathPrefixes {
449 if strings.HasPrefix(src.Rel(), k) {
450 deps.srcs = append(deps.srcs, src)
451 break
452 }
453 }
454 }
455 }
456 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
457 }
Colin Cross2d24c1b2018-05-23 10:59:18 -0700458 case SdkLibraryDependency:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900459 sdkVersion := String(j.properties.Sdk_version)
460 linkType := javaSdk
461 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
462 linkType = javaSystem
463 } else if sdkVersion == "" {
464 linkType = javaPlatform
465 }
466 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700467 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800468 checkProducesJars(ctx, dep)
469 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800470 default:
471 ctx.ModuleErrorf("depends on non-java module %q", otherName)
472 }
473 }
474 })
475 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
476 // may contain filegroup or genrule.
477 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900478 flags := j.collectBuilderFlags(ctx, deps)
479 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800480
481 // srcs may depend on some genrule output.
482 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800483 j.srcJars = append(j.srcJars, deps.srcJars...)
484
Nan Zhang581fd212018-01-10 16:06:12 -0800485 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800486 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800487
488 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800489 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800490
491 if j.properties.Local_sourcepaths == nil {
492 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
493 }
494 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800495
496 return deps
497}
498
499func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
500 j.addDeps(ctx)
501}
502
503func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
504 deps := j.collectDeps(ctx)
505
506 var implicits android.Paths
507 implicits = append(implicits, deps.bootClasspath...)
508 implicits = append(implicits, deps.classpath...)
509
510 var bootClasspathArgs, classpathArgs string
511 if ctx.Config().UseOpenJDK9() {
512 if len(deps.bootClasspath) > 0 {
513 // For OpenJDK 9 we use --patch-module to define the core libraries code.
514 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
515 // modules. Here we treat all code in core libraries as being in java.base
516 // to work around the OpenJDK 9 module system. http://b/62049770
517 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
518 }
519 } else {
520 if len(deps.bootClasspath.Strings()) > 0 {
521 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
522 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
523 }
524 }
525 if len(deps.classpath.Strings()) > 0 {
526 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
527 }
528
529 implicits = append(implicits, j.srcJars...)
530
531 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
532
533 ctx.Build(pctx, android.BuildParams{
534 Rule: javadoc,
535 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800536 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800537 ImplicitOutput: j.docZip,
538 Inputs: j.srcFiles,
539 Implicits: implicits,
540 Args: map[string]string{
541 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
542 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
543 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
544 "srcJars": strings.Join(j.srcJars.Strings(), " "),
545 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700546 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800547 "classpathArgs": classpathArgs,
548 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
549 "docZip": j.docZip.String(),
550 },
551 })
552}
553
Nan Zhang61819ce2018-05-04 18:49:16 -0700554func (d *Droiddoc) checkCurrentApi() bool {
555 if String(d.properties.Check_api.Current.Api_file) != "" &&
556 String(d.properties.Check_api.Current.Removed_api_file) != "" {
557 return true
558 } else if String(d.properties.Check_api.Current.Api_file) != "" {
559 panic("check_api.current.removed_api_file: has to be non empty!")
560 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
561 panic("check_api.current.api_file: has to be non empty!")
562 }
563
564 return false
565}
566
567func (d *Droiddoc) checkLastReleasedApi() bool {
568 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
569 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
570 return true
571 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
572 panic("check_api.last_released.removed_api_file: has to be non empty!")
573 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
574 panic("check_api.last_released.api_file: has to be non empty!")
575 }
576
577 return false
578}
579
Nan Zhang581fd212018-01-10 16:06:12 -0800580func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
581 d.Javadoc.addDeps(ctx)
582
Nan Zhang79614d12018-04-19 18:03:39 -0700583 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800584 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
585 }
586
Nan Zhang581fd212018-01-10 16:06:12 -0800587 // extra_arg_files may contains filegroup or genrule.
588 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
589
590 // knowntags may contain filegroup or genrule.
591 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700592
593 if d.checkCurrentApi() {
594 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
595 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
596 }
597
598 if d.checkLastReleasedApi() {
599 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
600 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
601 }
Nan Zhang79614d12018-04-19 18:03:39 -0700602
603 if String(d.properties.Metalava_previous_api) != "" {
604 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
605 }
Nan Zhang581fd212018-01-10 16:06:12 -0800606}
607
608func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
609 deps := d.Javadoc.collectDeps(ctx)
610
611 var implicits android.Paths
612 implicits = append(implicits, deps.bootClasspath...)
613 implicits = append(implicits, deps.classpath...)
614
Nan Zhang79614d12018-04-19 18:03:39 -0700615 bootClasspathArgs := deps.bootClasspath.FormJavaClassPath("-bootclasspath")
616 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
617
Nan Zhang581fd212018-01-10 16:06:12 -0800618 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
619 argFilesMap := map[string]android.Path{}
620
621 for _, f := range argFiles {
622 implicits = append(implicits, f)
623 if _, exists := argFilesMap[f.Rel()]; !exists {
624 argFilesMap[f.Rel()] = f
625 } else {
626 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
627 f, argFilesMap[f.Rel()], f.Rel())
628 }
629 }
630
631 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
632 if strings.HasPrefix(name, "location ") {
633 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
634 if f, ok := argFilesMap[label]; ok {
635 return f.String(), nil
636 } else {
637 return "", fmt.Errorf("unknown location label %q", label)
638 }
639 } else if name == "genDir" {
640 return android.PathForModuleGen(ctx).String(), nil
641 }
642 return "", fmt.Errorf("unknown variable '$(%s)'", name)
643 })
644
645 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700646 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800647 return
648 }
649
Nan Zhang79614d12018-04-19 18:03:39 -0700650 genDocsForMetalava := false
651 var metalavaArgs string
652 if Bool(d.properties.Metalava_enabled) {
653 if strings.Contains(args, "--generate-documentation") {
654 if !strings.Contains(args, "-nodocs") {
655 genDocsForMetalava = true
656 }
657 // TODO(nanzhang): Add a Soong property to handle documentation args.
658 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800659 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700660 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800661 }
Nan Zhang581fd212018-01-10 16:06:12 -0800662 }
663
Nan Zhang79614d12018-04-19 18:03:39 -0700664 var templateDir, htmlDirArgs, htmlDir2Args string
665 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
666 if String(d.properties.Custom_template) == "" {
667 // TODO: This is almost always droiddoc-templates-sdk
668 ctx.PropertyErrorf("custom_template", "must specify a template")
669 }
670
671 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
672 if t, ok := m.(*DroiddocTemplate); ok {
673 implicits = append(implicits, t.deps...)
674 templateDir = t.dir.String()
675 } else {
676 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
677 }
678 })
679
680 if len(d.properties.Html_dirs) > 0 {
681 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
682 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
683 htmlDirArgs = "-htmldir " + htmlDir.String()
684 }
685
686 if len(d.properties.Html_dirs) > 1 {
687 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
688 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
689 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
690 }
691
692 if len(d.properties.Html_dirs) > 2 {
693 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
694 }
695
696 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
697 implicits = append(implicits, knownTags...)
698
699 for _, kt := range knownTags {
700 args = args + " -knowntags " + kt.String()
701 }
702
703 for _, hdf := range d.properties.Hdf {
704 args = args + " -hdf " + hdf
705 }
706
707 if String(d.properties.Proofread_file) != "" {
708 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
709 args = args + " -proofread " + proofreadFile.String()
710 }
711
712 if String(d.properties.Todo_file) != "" {
713 // tricky part:
714 // we should not compute full path for todo_file through PathForModuleOut().
715 // the non-standard doclet will get the full path relative to "-o".
716 args = args + " -todo " + String(d.properties.Todo_file)
717 }
718
719 if String(d.properties.Resourcesdir) != "" {
720 // TODO: should we add files under resourcesDir to the implicits? It seems that
721 // resourcesDir is one sub dir of htmlDir
722 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
723 args = args + " -resourcesdir " + resourcesDir.String()
724 }
725
726 if String(d.properties.Resourcesoutdir) != "" {
727 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
728 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
729 }
Dan Willemsencc090972018-02-26 14:33:31 -0800730 }
731
Nan Zhang79614d12018-04-19 18:03:39 -0700732 var docArgsForMetalava string
733 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
734 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800735 }
736
Nan Zhang28c68b92018-03-13 16:17:01 -0700737 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700738
739 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
740 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700741 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700742 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700743 implicitOutputs = append(implicitOutputs, d.apiFile)
744 }
745
Nan Zhang61819ce2018-05-04 18:49:16 -0700746 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
747 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
748 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700749 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700750 implicitOutputs = append(implicitOutputs, d.removedApiFile)
751 }
752
Nan Zhang28c68b92018-03-13 16:17:01 -0700753 if String(d.properties.Private_api_filename) != "" {
754 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
755 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700756 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700757 implicitOutputs = append(implicitOutputs, d.privateApiFile)
758 }
759
David Brazdilfbe4cc32018-05-31 13:56:46 +0100760 if String(d.properties.Dex_api_filename) != "" {
761 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
762 args = args + " -dexApi " + d.dexApiFile.String()
763 implicitOutputs = append(implicitOutputs, d.dexApiFile)
764 }
765
Nan Zhang28c68b92018-03-13 16:17:01 -0700766 if String(d.properties.Private_dex_api_filename) != "" {
767 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
768 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700769 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700770 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
771 }
772
David Brazdilaac0c3c2018-04-24 16:23:29 +0100773 if String(d.properties.Removed_dex_api_filename) != "" {
774 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
775 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700776 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100777 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
778 }
779
Nan Zhang28c68b92018-03-13 16:17:01 -0700780 if String(d.properties.Exact_api_filename) != "" {
781 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
782 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700783 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700784 implicitOutputs = append(implicitOutputs, d.exactApiFile)
785 }
786
Nan Zhang581fd212018-01-10 16:06:12 -0800787 implicits = append(implicits, d.Javadoc.srcJars...)
788
Nan Zhang79614d12018-04-19 18:03:39 -0700789 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
790 for _, o := range d.properties.Out {
791 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
792 }
793
Nan Zhang30963742018-04-23 09:59:14 -0700794 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
795 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700796
Nan Zhang46130972018-06-04 11:28:01 -0700797 var date string
798 if runtime.GOOS == "darwin" {
799 date = `date -r`
800 } else {
801 date = `date -d`
802 }
803
Nan Zhang79614d12018-04-19 18:03:39 -0700804 doclavaOpts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700805 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800806 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800807 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700808 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700809
Nan Zhang79614d12018-04-19 18:03:39 -0700810 if !Bool(d.properties.Metalava_enabled) {
811 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800812
Nan Zhang79614d12018-04-19 18:03:39 -0700813 implicits = append(implicits, jsilver)
814 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800815
Nan Zhang79614d12018-04-19 18:03:39 -0700816 if BoolDefault(d.properties.Create_stubs, true) {
817 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
818 }
819
820 ctx.Build(pctx, android.BuildParams{
821 Rule: javadoc,
822 Description: "Droiddoc",
823 Output: d.Javadoc.stubsSrcJar,
824 Inputs: d.Javadoc.srcFiles,
825 Implicits: implicits,
826 ImplicitOutputs: implicitOutputs,
827 Args: map[string]string{
828 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
829 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
830 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
831 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
832 "opts": opts,
833 "bootclasspathArgs": bootClasspathArgs,
834 "classpathArgs": classpathArgs,
835 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
836 "docZip": d.Javadoc.docZip.String(),
837 },
838 })
839 } else {
840 opts := metalavaArgs
841
842 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800843 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
844 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
845 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
846 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang581fd212018-01-10 16:06:12 -0800847 "bootclasspathArgs": bootClasspathArgs,
848 "classpathArgs": classpathArgs,
849 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
850 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700851 }
852
853 var previousApi android.Path
854 if String(d.properties.Metalava_previous_api) != "" {
855 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
856 "metalava_previous_api")
857 opts += " --check-compatibility --previous-api " + previousApi.String()
858 implicits = append(implicits, previousApi)
859 }
860
861 if Bool(d.properties.Metalava_annotations_enabled) {
862 if String(d.properties.Metalava_previous_api) == "" {
863 ctx.PropertyErrorf("metalava_previous_api",
864 "has to be non-empty if annotations was enabled!")
865 }
866 opts += " --include-annotations --migrate-nullness"
867
868 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
869 implicitOutputs = append(implicitOutputs, annotationsZip)
870
871 if String(d.properties.Metalava_merge_annotations_dir) == "" {
872 ctx.PropertyErrorf("metalava_merge_annotations",
873 "has to be non-empty if annotations was enabled!")
874 }
875
876 mergeAnnotationsDir := android.PathForModuleSrc(ctx,
877 String(d.properties.Metalava_merge_annotations_dir))
878 implicits = append(implicits, ctx.Glob(mergeAnnotationsDir.Join(ctx, "**/*").String(), nil)...)
879
880 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
881 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
882 opts += "--hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
883 }
884
885 if genDocsForMetalava {
886 opts += " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 STUBS_SOURCE_LIST " +
887 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
888 strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + " -quiet -d $outDir "
889 implicits = append(implicits, jsilver)
890 implicits = append(implicits, doclava)
891 }
892
893 buildArgs["opts"] = opts
894 ctx.Build(pctx, android.BuildParams{
895 Rule: metalava,
896 Description: "Metalava",
897 Output: d.Javadoc.stubsSrcJar,
898 Inputs: d.Javadoc.srcFiles,
899 Implicits: implicits,
900 ImplicitOutputs: implicitOutputs,
901 Args: buildArgs,
902 })
903 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700904
905 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
906
907 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
908
909 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
910 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
911
912 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
913 "check_api.current.api_file")
914 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
915 "check_api.current_removed_api_file")
916
917 ctx.Build(pctx, android.BuildParams{
918 Rule: apiCheck,
919 Description: "Current API check",
920 Output: d.checkCurrentApiTimestamp,
921 Inputs: nil,
922 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
923 checkApiClasspath...),
924 Args: map[string]string{
925 "classpath": checkApiClasspath.FormJavaClassPath(""),
926 "opts": String(d.properties.Check_api.Current.Args),
927 "apiFile": apiFile.String(),
928 "apiFileToCheck": d.apiFile.String(),
929 "removedApiFile": removedApiFile.String(),
930 "removedApiFileToCheck": d.removedApiFile.String(),
931 "msg": fmt.Sprintf(`\n******************************\n`+
932 `You have tried to change the API from what has been previously approved.\n\n`+
933 `To make these errors go away, you have two choices:\n`+
934 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
935 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900936 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700937 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900938 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700939 ` you will need approval.\n`+
940 `******************************\n`, ctx.ModuleName()),
941 },
942 })
943
944 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
945
946 ctx.Build(pctx, android.BuildParams{
947 Rule: updateApi,
948 Description: "update current API",
949 Output: d.updateCurrentApiTimestamp,
950 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
951 Args: map[string]string{
952 "apiFile": apiFile.String(),
953 "apiFileToCheck": d.apiFile.String(),
954 "removedApiFile": removedApiFile.String(),
955 "removedApiFileToCheck": d.removedApiFile.String(),
956 },
957 })
958 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700959 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
960 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
961
962 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
963 "check_api.last_released.api_file")
964 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
965 "check_api.last_released.removed_api_file")
966
967 ctx.Build(pctx, android.BuildParams{
968 Rule: apiCheck,
969 Description: "Last Released API check",
970 Output: d.checkLastReleasedApiTimestamp,
971 Inputs: nil,
972 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
973 checkApiClasspath...),
974 Args: map[string]string{
975 "classpath": checkApiClasspath.FormJavaClassPath(""),
976 "opts": String(d.properties.Check_api.Last_released.Args),
977 "apiFile": apiFile.String(),
978 "apiFileToCheck": d.apiFile.String(),
979 "removedApiFile": removedApiFile.String(),
980 "removedApiFileToCheck": d.removedApiFile.String(),
981 "msg": `\n******************************\n` +
982 `You have tried to change the API from what has been previously released in\n` +
983 `an SDK. Please fix the errors listed above.\n` +
984 `******************************\n`,
985 },
986 })
987 }
Nan Zhang581fd212018-01-10 16:06:12 -0800988}
Dan Willemsencc090972018-02-26 14:33:31 -0800989
990var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
991
992type DroiddocTemplateProperties struct {
993 // path to the directory containing the droiddoc templates.
994 Path *string
995}
996
997type DroiddocTemplate struct {
998 android.ModuleBase
999
1000 properties DroiddocTemplateProperties
1001
1002 deps android.Paths
1003 dir android.Path
1004}
1005
1006func DroiddocTemplateFactory() android.Module {
1007 module := &DroiddocTemplate{}
1008 module.AddProperties(&module.properties)
1009 android.InitAndroidModule(module)
1010 return module
1011}
1012
1013func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1014
1015func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1016 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1017 d.dir = path
1018 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1019}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001020
1021//
1022// Defaults
1023//
1024type DocDefaults struct {
1025 android.ModuleBase
1026 android.DefaultsModuleBase
1027}
1028
1029func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1030}
1031
1032func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1033}
1034
1035func DocDefaultsFactory() android.Module {
1036 module := &DocDefaults{}
1037
1038 module.AddProperties(
1039 &JavadocProperties{},
1040 &DroiddocProperties{},
1041 )
1042
1043 android.InitDefaultsModule(module)
1044
1045 return module
1046}