blob: dfba17e86c19a9072029f0666ae49a689e3b440f [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 Zhangaf322cc2018-06-19 15:15:38 -070033 `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang581fd212018-01-10 16:06:12 -080034 `$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 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070047 "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 && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070072 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang16c0a312018-06-13 17:42:48 -070073 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
74 `--stubs $stubsDir $opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070075 `${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 },
Nan Zhang357466b2018-04-17 17:38:36 -070088 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
89 "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -080090)
91
92func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080093 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
94
Nan Zhang581fd212018-01-10 16:06:12 -080095 android.RegisterModuleType("droiddoc", DroiddocFactory)
96 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Dan Willemsencc090972018-02-26 14:33:31 -080097 android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080098 android.RegisterModuleType("javadoc", JavadocFactory)
99 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
100}
101
102type JavadocProperties struct {
103 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
104 // or .aidl files.
105 Srcs []string `android:"arch_variant"`
106
107 // list of directories rooted at the Android.bp file that will
108 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800109 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800110
111 // list of source files that should not be used to build the Java module.
112 // This is most useful in the arch/multilib variants to remove non-common files
113 // filegroup or genrule can be included within this property.
114 Exclude_srcs []string `android:"arch_variant"`
115
Nan Zhangb2b33de2018-02-23 11:18:47 -0800116 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800117 Libs []string `android:"arch_variant"`
118
Nan Zhange66c7272018-03-06 12:59:27 -0800119 // don't build against the framework libraries (legacy-test, core-junit,
120 // ext, and framework for device targets)
121 No_framework_libs *bool
122
Nan Zhangb2b33de2018-02-23 11:18:47 -0800123 // the java library (in classpath) for documentation that provides java srcs and srcjars.
124 Srcs_lib *string
125
126 // the base dirs under srcs_lib will be scanned for java srcs.
127 Srcs_lib_whitelist_dirs []string
128
129 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
130 Srcs_lib_whitelist_pkgs []string
131
Nan Zhang581fd212018-01-10 16:06:12 -0800132 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800133 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800134
135 // if not blank, set to the version of the sdk to compile against
136 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900137
138 Aidl struct {
139 // Top level directories to pass to aidl tool
140 Include_dirs []string
141
142 // Directories rooted at the Android.bp file to pass to aidl tool
143 Local_include_dirs []string
144 }
Nan Zhang357466b2018-04-17 17:38:36 -0700145
146 // If not blank, set the java version passed to javadoc as -source
147 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800148}
149
Nan Zhang61819ce2018-05-04 18:49:16 -0700150type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900151 // path to the API txt file that the new API extracted from source code is checked
152 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700153 Api_file *string
154
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900155 // path to the API txt file that the new @removed API extractd from source code is
156 // checked against. The path can be local to the module or from other module (via
157 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700158 Removed_api_file *string
159
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900160 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700161 Args *string
162}
163
Nan Zhang581fd212018-01-10 16:06:12 -0800164type DroiddocProperties struct {
165 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800166 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800167
168 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800169 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800170
171 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800173
174 // proofread file contains all of the text content of the javadocs concatenated into one file,
175 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800176 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800177
178 // a todo file lists the program elements that are missing documentation.
179 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800180 Todo_file *string
181
182 // directory under current module source that provide additional resources (images).
183 Resourcesdir *string
184
185 // resources output directory under out/soong/.intermediates.
186 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800187
188 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800189 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800190
191 // user customized droiddoc args.
192 // Available variables for substitution:
193 //
194 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800195 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800196
197 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800198 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800199
200 // a list of files under current module source dir which contains known tags in Java sources.
201 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800202 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700203
204 // the tag name used to distinguish if the API files belong to public/system/test.
205 Api_tag_name *string
206
207 // the generated public API filename by Doclava.
208 Api_filename *string
209
David Brazdilfbe4cc32018-05-31 13:56:46 +0100210 // the generated public Dex API filename by Doclava.
211 Dex_api_filename *string
212
Nan Zhang28c68b92018-03-13 16:17:01 -0700213 // the generated private API filename by Doclava.
214 Private_api_filename *string
215
216 // the generated private Dex API filename by Doclava.
217 Private_dex_api_filename *string
218
219 // the generated removed API filename by Doclava.
220 Removed_api_filename *string
221
David Brazdilaac0c3c2018-04-24 16:23:29 +0100222 // the generated removed Dex API filename by Doclava.
223 Removed_dex_api_filename *string
224
Nan Zhang28c68b92018-03-13 16:17:01 -0700225 // the generated exact API filename by Doclava.
226 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700227
228 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
229 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700230
231 Check_api struct {
232 Last_released ApiToCheck
233
234 Current ApiToCheck
235 }
Nan Zhang79614d12018-04-19 18:03:39 -0700236
237 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
238 // currently still used for documentation generation, and will be replaced by Dokka soon.
239 Metalava_enabled *bool
240
241 // user can specify the version of previous released API file in order to do compatibility check.
242 Metalava_previous_api *string
243
244 // is set to true, Metalava will allow framework SDK to contain annotations.
245 Metalava_annotations_enabled *bool
246
Nan Zhang16c0a312018-06-13 17:42:48 -0700247 // a top level directory contains XML files set to merge annotations.
Nan Zhang79614d12018-04-19 18:03:39 -0700248 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800249}
250
251type Javadoc struct {
252 android.ModuleBase
253 android.DefaultableModuleBase
254
255 properties JavadocProperties
256
257 srcJars android.Paths
258 srcFiles android.Paths
259 sourcepaths android.Paths
260
Nan Zhangccff0f72018-03-08 17:26:16 -0800261 docZip android.WritablePath
262 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800263}
264
Nan Zhangb2b33de2018-02-23 11:18:47 -0800265func (j *Javadoc) Srcs() android.Paths {
266 return android.Paths{j.stubsSrcJar}
267}
268
269var _ android.SourceFileProducer = (*Javadoc)(nil)
270
Nan Zhang581fd212018-01-10 16:06:12 -0800271type Droiddoc struct {
272 Javadoc
273
Nan Zhang28c68b92018-03-13 16:17:01 -0700274 properties DroiddocProperties
275 apiFile android.WritablePath
David Brazdilfbe4cc32018-05-31 13:56:46 +0100276 dexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700277 privateApiFile android.WritablePath
278 privateDexApiFile android.WritablePath
279 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100280 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700281 exactApiFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700282
283 checkCurrentApiTimestamp android.WritablePath
284 updateCurrentApiTimestamp android.WritablePath
285 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800286}
287
288func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
289 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
290 android.InitDefaultableModule(module)
291}
292
293func JavadocFactory() android.Module {
294 module := &Javadoc{}
295
296 module.AddProperties(&module.properties)
297
298 InitDroiddocModule(module, android.HostAndDeviceSupported)
299 return module
300}
301
302func JavadocHostFactory() android.Module {
303 module := &Javadoc{}
304
305 module.AddProperties(&module.properties)
306
307 InitDroiddocModule(module, android.HostSupported)
308 return module
309}
310
311func DroiddocFactory() android.Module {
312 module := &Droiddoc{}
313
314 module.AddProperties(&module.properties,
315 &module.Javadoc.properties)
316
317 InitDroiddocModule(module, android.HostAndDeviceSupported)
318 return module
319}
320
321func DroiddocHostFactory() android.Module {
322 module := &Droiddoc{}
323
324 module.AddProperties(&module.properties,
325 &module.Javadoc.properties)
326
327 InitDroiddocModule(module, android.HostSupported)
328 return module
329}
330
331func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
332 if ctx.Device() {
333 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
334 if sdkDep.useDefaultLibs {
335 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700336 if ctx.Config().TargetOpenJDK9() {
337 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
338 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700339 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800340 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
341 }
Nan Zhang581fd212018-01-10 16:06:12 -0800342 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700343 if ctx.Config().TargetOpenJDK9() {
344 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
345 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700346 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800347 }
348 }
349
350 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
351
352 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
353
354 // exclude_srcs may contain filegroup or genrule.
355 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
356}
357
Nan Zhangb2b33de2018-02-23 11:18:47 -0800358func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
359 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
360 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900361 // convert foo.bar.baz to foo/bar/baz
362 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
363 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800364 if _, found := whitelistPathPrefixes[prefix]; !found {
365 whitelistPathPrefixes[prefix] = true
366 }
367 }
368 }
369}
370
Jiyong Park1e440682018-05-23 18:42:04 +0900371func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
372 var flags javaBuilderFlags
373
374 // aidl flags.
375 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
376 if len(aidlFlags) > 0 {
377 // optimization.
378 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
379 flags.aidlFlags = "$aidlFlags"
380 }
381
382 return flags
383}
384
385func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
386 aidlIncludeDirs android.Paths) []string {
387
388 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
389 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
390
391 var flags []string
392 if aidlPreprocess.Valid() {
393 flags = append(flags, "-p"+aidlPreprocess.String())
394 } else {
395 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
396 }
397
398 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
399 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
400 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
401 flags = append(flags, "-I"+src.String())
402 }
403
404 return flags
405}
406
407func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
408 flags javaBuilderFlags) android.Paths {
409
410 outSrcFiles := make(android.Paths, 0, len(srcFiles))
411
412 for _, srcFile := range srcFiles {
413 switch srcFile.Ext() {
414 case ".aidl":
415 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
416 outSrcFiles = append(outSrcFiles, javaFile)
417 default:
418 outSrcFiles = append(outSrcFiles, srcFile)
419 }
420 }
421
422 return outSrcFiles
423}
424
Nan Zhang581fd212018-01-10 16:06:12 -0800425func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
426 var deps deps
427
428 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
429 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700430 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800431 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700432 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800433 }
434
435 ctx.VisitDirectDeps(func(module android.Module) {
436 otherName := ctx.OtherModuleName(module)
437 tag := ctx.OtherModuleDependencyTag(module)
438
Colin Cross2d24c1b2018-05-23 10:59:18 -0700439 switch tag {
440 case bootClasspathTag:
441 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800442 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700443 } else {
444 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
445 }
446 case libTag:
447 switch dep := module.(type) {
448 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800449 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800450 if otherName == String(j.properties.Srcs_lib) {
451 srcs := dep.(SrcDependency).CompiledSrcs()
452 whitelistPathPrefixes := make(map[string]bool)
453 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
454 for _, src := range srcs {
455 if _, ok := src.(android.WritablePath); ok { // generated sources
456 deps.srcs = append(deps.srcs, src)
457 } else { // select source path for documentation based on whitelist path prefixs.
458 for k, _ := range whitelistPathPrefixes {
459 if strings.HasPrefix(src.Rel(), k) {
460 deps.srcs = append(deps.srcs, src)
461 break
462 }
463 }
464 }
465 }
466 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
467 }
Colin Cross2d24c1b2018-05-23 10:59:18 -0700468 case SdkLibraryDependency:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900469 sdkVersion := String(j.properties.Sdk_version)
470 linkType := javaSdk
471 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
472 linkType = javaSystem
473 } else if sdkVersion == "" {
474 linkType = javaPlatform
475 }
476 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700477 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800478 checkProducesJars(ctx, dep)
479 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800480 default:
481 ctx.ModuleErrorf("depends on non-java module %q", otherName)
482 }
Nan Zhang357466b2018-04-17 17:38:36 -0700483 case systemModulesTag:
484 if deps.systemModules != nil {
485 panic("Found two system module dependencies")
486 }
487 sm := module.(*SystemModules)
488 if sm.outputFile == nil {
489 panic("Missing directory for system module dependency")
490 }
491 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800492 }
493 })
494 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
495 // may contain filegroup or genrule.
496 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900497 flags := j.collectBuilderFlags(ctx, deps)
498 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800499
500 // srcs may depend on some genrule output.
501 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800502 j.srcJars = append(j.srcJars, deps.srcJars...)
503
Nan Zhang581fd212018-01-10 16:06:12 -0800504 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800505 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800506
507 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800508 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800509
510 if j.properties.Local_sourcepaths == nil {
511 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
512 }
513 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800514
515 return deps
516}
517
518func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
519 j.addDeps(ctx)
520}
521
522func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
523 deps := j.collectDeps(ctx)
524
525 var implicits android.Paths
526 implicits = append(implicits, deps.bootClasspath...)
527 implicits = append(implicits, deps.classpath...)
528
529 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700530
531 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), String(j.properties.Sdk_version))
532 if javaVersion == "1.9" || ctx.Config().UseOpenJDK9() {
Nan Zhang581fd212018-01-10 16:06:12 -0800533 if len(deps.bootClasspath) > 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700534 var systemModules classpath
535 if deps.systemModules != nil {
536 systemModules = append(systemModules, deps.systemModules)
537 }
538 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
539 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800540 }
541 } else {
542 if len(deps.bootClasspath.Strings()) > 0 {
543 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
544 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
545 }
546 }
547 if len(deps.classpath.Strings()) > 0 {
548 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
549 }
550
551 implicits = append(implicits, j.srcJars...)
552
Nan Zhangaf322cc2018-06-19 15:15:38 -0700553 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800554
555 ctx.Build(pctx, android.BuildParams{
556 Rule: javadoc,
557 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800558 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800559 ImplicitOutput: j.docZip,
560 Inputs: j.srcFiles,
561 Implicits: implicits,
562 Args: map[string]string{
563 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
564 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
565 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
566 "srcJars": strings.Join(j.srcJars.Strings(), " "),
567 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700568 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800569 "classpathArgs": classpathArgs,
570 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
571 "docZip": j.docZip.String(),
572 },
573 })
574}
575
Nan Zhang61819ce2018-05-04 18:49:16 -0700576func (d *Droiddoc) checkCurrentApi() bool {
577 if String(d.properties.Check_api.Current.Api_file) != "" &&
578 String(d.properties.Check_api.Current.Removed_api_file) != "" {
579 return true
580 } else if String(d.properties.Check_api.Current.Api_file) != "" {
581 panic("check_api.current.removed_api_file: has to be non empty!")
582 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
583 panic("check_api.current.api_file: has to be non empty!")
584 }
585
586 return false
587}
588
589func (d *Droiddoc) checkLastReleasedApi() bool {
590 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
591 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
592 return true
593 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
594 panic("check_api.last_released.removed_api_file: has to be non empty!")
595 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
596 panic("check_api.last_released.api_file: has to be non empty!")
597 }
598
599 return false
600}
601
Nan Zhang581fd212018-01-10 16:06:12 -0800602func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
603 d.Javadoc.addDeps(ctx)
604
Nan Zhang79614d12018-04-19 18:03:39 -0700605 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800606 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
607 }
608
Nan Zhang581fd212018-01-10 16:06:12 -0800609 // extra_arg_files may contains filegroup or genrule.
610 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
611
612 // knowntags may contain filegroup or genrule.
613 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700614
615 if d.checkCurrentApi() {
616 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
617 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
618 }
619
620 if d.checkLastReleasedApi() {
621 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
622 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
623 }
Nan Zhang79614d12018-04-19 18:03:39 -0700624
625 if String(d.properties.Metalava_previous_api) != "" {
626 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
627 }
Nan Zhang581fd212018-01-10 16:06:12 -0800628}
629
630func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
631 deps := d.Javadoc.collectDeps(ctx)
632
633 var implicits android.Paths
634 implicits = append(implicits, deps.bootClasspath...)
635 implicits = append(implicits, deps.classpath...)
636
Nan Zhang357466b2018-04-17 17:38:36 -0700637 var bootClasspathArgs string
638 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), String(d.Javadoc.properties.Sdk_version))
639 if javaVersion == "1.9" {
640 if len(deps.bootClasspath) > 0 {
641 var systemModules classpath
642 if deps.systemModules != nil {
643 systemModules = append(systemModules, deps.systemModules)
644 }
645 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
646 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
647 }
648 } else {
649 if len(deps.bootClasspath.Strings()) > 0 {
650 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
651 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
652 }
653 }
Nan Zhang79614d12018-04-19 18:03:39 -0700654 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
655
Nan Zhang581fd212018-01-10 16:06:12 -0800656 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
657 argFilesMap := map[string]android.Path{}
658
659 for _, f := range argFiles {
660 implicits = append(implicits, f)
661 if _, exists := argFilesMap[f.Rel()]; !exists {
662 argFilesMap[f.Rel()] = f
663 } else {
664 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
665 f, argFilesMap[f.Rel()], f.Rel())
666 }
667 }
668
669 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
670 if strings.HasPrefix(name, "location ") {
671 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
672 if f, ok := argFilesMap[label]; ok {
673 return f.String(), nil
674 } else {
675 return "", fmt.Errorf("unknown location label %q", label)
676 }
677 } else if name == "genDir" {
678 return android.PathForModuleGen(ctx).String(), nil
679 }
680 return "", fmt.Errorf("unknown variable '$(%s)'", name)
681 })
682
683 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700684 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800685 return
686 }
687
Nan Zhang79614d12018-04-19 18:03:39 -0700688 genDocsForMetalava := false
689 var metalavaArgs string
690 if Bool(d.properties.Metalava_enabled) {
691 if strings.Contains(args, "--generate-documentation") {
692 if !strings.Contains(args, "-nodocs") {
693 genDocsForMetalava = true
694 }
695 // TODO(nanzhang): Add a Soong property to handle documentation args.
696 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800697 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700698 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800699 }
Nan Zhang581fd212018-01-10 16:06:12 -0800700 }
701
Nan Zhang79614d12018-04-19 18:03:39 -0700702 var templateDir, htmlDirArgs, htmlDir2Args string
703 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
704 if String(d.properties.Custom_template) == "" {
705 // TODO: This is almost always droiddoc-templates-sdk
706 ctx.PropertyErrorf("custom_template", "must specify a template")
707 }
708
709 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
710 if t, ok := m.(*DroiddocTemplate); ok {
711 implicits = append(implicits, t.deps...)
712 templateDir = t.dir.String()
713 } else {
714 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
715 }
716 })
717
718 if len(d.properties.Html_dirs) > 0 {
719 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
720 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
721 htmlDirArgs = "-htmldir " + htmlDir.String()
722 }
723
724 if len(d.properties.Html_dirs) > 1 {
725 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
726 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
727 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
728 }
729
730 if len(d.properties.Html_dirs) > 2 {
731 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
732 }
733
734 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
735 implicits = append(implicits, knownTags...)
736
737 for _, kt := range knownTags {
738 args = args + " -knowntags " + kt.String()
739 }
740
741 for _, hdf := range d.properties.Hdf {
742 args = args + " -hdf " + hdf
743 }
744
745 if String(d.properties.Proofread_file) != "" {
746 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
747 args = args + " -proofread " + proofreadFile.String()
748 }
749
750 if String(d.properties.Todo_file) != "" {
751 // tricky part:
752 // we should not compute full path for todo_file through PathForModuleOut().
753 // the non-standard doclet will get the full path relative to "-o".
754 args = args + " -todo " + String(d.properties.Todo_file)
755 }
756
757 if String(d.properties.Resourcesdir) != "" {
758 // TODO: should we add files under resourcesDir to the implicits? It seems that
759 // resourcesDir is one sub dir of htmlDir
760 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
761 args = args + " -resourcesdir " + resourcesDir.String()
762 }
763
764 if String(d.properties.Resourcesoutdir) != "" {
765 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
766 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
767 }
Dan Willemsencc090972018-02-26 14:33:31 -0800768 }
769
Nan Zhang79614d12018-04-19 18:03:39 -0700770 var docArgsForMetalava string
771 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
772 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800773 }
774
Nan Zhang28c68b92018-03-13 16:17:01 -0700775 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700776
777 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
778 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700779 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700780 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700781 implicitOutputs = append(implicitOutputs, d.apiFile)
782 }
783
Nan Zhang61819ce2018-05-04 18:49:16 -0700784 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
785 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
786 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700787 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700788 implicitOutputs = append(implicitOutputs, d.removedApiFile)
789 }
790
Nan Zhang28c68b92018-03-13 16:17:01 -0700791 if String(d.properties.Private_api_filename) != "" {
792 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
793 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700794 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700795 implicitOutputs = append(implicitOutputs, d.privateApiFile)
796 }
797
David Brazdilfbe4cc32018-05-31 13:56:46 +0100798 if String(d.properties.Dex_api_filename) != "" {
799 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
800 args = args + " -dexApi " + d.dexApiFile.String()
801 implicitOutputs = append(implicitOutputs, d.dexApiFile)
802 }
803
Nan Zhang28c68b92018-03-13 16:17:01 -0700804 if String(d.properties.Private_dex_api_filename) != "" {
805 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
806 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700807 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700808 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
809 }
810
David Brazdilaac0c3c2018-04-24 16:23:29 +0100811 if String(d.properties.Removed_dex_api_filename) != "" {
812 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
813 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700814 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100815 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
816 }
817
Nan Zhang28c68b92018-03-13 16:17:01 -0700818 if String(d.properties.Exact_api_filename) != "" {
819 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
820 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700821 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700822 implicitOutputs = append(implicitOutputs, d.exactApiFile)
823 }
824
Nan Zhang581fd212018-01-10 16:06:12 -0800825 implicits = append(implicits, d.Javadoc.srcJars...)
826
Nan Zhang79614d12018-04-19 18:03:39 -0700827 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
828 for _, o := range d.properties.Out {
829 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
830 }
831
Nan Zhang30963742018-04-23 09:59:14 -0700832 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
833 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700834
Nan Zhang46130972018-06-04 11:28:01 -0700835 var date string
836 if runtime.GOOS == "darwin" {
837 date = `date -r`
838 } else {
839 date = `date -d`
840 }
841
Nan Zhang357466b2018-04-17 17:38:36 -0700842 doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700843 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800844 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800845 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700846 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700847
Nan Zhang79614d12018-04-19 18:03:39 -0700848 if !Bool(d.properties.Metalava_enabled) {
849 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800850
Nan Zhang79614d12018-04-19 18:03:39 -0700851 implicits = append(implicits, jsilver)
852 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800853
Nan Zhang79614d12018-04-19 18:03:39 -0700854 if BoolDefault(d.properties.Create_stubs, true) {
855 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
856 }
857
858 ctx.Build(pctx, android.BuildParams{
859 Rule: javadoc,
860 Description: "Droiddoc",
861 Output: d.Javadoc.stubsSrcJar,
862 Inputs: d.Javadoc.srcFiles,
863 Implicits: implicits,
864 ImplicitOutputs: implicitOutputs,
865 Args: map[string]string{
866 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
867 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
868 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
869 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
870 "opts": opts,
871 "bootclasspathArgs": bootClasspathArgs,
872 "classpathArgs": classpathArgs,
873 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
874 "docZip": d.Javadoc.docZip.String(),
875 },
876 })
877 } else {
878 opts := metalavaArgs
879
880 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800881 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
882 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
883 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
884 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700885 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800886 "bootclasspathArgs": bootClasspathArgs,
887 "classpathArgs": classpathArgs,
888 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
889 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700890 }
891
892 var previousApi android.Path
893 if String(d.properties.Metalava_previous_api) != "" {
894 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
895 "metalava_previous_api")
Nan Zhang16c0a312018-06-13 17:42:48 -0700896 opts += " --previous-api " + previousApi.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700897 implicits = append(implicits, previousApi)
898 }
899
900 if Bool(d.properties.Metalava_annotations_enabled) {
901 if String(d.properties.Metalava_previous_api) == "" {
902 ctx.PropertyErrorf("metalava_previous_api",
903 "has to be non-empty if annotations was enabled!")
904 }
905 opts += " --include-annotations --migrate-nullness"
906
907 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
908 implicitOutputs = append(implicitOutputs, annotationsZip)
909
910 if String(d.properties.Metalava_merge_annotations_dir) == "" {
911 ctx.PropertyErrorf("metalava_merge_annotations",
912 "has to be non-empty if annotations was enabled!")
913 }
914
Nan Zhang16c0a312018-06-13 17:42:48 -0700915 mergeAnnotationsDir := android.PathForSource(ctx, String(d.properties.Metalava_merge_annotations_dir))
Nan Zhang79614d12018-04-19 18:03:39 -0700916
917 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
918 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Nan Zhang16c0a312018-06-13 17:42:48 -0700919 opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhang79614d12018-04-19 18:03:39 -0700920 }
921
922 if genDocsForMetalava {
Nan Zhang16c0a312018-06-13 17:42:48 -0700923 opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
924 " --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
925 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
Nan Zhang79614d12018-04-19 18:03:39 -0700926 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhang16c0a312018-06-13 17:42:48 -0700927 android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
Nan Zhang79614d12018-04-19 18:03:39 -0700928 implicits = append(implicits, jsilver)
929 implicits = append(implicits, doclava)
930 }
931
932 buildArgs["opts"] = opts
933 ctx.Build(pctx, android.BuildParams{
934 Rule: metalava,
935 Description: "Metalava",
936 Output: d.Javadoc.stubsSrcJar,
937 Inputs: d.Javadoc.srcFiles,
938 Implicits: implicits,
939 ImplicitOutputs: implicitOutputs,
940 Args: buildArgs,
941 })
942 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700943
944 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
945
946 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
947
948 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
949 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
950
951 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
952 "check_api.current.api_file")
953 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
954 "check_api.current_removed_api_file")
955
956 ctx.Build(pctx, android.BuildParams{
957 Rule: apiCheck,
958 Description: "Current API check",
959 Output: d.checkCurrentApiTimestamp,
960 Inputs: nil,
961 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
962 checkApiClasspath...),
963 Args: map[string]string{
964 "classpath": checkApiClasspath.FormJavaClassPath(""),
965 "opts": String(d.properties.Check_api.Current.Args),
966 "apiFile": apiFile.String(),
967 "apiFileToCheck": d.apiFile.String(),
968 "removedApiFile": removedApiFile.String(),
969 "removedApiFileToCheck": d.removedApiFile.String(),
970 "msg": fmt.Sprintf(`\n******************************\n`+
971 `You have tried to change the API from what has been previously approved.\n\n`+
972 `To make these errors go away, you have two choices:\n`+
973 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
974 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900975 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700976 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900977 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700978 ` you will need approval.\n`+
979 `******************************\n`, ctx.ModuleName()),
980 },
981 })
982
983 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
984
985 ctx.Build(pctx, android.BuildParams{
986 Rule: updateApi,
987 Description: "update current API",
988 Output: d.updateCurrentApiTimestamp,
989 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
990 Args: map[string]string{
991 "apiFile": apiFile.String(),
992 "apiFileToCheck": d.apiFile.String(),
993 "removedApiFile": removedApiFile.String(),
994 "removedApiFileToCheck": d.removedApiFile.String(),
995 },
996 })
997 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700998 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
999 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1000
1001 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1002 "check_api.last_released.api_file")
1003 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1004 "check_api.last_released.removed_api_file")
1005
1006 ctx.Build(pctx, android.BuildParams{
1007 Rule: apiCheck,
1008 Description: "Last Released API check",
1009 Output: d.checkLastReleasedApiTimestamp,
1010 Inputs: nil,
1011 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1012 checkApiClasspath...),
1013 Args: map[string]string{
1014 "classpath": checkApiClasspath.FormJavaClassPath(""),
1015 "opts": String(d.properties.Check_api.Last_released.Args),
1016 "apiFile": apiFile.String(),
1017 "apiFileToCheck": d.apiFile.String(),
1018 "removedApiFile": removedApiFile.String(),
1019 "removedApiFileToCheck": d.removedApiFile.String(),
1020 "msg": `\n******************************\n` +
1021 `You have tried to change the API from what has been previously released in\n` +
1022 `an SDK. Please fix the errors listed above.\n` +
1023 `******************************\n`,
1024 },
1025 })
1026 }
Nan Zhang581fd212018-01-10 16:06:12 -08001027}
Dan Willemsencc090972018-02-26 14:33:31 -08001028
1029var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
1030
1031type DroiddocTemplateProperties struct {
1032 // path to the directory containing the droiddoc templates.
1033 Path *string
1034}
1035
1036type DroiddocTemplate struct {
1037 android.ModuleBase
1038
1039 properties DroiddocTemplateProperties
1040
1041 deps android.Paths
1042 dir android.Path
1043}
1044
1045func DroiddocTemplateFactory() android.Module {
1046 module := &DroiddocTemplate{}
1047 module.AddProperties(&module.properties)
1048 android.InitAndroidModule(module)
1049 return module
1050}
1051
1052func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1053
1054func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1055 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1056 d.dir = path
1057 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1058}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001059
1060//
1061// Defaults
1062//
1063type DocDefaults struct {
1064 android.ModuleBase
1065 android.DefaultsModuleBase
1066}
1067
1068func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1069}
1070
1071func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1072}
1073
1074func DocDefaultsFactory() android.Module {
1075 module := &DocDefaults{}
1076
1077 module.AddProperties(
1078 &JavadocProperties{},
1079 &DroiddocProperties{},
1080 )
1081
1082 android.InitDefaultsModule(module)
1083
1084 return module
1085}