blob: 6cb8d3c14668991677eb26c1cc91e83b2ae46a3b [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
Colin Crossa1ce2a02018-06-20 15:19:39 -0700102var (
103 srcsLibTag = dependencyTag{name: "sources from javalib"}
104)
105
Nan Zhang581fd212018-01-10 16:06:12 -0800106type JavadocProperties struct {
107 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
108 // or .aidl files.
109 Srcs []string `android:"arch_variant"`
110
111 // list of directories rooted at the Android.bp file that will
112 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800113 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800114
115 // list of source files that should not be used to build the Java module.
116 // This is most useful in the arch/multilib variants to remove non-common files
117 // filegroup or genrule can be included within this property.
118 Exclude_srcs []string `android:"arch_variant"`
119
Nan Zhangb2b33de2018-02-23 11:18:47 -0800120 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800121 Libs []string `android:"arch_variant"`
122
Nan Zhange66c7272018-03-06 12:59:27 -0800123 // don't build against the framework libraries (legacy-test, core-junit,
124 // ext, and framework for device targets)
125 No_framework_libs *bool
126
Nan Zhangb2b33de2018-02-23 11:18:47 -0800127 // the java library (in classpath) for documentation that provides java srcs and srcjars.
128 Srcs_lib *string
129
130 // the base dirs under srcs_lib will be scanned for java srcs.
131 Srcs_lib_whitelist_dirs []string
132
133 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
134 Srcs_lib_whitelist_pkgs []string
135
Nan Zhang581fd212018-01-10 16:06:12 -0800136 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800137 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800138
139 // if not blank, set to the version of the sdk to compile against
140 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900141
142 Aidl struct {
143 // Top level directories to pass to aidl tool
144 Include_dirs []string
145
146 // Directories rooted at the Android.bp file to pass to aidl tool
147 Local_include_dirs []string
148 }
Nan Zhang357466b2018-04-17 17:38:36 -0700149
150 // If not blank, set the java version passed to javadoc as -source
151 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800152}
153
Nan Zhang61819ce2018-05-04 18:49:16 -0700154type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900155 // path to the API txt file that the new API extracted from source code is checked
156 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700157 Api_file *string
158
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900159 // path to the API txt file that the new @removed API extractd from source code is
160 // checked against. The path can be local to the module or from other module (via
161 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700162 Removed_api_file *string
163
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900164 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700165 Args *string
166}
167
Nan Zhang581fd212018-01-10 16:06:12 -0800168type DroiddocProperties struct {
169 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800170 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800171
172 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800173 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800174
175 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800176 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800177
178 // proofread file contains all of the text content of the javadocs concatenated into one file,
179 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800180 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800181
182 // a todo file lists the program elements that are missing documentation.
183 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800184 Todo_file *string
185
186 // directory under current module source that provide additional resources (images).
187 Resourcesdir *string
188
189 // resources output directory under out/soong/.intermediates.
190 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800191
192 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800193 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800194
195 // user customized droiddoc args.
196 // Available variables for substitution:
197 //
198 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800199 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800200
201 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800202 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800203
204 // a list of files under current module source dir which contains known tags in Java sources.
205 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800206 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700207
208 // the tag name used to distinguish if the API files belong to public/system/test.
209 Api_tag_name *string
210
211 // the generated public API filename by Doclava.
212 Api_filename *string
213
David Brazdilfbe4cc32018-05-31 13:56:46 +0100214 // the generated public Dex API filename by Doclava.
215 Dex_api_filename *string
216
Nan Zhang28c68b92018-03-13 16:17:01 -0700217 // the generated private API filename by Doclava.
218 Private_api_filename *string
219
220 // the generated private Dex API filename by Doclava.
221 Private_dex_api_filename *string
222
223 // the generated removed API filename by Doclava.
224 Removed_api_filename *string
225
David Brazdilaac0c3c2018-04-24 16:23:29 +0100226 // the generated removed Dex API filename by Doclava.
227 Removed_dex_api_filename *string
228
Mathew Inwood76c3de12018-06-22 15:28:11 +0100229 // mapping of dex signatures to source file and line number. This is a temporary property and
230 // will be deleted; you probably shouldn't be using it.
231 Dex_mapping_filename *string
232
Nan Zhang28c68b92018-03-13 16:17:01 -0700233 // the generated exact API filename by Doclava.
234 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700235
236 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
237 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700238
239 Check_api struct {
240 Last_released ApiToCheck
241
242 Current ApiToCheck
243 }
Nan Zhang79614d12018-04-19 18:03:39 -0700244
245 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
246 // currently still used for documentation generation, and will be replaced by Dokka soon.
247 Metalava_enabled *bool
248
249 // user can specify the version of previous released API file in order to do compatibility check.
250 Metalava_previous_api *string
251
252 // is set to true, Metalava will allow framework SDK to contain annotations.
253 Metalava_annotations_enabled *bool
254
Nan Zhang16c0a312018-06-13 17:42:48 -0700255 // a top level directory contains XML files set to merge annotations.
Nan Zhang79614d12018-04-19 18:03:39 -0700256 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800257}
258
259type Javadoc struct {
260 android.ModuleBase
261 android.DefaultableModuleBase
262
263 properties JavadocProperties
264
265 srcJars android.Paths
266 srcFiles android.Paths
267 sourcepaths android.Paths
268
Nan Zhangccff0f72018-03-08 17:26:16 -0800269 docZip android.WritablePath
270 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800271}
272
Nan Zhangb2b33de2018-02-23 11:18:47 -0800273func (j *Javadoc) Srcs() android.Paths {
274 return android.Paths{j.stubsSrcJar}
275}
276
277var _ android.SourceFileProducer = (*Javadoc)(nil)
278
Nan Zhang581fd212018-01-10 16:06:12 -0800279type Droiddoc struct {
280 Javadoc
281
Nan Zhang28c68b92018-03-13 16:17:01 -0700282 properties DroiddocProperties
283 apiFile android.WritablePath
David Brazdilfbe4cc32018-05-31 13:56:46 +0100284 dexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700285 privateApiFile android.WritablePath
286 privateDexApiFile android.WritablePath
287 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100288 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700289 exactApiFile android.WritablePath
Mathew Inwood76c3de12018-06-22 15:28:11 +0100290 apiMappingFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700291
292 checkCurrentApiTimestamp android.WritablePath
293 updateCurrentApiTimestamp android.WritablePath
294 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800295}
296
297func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
298 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
299 android.InitDefaultableModule(module)
300}
301
302func JavadocFactory() android.Module {
303 module := &Javadoc{}
304
305 module.AddProperties(&module.properties)
306
307 InitDroiddocModule(module, android.HostAndDeviceSupported)
308 return module
309}
310
311func JavadocHostFactory() android.Module {
312 module := &Javadoc{}
313
314 module.AddProperties(&module.properties)
315
316 InitDroiddocModule(module, android.HostSupported)
317 return module
318}
319
320func DroiddocFactory() android.Module {
321 module := &Droiddoc{}
322
323 module.AddProperties(&module.properties,
324 &module.Javadoc.properties)
325
326 InitDroiddocModule(module, android.HostAndDeviceSupported)
327 return module
328}
329
330func DroiddocHostFactory() android.Module {
331 module := &Droiddoc{}
332
333 module.AddProperties(&module.properties,
334 &module.Javadoc.properties)
335
336 InitDroiddocModule(module, android.HostSupported)
337 return module
338}
339
Colin Cross83bb3162018-06-25 15:48:06 -0700340func (j *Javadoc) sdkVersion() string {
341 return String(j.properties.Sdk_version)
342}
343
344func (j *Javadoc) minSdkVersion() string {
345 return j.sdkVersion()
346}
347
Nan Zhang581fd212018-01-10 16:06:12 -0800348func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
349 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700350 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800351 if sdkDep.useDefaultLibs {
352 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700353 if ctx.Config().TargetOpenJDK9() {
354 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
355 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700356 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800357 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
358 }
Nan Zhang581fd212018-01-10 16:06:12 -0800359 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700360 if ctx.Config().TargetOpenJDK9() {
361 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
362 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700363 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800364 }
365 }
366
367 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700368 if j.properties.Srcs_lib != nil {
369 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
370 }
Nan Zhang581fd212018-01-10 16:06:12 -0800371
372 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
373
374 // exclude_srcs may contain filegroup or genrule.
375 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
376}
377
Nan Zhangb2b33de2018-02-23 11:18:47 -0800378func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
379 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
380 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900381 // convert foo.bar.baz to foo/bar/baz
382 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
383 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800384 if _, found := whitelistPathPrefixes[prefix]; !found {
385 whitelistPathPrefixes[prefix] = true
386 }
387 }
388 }
389}
390
Jiyong Park1e440682018-05-23 18:42:04 +0900391func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
392 var flags javaBuilderFlags
393
394 // aidl flags.
395 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
396 if len(aidlFlags) > 0 {
397 // optimization.
398 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
399 flags.aidlFlags = "$aidlFlags"
400 }
401
402 return flags
403}
404
405func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
406 aidlIncludeDirs android.Paths) []string {
407
408 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
409 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
410
411 var flags []string
412 if aidlPreprocess.Valid() {
413 flags = append(flags, "-p"+aidlPreprocess.String())
414 } else {
415 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
416 }
417
418 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
419 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
420 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
421 flags = append(flags, "-I"+src.String())
422 }
423
424 return flags
425}
426
427func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
428 flags javaBuilderFlags) android.Paths {
429
430 outSrcFiles := make(android.Paths, 0, len(srcFiles))
431
432 for _, srcFile := range srcFiles {
433 switch srcFile.Ext() {
434 case ".aidl":
435 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
436 outSrcFiles = append(outSrcFiles, javaFile)
437 default:
438 outSrcFiles = append(outSrcFiles, srcFile)
439 }
440 }
441
442 return outSrcFiles
443}
444
Nan Zhang581fd212018-01-10 16:06:12 -0800445func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
446 var deps deps
447
Colin Cross83bb3162018-06-25 15:48:06 -0700448 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800449 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700450 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800451 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700452 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800453 }
454
455 ctx.VisitDirectDeps(func(module android.Module) {
456 otherName := ctx.OtherModuleName(module)
457 tag := ctx.OtherModuleDependencyTag(module)
458
Colin Cross2d24c1b2018-05-23 10:59:18 -0700459 switch tag {
460 case bootClasspathTag:
461 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800462 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700463 } else {
464 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
465 }
466 case libTag:
467 switch dep := module.(type) {
468 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800469 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700470 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700471 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900472 linkType := javaSdk
473 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
474 linkType = javaSystem
475 } else if sdkVersion == "" {
476 linkType = javaPlatform
477 }
478 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700479 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800480 checkProducesJars(ctx, dep)
481 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800482 default:
483 ctx.ModuleErrorf("depends on non-java module %q", otherName)
484 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700485 case srcsLibTag:
486 switch dep := module.(type) {
487 case Dependency:
488 srcs := dep.(SrcDependency).CompiledSrcs()
489 whitelistPathPrefixes := make(map[string]bool)
490 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
491 for _, src := range srcs {
492 if _, ok := src.(android.WritablePath); ok { // generated sources
493 deps.srcs = append(deps.srcs, src)
494 } else { // select source path for documentation based on whitelist path prefixs.
495 for k, _ := range whitelistPathPrefixes {
496 if strings.HasPrefix(src.Rel(), k) {
497 deps.srcs = append(deps.srcs, src)
498 break
499 }
500 }
501 }
502 }
503 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
504 default:
505 ctx.ModuleErrorf("depends on non-java module %q", otherName)
506 }
Nan Zhang357466b2018-04-17 17:38:36 -0700507 case systemModulesTag:
508 if deps.systemModules != nil {
509 panic("Found two system module dependencies")
510 }
511 sm := module.(*SystemModules)
512 if sm.outputFile == nil {
513 panic("Missing directory for system module dependency")
514 }
515 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800516 }
517 })
518 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
519 // may contain filegroup or genrule.
520 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900521 flags := j.collectBuilderFlags(ctx, deps)
522 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800523
524 // srcs may depend on some genrule output.
525 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800526 j.srcJars = append(j.srcJars, deps.srcJars...)
527
Nan Zhang581fd212018-01-10 16:06:12 -0800528 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800529 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800530
531 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800532 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800533
534 if j.properties.Local_sourcepaths == nil {
535 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
536 }
537 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800538
539 return deps
540}
541
542func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
543 j.addDeps(ctx)
544}
545
546func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
547 deps := j.collectDeps(ctx)
548
549 var implicits android.Paths
550 implicits = append(implicits, deps.bootClasspath...)
551 implicits = append(implicits, deps.classpath...)
552
553 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700554
Colin Cross83bb3162018-06-25 15:48:06 -0700555 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700556 if len(deps.bootClasspath) > 0 {
557 var systemModules classpath
558 if deps.systemModules != nil {
559 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800560 }
Colin Cross997262f2018-06-19 22:49:39 -0700561 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
562 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800563 }
564 if len(deps.classpath.Strings()) > 0 {
565 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
566 }
567
568 implicits = append(implicits, j.srcJars...)
569
Nan Zhangaf322cc2018-06-19 15:15:38 -0700570 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800571
572 ctx.Build(pctx, android.BuildParams{
573 Rule: javadoc,
574 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800575 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800576 ImplicitOutput: j.docZip,
577 Inputs: j.srcFiles,
578 Implicits: implicits,
579 Args: map[string]string{
580 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
581 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
582 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
583 "srcJars": strings.Join(j.srcJars.Strings(), " "),
584 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700585 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800586 "classpathArgs": classpathArgs,
587 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
588 "docZip": j.docZip.String(),
589 },
590 })
591}
592
Nan Zhang61819ce2018-05-04 18:49:16 -0700593func (d *Droiddoc) checkCurrentApi() bool {
594 if String(d.properties.Check_api.Current.Api_file) != "" &&
595 String(d.properties.Check_api.Current.Removed_api_file) != "" {
596 return true
597 } else if String(d.properties.Check_api.Current.Api_file) != "" {
598 panic("check_api.current.removed_api_file: has to be non empty!")
599 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
600 panic("check_api.current.api_file: has to be non empty!")
601 }
602
603 return false
604}
605
606func (d *Droiddoc) checkLastReleasedApi() bool {
607 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
608 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
609 return true
610 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
611 panic("check_api.last_released.removed_api_file: has to be non empty!")
612 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
613 panic("check_api.last_released.api_file: has to be non empty!")
614 }
615
616 return false
617}
618
Nan Zhang581fd212018-01-10 16:06:12 -0800619func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
620 d.Javadoc.addDeps(ctx)
621
Nan Zhang79614d12018-04-19 18:03:39 -0700622 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800623 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
624 }
625
Nan Zhang581fd212018-01-10 16:06:12 -0800626 // extra_arg_files may contains filegroup or genrule.
627 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
628
629 // knowntags may contain filegroup or genrule.
630 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700631
632 if d.checkCurrentApi() {
633 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
634 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
635 }
636
637 if d.checkLastReleasedApi() {
638 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
639 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
640 }
Nan Zhang79614d12018-04-19 18:03:39 -0700641
642 if String(d.properties.Metalava_previous_api) != "" {
643 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
644 }
Nan Zhang581fd212018-01-10 16:06:12 -0800645}
646
647func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
648 deps := d.Javadoc.collectDeps(ctx)
649
650 var implicits android.Paths
651 implicits = append(implicits, deps.bootClasspath...)
652 implicits = append(implicits, deps.classpath...)
653
Nan Zhang357466b2018-04-17 17:38:36 -0700654 var bootClasspathArgs string
Colin Cross83bb3162018-06-25 15:48:06 -0700655 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang7ca46782018-06-25 13:00:25 -0700656 // Doclava has problem with "-source 1.9", so override javaVersion when Doclava
657 // is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
658 // replaced by Metalava.
659 if !Bool(d.properties.Metalava_enabled) {
660 javaVersion = "1.8"
661 }
Nan Zhangc94f9d82018-06-26 10:02:26 -0700662 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
663 // since it doesn't support system modules yet.
664 if len(deps.bootClasspath.Strings()) > 0 {
665 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
666 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700667 }
Nan Zhang79614d12018-04-19 18:03:39 -0700668 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
669
Nan Zhang581fd212018-01-10 16:06:12 -0800670 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
671 argFilesMap := map[string]android.Path{}
672
673 for _, f := range argFiles {
674 implicits = append(implicits, f)
675 if _, exists := argFilesMap[f.Rel()]; !exists {
676 argFilesMap[f.Rel()] = f
677 } else {
678 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
679 f, argFilesMap[f.Rel()], f.Rel())
680 }
681 }
682
683 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
684 if strings.HasPrefix(name, "location ") {
685 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
686 if f, ok := argFilesMap[label]; ok {
687 return f.String(), nil
688 } else {
689 return "", fmt.Errorf("unknown location label %q", label)
690 }
691 } else if name == "genDir" {
692 return android.PathForModuleGen(ctx).String(), nil
693 }
694 return "", fmt.Errorf("unknown variable '$(%s)'", name)
695 })
696
697 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700698 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800699 return
700 }
701
Nan Zhang79614d12018-04-19 18:03:39 -0700702 genDocsForMetalava := false
703 var metalavaArgs string
704 if Bool(d.properties.Metalava_enabled) {
705 if strings.Contains(args, "--generate-documentation") {
706 if !strings.Contains(args, "-nodocs") {
707 genDocsForMetalava = true
708 }
709 // TODO(nanzhang): Add a Soong property to handle documentation args.
710 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800711 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700712 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800713 }
Nan Zhang581fd212018-01-10 16:06:12 -0800714 }
715
Nan Zhang79614d12018-04-19 18:03:39 -0700716 var templateDir, htmlDirArgs, htmlDir2Args string
717 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
718 if String(d.properties.Custom_template) == "" {
719 // TODO: This is almost always droiddoc-templates-sdk
720 ctx.PropertyErrorf("custom_template", "must specify a template")
721 }
722
723 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
724 if t, ok := m.(*DroiddocTemplate); ok {
725 implicits = append(implicits, t.deps...)
726 templateDir = t.dir.String()
727 } else {
728 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
729 }
730 })
731
732 if len(d.properties.Html_dirs) > 0 {
733 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
734 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
735 htmlDirArgs = "-htmldir " + htmlDir.String()
736 }
737
738 if len(d.properties.Html_dirs) > 1 {
739 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
740 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
741 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
742 }
743
744 if len(d.properties.Html_dirs) > 2 {
745 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
746 }
747
748 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
749 implicits = append(implicits, knownTags...)
750
751 for _, kt := range knownTags {
752 args = args + " -knowntags " + kt.String()
753 }
754
755 for _, hdf := range d.properties.Hdf {
756 args = args + " -hdf " + hdf
757 }
758
759 if String(d.properties.Proofread_file) != "" {
760 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
761 args = args + " -proofread " + proofreadFile.String()
762 }
763
764 if String(d.properties.Todo_file) != "" {
765 // tricky part:
766 // we should not compute full path for todo_file through PathForModuleOut().
767 // the non-standard doclet will get the full path relative to "-o".
768 args = args + " -todo " + String(d.properties.Todo_file)
769 }
770
771 if String(d.properties.Resourcesdir) != "" {
772 // TODO: should we add files under resourcesDir to the implicits? It seems that
773 // resourcesDir is one sub dir of htmlDir
774 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
775 args = args + " -resourcesdir " + resourcesDir.String()
776 }
777
778 if String(d.properties.Resourcesoutdir) != "" {
779 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
780 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
781 }
Dan Willemsencc090972018-02-26 14:33:31 -0800782 }
783
Nan Zhang79614d12018-04-19 18:03:39 -0700784 var docArgsForMetalava string
785 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
786 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800787 }
788
Nan Zhang28c68b92018-03-13 16:17:01 -0700789 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700790
791 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
792 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700793 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700794 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700795 implicitOutputs = append(implicitOutputs, d.apiFile)
796 }
797
Nan Zhang61819ce2018-05-04 18:49:16 -0700798 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
799 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
800 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700801 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700802 implicitOutputs = append(implicitOutputs, d.removedApiFile)
803 }
804
Nan Zhang28c68b92018-03-13 16:17:01 -0700805 if String(d.properties.Private_api_filename) != "" {
806 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
807 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700808 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700809 implicitOutputs = append(implicitOutputs, d.privateApiFile)
810 }
811
David Brazdilfbe4cc32018-05-31 13:56:46 +0100812 if String(d.properties.Dex_api_filename) != "" {
813 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
814 args = args + " -dexApi " + d.dexApiFile.String()
815 implicitOutputs = append(implicitOutputs, d.dexApiFile)
816 }
817
Nan Zhang28c68b92018-03-13 16:17:01 -0700818 if String(d.properties.Private_dex_api_filename) != "" {
819 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
820 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700821 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700822 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
823 }
824
David Brazdilaac0c3c2018-04-24 16:23:29 +0100825 if String(d.properties.Removed_dex_api_filename) != "" {
826 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
827 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700828 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100829 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
830 }
831
Nan Zhang28c68b92018-03-13 16:17:01 -0700832 if String(d.properties.Exact_api_filename) != "" {
833 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
834 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700835 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700836 implicitOutputs = append(implicitOutputs, d.exactApiFile)
837 }
838
Mathew Inwood76c3de12018-06-22 15:28:11 +0100839 if String(d.properties.Dex_mapping_filename) != "" {
840 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
841 args = args + " -apiMapping " + d.apiMappingFile.String()
842 // Omitted: metalava support
843 implicitOutputs = append(implicitOutputs, d.apiMappingFile)
844 }
845
Nan Zhang581fd212018-01-10 16:06:12 -0800846 implicits = append(implicits, d.Javadoc.srcJars...)
847
Nan Zhang79614d12018-04-19 18:03:39 -0700848 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
849 for _, o := range d.properties.Out {
850 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
851 }
852
Nan Zhang30963742018-04-23 09:59:14 -0700853 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
854 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700855
Nan Zhang46130972018-06-04 11:28:01 -0700856 var date string
857 if runtime.GOOS == "darwin" {
858 date = `date -r`
859 } else {
860 date = `date -d`
861 }
862
Nan Zhang357466b2018-04-17 17:38:36 -0700863 doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700864 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800865 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800866 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700867 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700868
Nan Zhang79614d12018-04-19 18:03:39 -0700869 if !Bool(d.properties.Metalava_enabled) {
870 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800871
Nan Zhang79614d12018-04-19 18:03:39 -0700872 implicits = append(implicits, jsilver)
873 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800874
Nan Zhang79614d12018-04-19 18:03:39 -0700875 if BoolDefault(d.properties.Create_stubs, true) {
876 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
877 }
878
879 ctx.Build(pctx, android.BuildParams{
880 Rule: javadoc,
881 Description: "Droiddoc",
882 Output: d.Javadoc.stubsSrcJar,
883 Inputs: d.Javadoc.srcFiles,
884 Implicits: implicits,
885 ImplicitOutputs: implicitOutputs,
886 Args: map[string]string{
887 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
888 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
889 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
890 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
891 "opts": opts,
892 "bootclasspathArgs": bootClasspathArgs,
893 "classpathArgs": classpathArgs,
894 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
895 "docZip": d.Javadoc.docZip.String(),
896 },
897 })
898 } else {
899 opts := metalavaArgs
900
901 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800902 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
903 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
904 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
905 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700906 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800907 "bootclasspathArgs": bootClasspathArgs,
908 "classpathArgs": classpathArgs,
909 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
910 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700911 }
912
913 var previousApi android.Path
914 if String(d.properties.Metalava_previous_api) != "" {
915 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
916 "metalava_previous_api")
Nan Zhang16c0a312018-06-13 17:42:48 -0700917 opts += " --previous-api " + previousApi.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700918 implicits = append(implicits, previousApi)
919 }
920
921 if Bool(d.properties.Metalava_annotations_enabled) {
922 if String(d.properties.Metalava_previous_api) == "" {
923 ctx.PropertyErrorf("metalava_previous_api",
924 "has to be non-empty if annotations was enabled!")
925 }
926 opts += " --include-annotations --migrate-nullness"
927
928 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
929 implicitOutputs = append(implicitOutputs, annotationsZip)
930
931 if String(d.properties.Metalava_merge_annotations_dir) == "" {
932 ctx.PropertyErrorf("metalava_merge_annotations",
933 "has to be non-empty if annotations was enabled!")
934 }
935
Nan Zhang16c0a312018-06-13 17:42:48 -0700936 mergeAnnotationsDir := android.PathForSource(ctx, String(d.properties.Metalava_merge_annotations_dir))
Nan Zhang79614d12018-04-19 18:03:39 -0700937
938 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
939 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Nan Zhang16c0a312018-06-13 17:42:48 -0700940 opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhang79614d12018-04-19 18:03:39 -0700941 }
942
943 if genDocsForMetalava {
Nan Zhang16c0a312018-06-13 17:42:48 -0700944 opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
945 " --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
946 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
Nan Zhang79614d12018-04-19 18:03:39 -0700947 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhang16c0a312018-06-13 17:42:48 -0700948 android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
Nan Zhang79614d12018-04-19 18:03:39 -0700949 implicits = append(implicits, jsilver)
950 implicits = append(implicits, doclava)
951 }
952
953 buildArgs["opts"] = opts
954 ctx.Build(pctx, android.BuildParams{
955 Rule: metalava,
956 Description: "Metalava",
957 Output: d.Javadoc.stubsSrcJar,
958 Inputs: d.Javadoc.srcFiles,
959 Implicits: implicits,
960 ImplicitOutputs: implicitOutputs,
961 Args: buildArgs,
962 })
963 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700964
965 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
966
967 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
968
969 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
970 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
971
972 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
973 "check_api.current.api_file")
974 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
975 "check_api.current_removed_api_file")
976
977 ctx.Build(pctx, android.BuildParams{
978 Rule: apiCheck,
979 Description: "Current API check",
980 Output: d.checkCurrentApiTimestamp,
981 Inputs: nil,
982 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
983 checkApiClasspath...),
984 Args: map[string]string{
985 "classpath": checkApiClasspath.FormJavaClassPath(""),
986 "opts": String(d.properties.Check_api.Current.Args),
987 "apiFile": apiFile.String(),
988 "apiFileToCheck": d.apiFile.String(),
989 "removedApiFile": removedApiFile.String(),
990 "removedApiFileToCheck": d.removedApiFile.String(),
991 "msg": fmt.Sprintf(`\n******************************\n`+
992 `You have tried to change the API from what has been previously approved.\n\n`+
993 `To make these errors go away, you have two choices:\n`+
994 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
995 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900996 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700997 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900998 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700999 ` you will need approval.\n`+
1000 `******************************\n`, ctx.ModuleName()),
1001 },
1002 })
1003
1004 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1005
1006 ctx.Build(pctx, android.BuildParams{
1007 Rule: updateApi,
1008 Description: "update current API",
1009 Output: d.updateCurrentApiTimestamp,
1010 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1011 Args: map[string]string{
1012 "apiFile": apiFile.String(),
1013 "apiFileToCheck": d.apiFile.String(),
1014 "removedApiFile": removedApiFile.String(),
1015 "removedApiFileToCheck": d.removedApiFile.String(),
1016 },
1017 })
1018 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001019 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
1020 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1021
1022 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1023 "check_api.last_released.api_file")
1024 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1025 "check_api.last_released.removed_api_file")
1026
1027 ctx.Build(pctx, android.BuildParams{
1028 Rule: apiCheck,
1029 Description: "Last Released API check",
1030 Output: d.checkLastReleasedApiTimestamp,
1031 Inputs: nil,
1032 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1033 checkApiClasspath...),
1034 Args: map[string]string{
1035 "classpath": checkApiClasspath.FormJavaClassPath(""),
1036 "opts": String(d.properties.Check_api.Last_released.Args),
1037 "apiFile": apiFile.String(),
1038 "apiFileToCheck": d.apiFile.String(),
1039 "removedApiFile": removedApiFile.String(),
1040 "removedApiFileToCheck": d.removedApiFile.String(),
1041 "msg": `\n******************************\n` +
1042 `You have tried to change the API from what has been previously released in\n` +
1043 `an SDK. Please fix the errors listed above.\n` +
1044 `******************************\n`,
1045 },
1046 })
1047 }
Nan Zhang581fd212018-01-10 16:06:12 -08001048}
Dan Willemsencc090972018-02-26 14:33:31 -08001049
1050var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
1051
1052type DroiddocTemplateProperties struct {
1053 // path to the directory containing the droiddoc templates.
1054 Path *string
1055}
1056
1057type DroiddocTemplate struct {
1058 android.ModuleBase
1059
1060 properties DroiddocTemplateProperties
1061
1062 deps android.Paths
1063 dir android.Path
1064}
1065
1066func DroiddocTemplateFactory() android.Module {
1067 module := &DroiddocTemplate{}
1068 module.AddProperties(&module.properties)
1069 android.InitAndroidModule(module)
1070 return module
1071}
1072
1073func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1074
1075func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1076 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1077 d.dir = path
1078 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1079}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001080
1081//
1082// Defaults
1083//
1084type DocDefaults struct {
1085 android.ModuleBase
1086 android.DefaultsModuleBase
1087}
1088
1089func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1090}
1091
1092func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1093}
1094
1095func DocDefaultsFactory() android.Module {
1096 module := &DocDefaults{}
1097
1098 module.AddProperties(
1099 &JavadocProperties{},
1100 &DroiddocProperties{},
1101 )
1102
1103 android.InitDefaultsModule(module)
1104
1105 return module
1106}