blob: 13a8e7845bd99f919c190ab8c12887d723b199c2 [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 Zhang357466b2018-04-17 17:38:36 -070033 `${config.JavadocCmd} -source $javaVersion -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 Zhang357466b2018-04-17 17:38:36 -070047 "outDir", "srcJarDir", "stubsDir", "javaVersion", "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
553 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
554
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(),
Nan Zhang357466b2018-04-17 17:38:36 -0700566 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800567 "srcJars": strings.Join(j.srcJars.Strings(), " "),
568 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700569 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800570 "classpathArgs": classpathArgs,
571 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
572 "docZip": j.docZip.String(),
573 },
574 })
575}
576
Nan Zhang61819ce2018-05-04 18:49:16 -0700577func (d *Droiddoc) checkCurrentApi() bool {
578 if String(d.properties.Check_api.Current.Api_file) != "" &&
579 String(d.properties.Check_api.Current.Removed_api_file) != "" {
580 return true
581 } else if String(d.properties.Check_api.Current.Api_file) != "" {
582 panic("check_api.current.removed_api_file: has to be non empty!")
583 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
584 panic("check_api.current.api_file: has to be non empty!")
585 }
586
587 return false
588}
589
590func (d *Droiddoc) checkLastReleasedApi() bool {
591 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
592 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
593 return true
594 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
595 panic("check_api.last_released.removed_api_file: has to be non empty!")
596 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
597 panic("check_api.last_released.api_file: has to be non empty!")
598 }
599
600 return false
601}
602
Nan Zhang581fd212018-01-10 16:06:12 -0800603func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
604 d.Javadoc.addDeps(ctx)
605
Nan Zhang79614d12018-04-19 18:03:39 -0700606 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800607 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
608 }
609
Nan Zhang581fd212018-01-10 16:06:12 -0800610 // extra_arg_files may contains filegroup or genrule.
611 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
612
613 // knowntags may contain filegroup or genrule.
614 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700615
616 if d.checkCurrentApi() {
617 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
618 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
619 }
620
621 if d.checkLastReleasedApi() {
622 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
623 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
624 }
Nan Zhang79614d12018-04-19 18:03:39 -0700625
626 if String(d.properties.Metalava_previous_api) != "" {
627 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
628 }
Nan Zhang581fd212018-01-10 16:06:12 -0800629}
630
631func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
632 deps := d.Javadoc.collectDeps(ctx)
633
634 var implicits android.Paths
635 implicits = append(implicits, deps.bootClasspath...)
636 implicits = append(implicits, deps.classpath...)
637
Nan Zhang357466b2018-04-17 17:38:36 -0700638 var bootClasspathArgs string
639 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), String(d.Javadoc.properties.Sdk_version))
640 if javaVersion == "1.9" {
641 if len(deps.bootClasspath) > 0 {
642 var systemModules classpath
643 if deps.systemModules != nil {
644 systemModules = append(systemModules, deps.systemModules)
645 }
646 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
647 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
648 }
649 } else {
650 if len(deps.bootClasspath.Strings()) > 0 {
651 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
652 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
653 }
654 }
Nan Zhang79614d12018-04-19 18:03:39 -0700655 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
656
Nan Zhang581fd212018-01-10 16:06:12 -0800657 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
658 argFilesMap := map[string]android.Path{}
659
660 for _, f := range argFiles {
661 implicits = append(implicits, f)
662 if _, exists := argFilesMap[f.Rel()]; !exists {
663 argFilesMap[f.Rel()] = f
664 } else {
665 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
666 f, argFilesMap[f.Rel()], f.Rel())
667 }
668 }
669
670 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
671 if strings.HasPrefix(name, "location ") {
672 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
673 if f, ok := argFilesMap[label]; ok {
674 return f.String(), nil
675 } else {
676 return "", fmt.Errorf("unknown location label %q", label)
677 }
678 } else if name == "genDir" {
679 return android.PathForModuleGen(ctx).String(), nil
680 }
681 return "", fmt.Errorf("unknown variable '$(%s)'", name)
682 })
683
684 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700685 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800686 return
687 }
688
Nan Zhang79614d12018-04-19 18:03:39 -0700689 genDocsForMetalava := false
690 var metalavaArgs string
691 if Bool(d.properties.Metalava_enabled) {
692 if strings.Contains(args, "--generate-documentation") {
693 if !strings.Contains(args, "-nodocs") {
694 genDocsForMetalava = true
695 }
696 // TODO(nanzhang): Add a Soong property to handle documentation args.
697 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800698 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700699 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800700 }
Nan Zhang581fd212018-01-10 16:06:12 -0800701 }
702
Nan Zhang79614d12018-04-19 18:03:39 -0700703 var templateDir, htmlDirArgs, htmlDir2Args string
704 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
705 if String(d.properties.Custom_template) == "" {
706 // TODO: This is almost always droiddoc-templates-sdk
707 ctx.PropertyErrorf("custom_template", "must specify a template")
708 }
709
710 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
711 if t, ok := m.(*DroiddocTemplate); ok {
712 implicits = append(implicits, t.deps...)
713 templateDir = t.dir.String()
714 } else {
715 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
716 }
717 })
718
719 if len(d.properties.Html_dirs) > 0 {
720 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
721 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
722 htmlDirArgs = "-htmldir " + htmlDir.String()
723 }
724
725 if len(d.properties.Html_dirs) > 1 {
726 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
727 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
728 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
729 }
730
731 if len(d.properties.Html_dirs) > 2 {
732 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
733 }
734
735 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
736 implicits = append(implicits, knownTags...)
737
738 for _, kt := range knownTags {
739 args = args + " -knowntags " + kt.String()
740 }
741
742 for _, hdf := range d.properties.Hdf {
743 args = args + " -hdf " + hdf
744 }
745
746 if String(d.properties.Proofread_file) != "" {
747 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
748 args = args + " -proofread " + proofreadFile.String()
749 }
750
751 if String(d.properties.Todo_file) != "" {
752 // tricky part:
753 // we should not compute full path for todo_file through PathForModuleOut().
754 // the non-standard doclet will get the full path relative to "-o".
755 args = args + " -todo " + String(d.properties.Todo_file)
756 }
757
758 if String(d.properties.Resourcesdir) != "" {
759 // TODO: should we add files under resourcesDir to the implicits? It seems that
760 // resourcesDir is one sub dir of htmlDir
761 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
762 args = args + " -resourcesdir " + resourcesDir.String()
763 }
764
765 if String(d.properties.Resourcesoutdir) != "" {
766 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
767 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
768 }
Dan Willemsencc090972018-02-26 14:33:31 -0800769 }
770
Nan Zhang79614d12018-04-19 18:03:39 -0700771 var docArgsForMetalava string
772 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
773 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800774 }
775
Nan Zhang28c68b92018-03-13 16:17:01 -0700776 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700777
778 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
779 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700780 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700781 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700782 implicitOutputs = append(implicitOutputs, d.apiFile)
783 }
784
Nan Zhang61819ce2018-05-04 18:49:16 -0700785 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
786 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
787 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700788 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700789 implicitOutputs = append(implicitOutputs, d.removedApiFile)
790 }
791
Nan Zhang28c68b92018-03-13 16:17:01 -0700792 if String(d.properties.Private_api_filename) != "" {
793 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
794 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700795 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700796 implicitOutputs = append(implicitOutputs, d.privateApiFile)
797 }
798
David Brazdilfbe4cc32018-05-31 13:56:46 +0100799 if String(d.properties.Dex_api_filename) != "" {
800 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
801 args = args + " -dexApi " + d.dexApiFile.String()
802 implicitOutputs = append(implicitOutputs, d.dexApiFile)
803 }
804
Nan Zhang28c68b92018-03-13 16:17:01 -0700805 if String(d.properties.Private_dex_api_filename) != "" {
806 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
807 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700808 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700809 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
810 }
811
David Brazdilaac0c3c2018-04-24 16:23:29 +0100812 if String(d.properties.Removed_dex_api_filename) != "" {
813 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
814 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700815 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100816 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
817 }
818
Nan Zhang28c68b92018-03-13 16:17:01 -0700819 if String(d.properties.Exact_api_filename) != "" {
820 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
821 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700822 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700823 implicitOutputs = append(implicitOutputs, d.exactApiFile)
824 }
825
Nan Zhang581fd212018-01-10 16:06:12 -0800826 implicits = append(implicits, d.Javadoc.srcJars...)
827
Nan Zhang79614d12018-04-19 18:03:39 -0700828 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
829 for _, o := range d.properties.Out {
830 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
831 }
832
Nan Zhang30963742018-04-23 09:59:14 -0700833 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
834 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700835
Nan Zhang46130972018-06-04 11:28:01 -0700836 var date string
837 if runtime.GOOS == "darwin" {
838 date = `date -r`
839 } else {
840 date = `date -d`
841 }
842
Nan Zhang357466b2018-04-17 17:38:36 -0700843 doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700844 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800845 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800846 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700847 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700848
Nan Zhang79614d12018-04-19 18:03:39 -0700849 if !Bool(d.properties.Metalava_enabled) {
850 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800851
Nan Zhang79614d12018-04-19 18:03:39 -0700852 implicits = append(implicits, jsilver)
853 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800854
Nan Zhang79614d12018-04-19 18:03:39 -0700855 if BoolDefault(d.properties.Create_stubs, true) {
856 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
857 }
858
859 ctx.Build(pctx, android.BuildParams{
860 Rule: javadoc,
861 Description: "Droiddoc",
862 Output: d.Javadoc.stubsSrcJar,
863 Inputs: d.Javadoc.srcFiles,
864 Implicits: implicits,
865 ImplicitOutputs: implicitOutputs,
866 Args: map[string]string{
867 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
868 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
869 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
870 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700871 "javaVersion": javaVersion,
Nan Zhang79614d12018-04-19 18:03:39 -0700872 "opts": opts,
873 "bootclasspathArgs": bootClasspathArgs,
874 "classpathArgs": classpathArgs,
875 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
876 "docZip": d.Javadoc.docZip.String(),
877 },
878 })
879 } else {
880 opts := metalavaArgs
881
882 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800883 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
884 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
885 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
886 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700887 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800888 "bootclasspathArgs": bootClasspathArgs,
889 "classpathArgs": classpathArgs,
890 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
891 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700892 }
893
894 var previousApi android.Path
895 if String(d.properties.Metalava_previous_api) != "" {
896 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
897 "metalava_previous_api")
Nan Zhang16c0a312018-06-13 17:42:48 -0700898 opts += " --previous-api " + previousApi.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700899 implicits = append(implicits, previousApi)
900 }
901
902 if Bool(d.properties.Metalava_annotations_enabled) {
903 if String(d.properties.Metalava_previous_api) == "" {
904 ctx.PropertyErrorf("metalava_previous_api",
905 "has to be non-empty if annotations was enabled!")
906 }
907 opts += " --include-annotations --migrate-nullness"
908
909 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
910 implicitOutputs = append(implicitOutputs, annotationsZip)
911
912 if String(d.properties.Metalava_merge_annotations_dir) == "" {
913 ctx.PropertyErrorf("metalava_merge_annotations",
914 "has to be non-empty if annotations was enabled!")
915 }
916
Nan Zhang16c0a312018-06-13 17:42:48 -0700917 mergeAnnotationsDir := android.PathForSource(ctx, String(d.properties.Metalava_merge_annotations_dir))
Nan Zhang79614d12018-04-19 18:03:39 -0700918
919 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
920 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Nan Zhang16c0a312018-06-13 17:42:48 -0700921 opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhang79614d12018-04-19 18:03:39 -0700922 }
923
924 if genDocsForMetalava {
Nan Zhang16c0a312018-06-13 17:42:48 -0700925 opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
926 " --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
927 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
Nan Zhang79614d12018-04-19 18:03:39 -0700928 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhang16c0a312018-06-13 17:42:48 -0700929 android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
Nan Zhang79614d12018-04-19 18:03:39 -0700930 implicits = append(implicits, jsilver)
931 implicits = append(implicits, doclava)
932 }
933
934 buildArgs["opts"] = opts
935 ctx.Build(pctx, android.BuildParams{
936 Rule: metalava,
937 Description: "Metalava",
938 Output: d.Javadoc.stubsSrcJar,
939 Inputs: d.Javadoc.srcFiles,
940 Implicits: implicits,
941 ImplicitOutputs: implicitOutputs,
942 Args: buildArgs,
943 })
944 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700945
946 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
947
948 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
949
950 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
951 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
952
953 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
954 "check_api.current.api_file")
955 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
956 "check_api.current_removed_api_file")
957
958 ctx.Build(pctx, android.BuildParams{
959 Rule: apiCheck,
960 Description: "Current API check",
961 Output: d.checkCurrentApiTimestamp,
962 Inputs: nil,
963 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
964 checkApiClasspath...),
965 Args: map[string]string{
966 "classpath": checkApiClasspath.FormJavaClassPath(""),
967 "opts": String(d.properties.Check_api.Current.Args),
968 "apiFile": apiFile.String(),
969 "apiFileToCheck": d.apiFile.String(),
970 "removedApiFile": removedApiFile.String(),
971 "removedApiFileToCheck": d.removedApiFile.String(),
972 "msg": fmt.Sprintf(`\n******************************\n`+
973 `You have tried to change the API from what has been previously approved.\n\n`+
974 `To make these errors go away, you have two choices:\n`+
975 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
976 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900977 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700978 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900979 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700980 ` you will need approval.\n`+
981 `******************************\n`, ctx.ModuleName()),
982 },
983 })
984
985 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
986
987 ctx.Build(pctx, android.BuildParams{
988 Rule: updateApi,
989 Description: "update current API",
990 Output: d.updateCurrentApiTimestamp,
991 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
992 Args: map[string]string{
993 "apiFile": apiFile.String(),
994 "apiFileToCheck": d.apiFile.String(),
995 "removedApiFile": removedApiFile.String(),
996 "removedApiFileToCheck": d.removedApiFile.String(),
997 },
998 })
999 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001000 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
1001 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1002
1003 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1004 "check_api.last_released.api_file")
1005 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1006 "check_api.last_released.removed_api_file")
1007
1008 ctx.Build(pctx, android.BuildParams{
1009 Rule: apiCheck,
1010 Description: "Last Released API check",
1011 Output: d.checkLastReleasedApiTimestamp,
1012 Inputs: nil,
1013 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1014 checkApiClasspath...),
1015 Args: map[string]string{
1016 "classpath": checkApiClasspath.FormJavaClassPath(""),
1017 "opts": String(d.properties.Check_api.Last_released.Args),
1018 "apiFile": apiFile.String(),
1019 "apiFileToCheck": d.apiFile.String(),
1020 "removedApiFile": removedApiFile.String(),
1021 "removedApiFileToCheck": d.removedApiFile.String(),
1022 "msg": `\n******************************\n` +
1023 `You have tried to change the API from what has been previously released in\n` +
1024 `an SDK. Please fix the errors listed above.\n` +
1025 `******************************\n`,
1026 },
1027 })
1028 }
Nan Zhang581fd212018-01-10 16:06:12 -08001029}
Dan Willemsencc090972018-02-26 14:33:31 -08001030
1031var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
1032
1033type DroiddocTemplateProperties struct {
1034 // path to the directory containing the droiddoc templates.
1035 Path *string
1036}
1037
1038type DroiddocTemplate struct {
1039 android.ModuleBase
1040
1041 properties DroiddocTemplateProperties
1042
1043 deps android.Paths
1044 dir android.Path
1045}
1046
1047func DroiddocTemplateFactory() android.Module {
1048 module := &DroiddocTemplate{}
1049 module.AddProperties(&module.properties)
1050 android.InitAndroidModule(module)
1051 return module
1052}
1053
1054func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1055
1056func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1057 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1058 d.dir = path
1059 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1060}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001061
1062//
1063// Defaults
1064//
1065type DocDefaults struct {
1066 android.ModuleBase
1067 android.DefaultsModuleBase
1068}
1069
1070func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1071}
1072
1073func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1074}
1075
1076func DocDefaultsFactory() android.Module {
1077 module := &DocDefaults{}
1078
1079 module.AddProperties(
1080 &JavadocProperties{},
1081 &DroiddocProperties{},
1082 )
1083
1084 android.InitDefaultsModule(module)
1085
1086 return module
1087}