blob: dbceed86e2bdd55761bf6252d9eb848fc9c24c92 [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
Nan Zhang28c68b92018-03-13 16:17:01 -0700229 // the generated exact API filename by Doclava.
230 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700231
232 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
233 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700234
235 Check_api struct {
236 Last_released ApiToCheck
237
238 Current ApiToCheck
239 }
Nan Zhang79614d12018-04-19 18:03:39 -0700240
241 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
242 // currently still used for documentation generation, and will be replaced by Dokka soon.
243 Metalava_enabled *bool
244
245 // user can specify the version of previous released API file in order to do compatibility check.
246 Metalava_previous_api *string
247
248 // is set to true, Metalava will allow framework SDK to contain annotations.
249 Metalava_annotations_enabled *bool
250
Nan Zhang16c0a312018-06-13 17:42:48 -0700251 // a top level directory contains XML files set to merge annotations.
Nan Zhang79614d12018-04-19 18:03:39 -0700252 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800253}
254
255type Javadoc struct {
256 android.ModuleBase
257 android.DefaultableModuleBase
258
259 properties JavadocProperties
260
261 srcJars android.Paths
262 srcFiles android.Paths
263 sourcepaths android.Paths
264
Nan Zhangccff0f72018-03-08 17:26:16 -0800265 docZip android.WritablePath
266 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800267}
268
Nan Zhangb2b33de2018-02-23 11:18:47 -0800269func (j *Javadoc) Srcs() android.Paths {
270 return android.Paths{j.stubsSrcJar}
271}
272
273var _ android.SourceFileProducer = (*Javadoc)(nil)
274
Nan Zhang581fd212018-01-10 16:06:12 -0800275type Droiddoc struct {
276 Javadoc
277
Nan Zhang28c68b92018-03-13 16:17:01 -0700278 properties DroiddocProperties
279 apiFile android.WritablePath
David Brazdilfbe4cc32018-05-31 13:56:46 +0100280 dexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700281 privateApiFile android.WritablePath
282 privateDexApiFile android.WritablePath
283 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100284 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700285 exactApiFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700286
287 checkCurrentApiTimestamp android.WritablePath
288 updateCurrentApiTimestamp android.WritablePath
289 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800290}
291
292func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
293 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
294 android.InitDefaultableModule(module)
295}
296
297func JavadocFactory() android.Module {
298 module := &Javadoc{}
299
300 module.AddProperties(&module.properties)
301
302 InitDroiddocModule(module, android.HostAndDeviceSupported)
303 return module
304}
305
306func JavadocHostFactory() android.Module {
307 module := &Javadoc{}
308
309 module.AddProperties(&module.properties)
310
311 InitDroiddocModule(module, android.HostSupported)
312 return module
313}
314
315func DroiddocFactory() android.Module {
316 module := &Droiddoc{}
317
318 module.AddProperties(&module.properties,
319 &module.Javadoc.properties)
320
321 InitDroiddocModule(module, android.HostAndDeviceSupported)
322 return module
323}
324
325func DroiddocHostFactory() android.Module {
326 module := &Droiddoc{}
327
328 module.AddProperties(&module.properties,
329 &module.Javadoc.properties)
330
331 InitDroiddocModule(module, android.HostSupported)
332 return module
333}
334
Colin Cross83bb3162018-06-25 15:48:06 -0700335func (j *Javadoc) sdkVersion() string {
336 return String(j.properties.Sdk_version)
337}
338
339func (j *Javadoc) minSdkVersion() string {
340 return j.sdkVersion()
341}
342
Nan Zhang581fd212018-01-10 16:06:12 -0800343func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
344 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700345 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800346 if sdkDep.useDefaultLibs {
347 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700348 if ctx.Config().TargetOpenJDK9() {
349 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
350 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700351 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800352 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
353 }
Nan Zhang581fd212018-01-10 16:06:12 -0800354 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700355 if ctx.Config().TargetOpenJDK9() {
356 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
357 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700358 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800359 }
360 }
361
362 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700363 if j.properties.Srcs_lib != nil {
364 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
365 }
Nan Zhang581fd212018-01-10 16:06:12 -0800366
367 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
368
369 // exclude_srcs may contain filegroup or genrule.
370 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
371}
372
Nan Zhangb2b33de2018-02-23 11:18:47 -0800373func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
374 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
375 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900376 // convert foo.bar.baz to foo/bar/baz
377 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
378 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800379 if _, found := whitelistPathPrefixes[prefix]; !found {
380 whitelistPathPrefixes[prefix] = true
381 }
382 }
383 }
384}
385
Jiyong Park1e440682018-05-23 18:42:04 +0900386func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
387 var flags javaBuilderFlags
388
389 // aidl flags.
390 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
391 if len(aidlFlags) > 0 {
392 // optimization.
393 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
394 flags.aidlFlags = "$aidlFlags"
395 }
396
397 return flags
398}
399
400func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
401 aidlIncludeDirs android.Paths) []string {
402
403 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
404 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
405
406 var flags []string
407 if aidlPreprocess.Valid() {
408 flags = append(flags, "-p"+aidlPreprocess.String())
409 } else {
410 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
411 }
412
413 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
414 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
415 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
416 flags = append(flags, "-I"+src.String())
417 }
418
419 return flags
420}
421
422func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
423 flags javaBuilderFlags) android.Paths {
424
425 outSrcFiles := make(android.Paths, 0, len(srcFiles))
426
427 for _, srcFile := range srcFiles {
428 switch srcFile.Ext() {
429 case ".aidl":
430 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
431 outSrcFiles = append(outSrcFiles, javaFile)
432 default:
433 outSrcFiles = append(outSrcFiles, srcFile)
434 }
435 }
436
437 return outSrcFiles
438}
439
Nan Zhang581fd212018-01-10 16:06:12 -0800440func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
441 var deps deps
442
Colin Cross83bb3162018-06-25 15:48:06 -0700443 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800444 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700445 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800446 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700447 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800448 }
449
450 ctx.VisitDirectDeps(func(module android.Module) {
451 otherName := ctx.OtherModuleName(module)
452 tag := ctx.OtherModuleDependencyTag(module)
453
Colin Cross2d24c1b2018-05-23 10:59:18 -0700454 switch tag {
455 case bootClasspathTag:
456 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800457 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700458 } else {
459 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
460 }
461 case libTag:
462 switch dep := module.(type) {
463 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800464 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700465 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700466 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900467 linkType := javaSdk
468 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
469 linkType = javaSystem
470 } else if sdkVersion == "" {
471 linkType = javaPlatform
472 }
473 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700474 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800475 checkProducesJars(ctx, dep)
476 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800477 default:
478 ctx.ModuleErrorf("depends on non-java module %q", otherName)
479 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700480 case srcsLibTag:
481 switch dep := module.(type) {
482 case Dependency:
483 srcs := dep.(SrcDependency).CompiledSrcs()
484 whitelistPathPrefixes := make(map[string]bool)
485 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
486 for _, src := range srcs {
487 if _, ok := src.(android.WritablePath); ok { // generated sources
488 deps.srcs = append(deps.srcs, src)
489 } else { // select source path for documentation based on whitelist path prefixs.
490 for k, _ := range whitelistPathPrefixes {
491 if strings.HasPrefix(src.Rel(), k) {
492 deps.srcs = append(deps.srcs, src)
493 break
494 }
495 }
496 }
497 }
498 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
499 default:
500 ctx.ModuleErrorf("depends on non-java module %q", otherName)
501 }
Nan Zhang357466b2018-04-17 17:38:36 -0700502 case systemModulesTag:
503 if deps.systemModules != nil {
504 panic("Found two system module dependencies")
505 }
506 sm := module.(*SystemModules)
507 if sm.outputFile == nil {
508 panic("Missing directory for system module dependency")
509 }
510 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800511 }
512 })
513 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
514 // may contain filegroup or genrule.
515 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900516 flags := j.collectBuilderFlags(ctx, deps)
517 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800518
519 // srcs may depend on some genrule output.
520 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800521 j.srcJars = append(j.srcJars, deps.srcJars...)
522
Nan Zhang581fd212018-01-10 16:06:12 -0800523 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800524 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800525
526 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800527 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800528
529 if j.properties.Local_sourcepaths == nil {
530 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
531 }
532 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800533
534 return deps
535}
536
537func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
538 j.addDeps(ctx)
539}
540
541func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
542 deps := j.collectDeps(ctx)
543
544 var implicits android.Paths
545 implicits = append(implicits, deps.bootClasspath...)
546 implicits = append(implicits, deps.classpath...)
547
548 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700549
Colin Cross83bb3162018-06-25 15:48:06 -0700550 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700551 if len(deps.bootClasspath) > 0 {
552 var systemModules classpath
553 if deps.systemModules != nil {
554 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800555 }
Colin Cross997262f2018-06-19 22:49:39 -0700556 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
557 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800558 }
559 if len(deps.classpath.Strings()) > 0 {
560 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
561 }
562
563 implicits = append(implicits, j.srcJars...)
564
Nan Zhangaf322cc2018-06-19 15:15:38 -0700565 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800566
567 ctx.Build(pctx, android.BuildParams{
568 Rule: javadoc,
569 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800570 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800571 ImplicitOutput: j.docZip,
572 Inputs: j.srcFiles,
573 Implicits: implicits,
574 Args: map[string]string{
575 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
576 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
577 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
578 "srcJars": strings.Join(j.srcJars.Strings(), " "),
579 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700580 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800581 "classpathArgs": classpathArgs,
582 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
583 "docZip": j.docZip.String(),
584 },
585 })
586}
587
Nan Zhang61819ce2018-05-04 18:49:16 -0700588func (d *Droiddoc) checkCurrentApi() bool {
589 if String(d.properties.Check_api.Current.Api_file) != "" &&
590 String(d.properties.Check_api.Current.Removed_api_file) != "" {
591 return true
592 } else if String(d.properties.Check_api.Current.Api_file) != "" {
593 panic("check_api.current.removed_api_file: has to be non empty!")
594 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
595 panic("check_api.current.api_file: has to be non empty!")
596 }
597
598 return false
599}
600
601func (d *Droiddoc) checkLastReleasedApi() bool {
602 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
603 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
604 return true
605 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
606 panic("check_api.last_released.removed_api_file: has to be non empty!")
607 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
608 panic("check_api.last_released.api_file: has to be non empty!")
609 }
610
611 return false
612}
613
Nan Zhang581fd212018-01-10 16:06:12 -0800614func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
615 d.Javadoc.addDeps(ctx)
616
Nan Zhang79614d12018-04-19 18:03:39 -0700617 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800618 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
619 }
620
Nan Zhang581fd212018-01-10 16:06:12 -0800621 // extra_arg_files may contains filegroup or genrule.
622 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
623
624 // knowntags may contain filegroup or genrule.
625 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700626
627 if d.checkCurrentApi() {
628 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
629 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
630 }
631
632 if d.checkLastReleasedApi() {
633 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
634 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
635 }
Nan Zhang79614d12018-04-19 18:03:39 -0700636
637 if String(d.properties.Metalava_previous_api) != "" {
638 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
639 }
Nan Zhang581fd212018-01-10 16:06:12 -0800640}
641
642func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
643 deps := d.Javadoc.collectDeps(ctx)
644
645 var implicits android.Paths
646 implicits = append(implicits, deps.bootClasspath...)
647 implicits = append(implicits, deps.classpath...)
648
Nan Zhang357466b2018-04-17 17:38:36 -0700649 var bootClasspathArgs string
Colin Cross83bb3162018-06-25 15:48:06 -0700650 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang7ca46782018-06-25 13:00:25 -0700651 // Doclava has problem with "-source 1.9", so override javaVersion when Doclava
652 // is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
653 // replaced by Metalava.
654 if !Bool(d.properties.Metalava_enabled) {
655 javaVersion = "1.8"
656 }
Nan Zhangc94f9d82018-06-26 10:02:26 -0700657 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
658 // since it doesn't support system modules yet.
659 if len(deps.bootClasspath.Strings()) > 0 {
660 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
661 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700662 }
Nan Zhang79614d12018-04-19 18:03:39 -0700663 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
664
Nan Zhang581fd212018-01-10 16:06:12 -0800665 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
666 argFilesMap := map[string]android.Path{}
667
668 for _, f := range argFiles {
669 implicits = append(implicits, f)
670 if _, exists := argFilesMap[f.Rel()]; !exists {
671 argFilesMap[f.Rel()] = f
672 } else {
673 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
674 f, argFilesMap[f.Rel()], f.Rel())
675 }
676 }
677
678 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
679 if strings.HasPrefix(name, "location ") {
680 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
681 if f, ok := argFilesMap[label]; ok {
682 return f.String(), nil
683 } else {
684 return "", fmt.Errorf("unknown location label %q", label)
685 }
686 } else if name == "genDir" {
687 return android.PathForModuleGen(ctx).String(), nil
688 }
689 return "", fmt.Errorf("unknown variable '$(%s)'", name)
690 })
691
692 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700693 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800694 return
695 }
696
Nan Zhang79614d12018-04-19 18:03:39 -0700697 genDocsForMetalava := false
698 var metalavaArgs string
699 if Bool(d.properties.Metalava_enabled) {
700 if strings.Contains(args, "--generate-documentation") {
701 if !strings.Contains(args, "-nodocs") {
702 genDocsForMetalava = true
703 }
704 // TODO(nanzhang): Add a Soong property to handle documentation args.
705 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800706 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700707 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800708 }
Nan Zhang581fd212018-01-10 16:06:12 -0800709 }
710
Nan Zhang79614d12018-04-19 18:03:39 -0700711 var templateDir, htmlDirArgs, htmlDir2Args string
712 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
713 if String(d.properties.Custom_template) == "" {
714 // TODO: This is almost always droiddoc-templates-sdk
715 ctx.PropertyErrorf("custom_template", "must specify a template")
716 }
717
718 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
719 if t, ok := m.(*DroiddocTemplate); ok {
720 implicits = append(implicits, t.deps...)
721 templateDir = t.dir.String()
722 } else {
723 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
724 }
725 })
726
727 if len(d.properties.Html_dirs) > 0 {
728 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
729 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
730 htmlDirArgs = "-htmldir " + htmlDir.String()
731 }
732
733 if len(d.properties.Html_dirs) > 1 {
734 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
735 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
736 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
737 }
738
739 if len(d.properties.Html_dirs) > 2 {
740 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
741 }
742
743 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
744 implicits = append(implicits, knownTags...)
745
746 for _, kt := range knownTags {
747 args = args + " -knowntags " + kt.String()
748 }
749
750 for _, hdf := range d.properties.Hdf {
751 args = args + " -hdf " + hdf
752 }
753
754 if String(d.properties.Proofread_file) != "" {
755 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
756 args = args + " -proofread " + proofreadFile.String()
757 }
758
759 if String(d.properties.Todo_file) != "" {
760 // tricky part:
761 // we should not compute full path for todo_file through PathForModuleOut().
762 // the non-standard doclet will get the full path relative to "-o".
763 args = args + " -todo " + String(d.properties.Todo_file)
764 }
765
766 if String(d.properties.Resourcesdir) != "" {
767 // TODO: should we add files under resourcesDir to the implicits? It seems that
768 // resourcesDir is one sub dir of htmlDir
769 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
770 args = args + " -resourcesdir " + resourcesDir.String()
771 }
772
773 if String(d.properties.Resourcesoutdir) != "" {
774 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
775 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
776 }
Dan Willemsencc090972018-02-26 14:33:31 -0800777 }
778
Nan Zhang79614d12018-04-19 18:03:39 -0700779 var docArgsForMetalava string
780 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
781 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800782 }
783
Nan Zhang28c68b92018-03-13 16:17:01 -0700784 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700785
786 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
787 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700788 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700789 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700790 implicitOutputs = append(implicitOutputs, d.apiFile)
791 }
792
Nan Zhang61819ce2018-05-04 18:49:16 -0700793 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
794 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
795 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700796 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700797 implicitOutputs = append(implicitOutputs, d.removedApiFile)
798 }
799
Nan Zhang28c68b92018-03-13 16:17:01 -0700800 if String(d.properties.Private_api_filename) != "" {
801 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
802 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700803 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700804 implicitOutputs = append(implicitOutputs, d.privateApiFile)
805 }
806
David Brazdilfbe4cc32018-05-31 13:56:46 +0100807 if String(d.properties.Dex_api_filename) != "" {
808 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
809 args = args + " -dexApi " + d.dexApiFile.String()
810 implicitOutputs = append(implicitOutputs, d.dexApiFile)
811 }
812
Nan Zhang28c68b92018-03-13 16:17:01 -0700813 if String(d.properties.Private_dex_api_filename) != "" {
814 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
815 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700816 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700817 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
818 }
819
David Brazdilaac0c3c2018-04-24 16:23:29 +0100820 if String(d.properties.Removed_dex_api_filename) != "" {
821 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
822 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700823 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100824 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
825 }
826
Nan Zhang28c68b92018-03-13 16:17:01 -0700827 if String(d.properties.Exact_api_filename) != "" {
828 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
829 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700830 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700831 implicitOutputs = append(implicitOutputs, d.exactApiFile)
832 }
833
Nan Zhang581fd212018-01-10 16:06:12 -0800834 implicits = append(implicits, d.Javadoc.srcJars...)
835
Nan Zhang79614d12018-04-19 18:03:39 -0700836 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
837 for _, o := range d.properties.Out {
838 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
839 }
840
Nan Zhang30963742018-04-23 09:59:14 -0700841 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
842 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700843
Nan Zhang46130972018-06-04 11:28:01 -0700844 var date string
845 if runtime.GOOS == "darwin" {
846 date = `date -r`
847 } else {
848 date = `date -d`
849 }
850
Nan Zhang357466b2018-04-17 17:38:36 -0700851 doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700852 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800853 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800854 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700855 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700856
Nan Zhang79614d12018-04-19 18:03:39 -0700857 if !Bool(d.properties.Metalava_enabled) {
858 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800859
Nan Zhang79614d12018-04-19 18:03:39 -0700860 implicits = append(implicits, jsilver)
861 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800862
Nan Zhang79614d12018-04-19 18:03:39 -0700863 if BoolDefault(d.properties.Create_stubs, true) {
864 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
865 }
866
867 ctx.Build(pctx, android.BuildParams{
868 Rule: javadoc,
869 Description: "Droiddoc",
870 Output: d.Javadoc.stubsSrcJar,
871 Inputs: d.Javadoc.srcFiles,
872 Implicits: implicits,
873 ImplicitOutputs: implicitOutputs,
874 Args: map[string]string{
875 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
876 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
877 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
878 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
879 "opts": opts,
880 "bootclasspathArgs": bootClasspathArgs,
881 "classpathArgs": classpathArgs,
882 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
883 "docZip": d.Javadoc.docZip.String(),
884 },
885 })
886 } else {
887 opts := metalavaArgs
888
889 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800890 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
891 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
892 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
893 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700894 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800895 "bootclasspathArgs": bootClasspathArgs,
896 "classpathArgs": classpathArgs,
897 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
898 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700899 }
900
901 var previousApi android.Path
902 if String(d.properties.Metalava_previous_api) != "" {
903 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
904 "metalava_previous_api")
Nan Zhang16c0a312018-06-13 17:42:48 -0700905 opts += " --previous-api " + previousApi.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700906 implicits = append(implicits, previousApi)
907 }
908
909 if Bool(d.properties.Metalava_annotations_enabled) {
910 if String(d.properties.Metalava_previous_api) == "" {
911 ctx.PropertyErrorf("metalava_previous_api",
912 "has to be non-empty if annotations was enabled!")
913 }
914 opts += " --include-annotations --migrate-nullness"
915
916 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
917 implicitOutputs = append(implicitOutputs, annotationsZip)
918
919 if String(d.properties.Metalava_merge_annotations_dir) == "" {
920 ctx.PropertyErrorf("metalava_merge_annotations",
921 "has to be non-empty if annotations was enabled!")
922 }
923
Nan Zhang16c0a312018-06-13 17:42:48 -0700924 mergeAnnotationsDir := android.PathForSource(ctx, String(d.properties.Metalava_merge_annotations_dir))
Nan Zhang79614d12018-04-19 18:03:39 -0700925
926 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
927 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Nan Zhang16c0a312018-06-13 17:42:48 -0700928 opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhang79614d12018-04-19 18:03:39 -0700929 }
930
931 if genDocsForMetalava {
Nan Zhang16c0a312018-06-13 17:42:48 -0700932 opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
933 " --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
934 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
Nan Zhang79614d12018-04-19 18:03:39 -0700935 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhang16c0a312018-06-13 17:42:48 -0700936 android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
Nan Zhang79614d12018-04-19 18:03:39 -0700937 implicits = append(implicits, jsilver)
938 implicits = append(implicits, doclava)
939 }
940
941 buildArgs["opts"] = opts
942 ctx.Build(pctx, android.BuildParams{
943 Rule: metalava,
944 Description: "Metalava",
945 Output: d.Javadoc.stubsSrcJar,
946 Inputs: d.Javadoc.srcFiles,
947 Implicits: implicits,
948 ImplicitOutputs: implicitOutputs,
949 Args: buildArgs,
950 })
951 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700952
953 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
954
955 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
956
957 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
958 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
959
960 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
961 "check_api.current.api_file")
962 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
963 "check_api.current_removed_api_file")
964
965 ctx.Build(pctx, android.BuildParams{
966 Rule: apiCheck,
967 Description: "Current API check",
968 Output: d.checkCurrentApiTimestamp,
969 Inputs: nil,
970 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
971 checkApiClasspath...),
972 Args: map[string]string{
973 "classpath": checkApiClasspath.FormJavaClassPath(""),
974 "opts": String(d.properties.Check_api.Current.Args),
975 "apiFile": apiFile.String(),
976 "apiFileToCheck": d.apiFile.String(),
977 "removedApiFile": removedApiFile.String(),
978 "removedApiFileToCheck": d.removedApiFile.String(),
979 "msg": fmt.Sprintf(`\n******************************\n`+
980 `You have tried to change the API from what has been previously approved.\n\n`+
981 `To make these errors go away, you have two choices:\n`+
982 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
983 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900984 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700985 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900986 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700987 ` you will need approval.\n`+
988 `******************************\n`, ctx.ModuleName()),
989 },
990 })
991
992 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
993
994 ctx.Build(pctx, android.BuildParams{
995 Rule: updateApi,
996 Description: "update current API",
997 Output: d.updateCurrentApiTimestamp,
998 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
999 Args: map[string]string{
1000 "apiFile": apiFile.String(),
1001 "apiFileToCheck": d.apiFile.String(),
1002 "removedApiFile": removedApiFile.String(),
1003 "removedApiFileToCheck": d.removedApiFile.String(),
1004 },
1005 })
1006 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001007 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
1008 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1009
1010 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1011 "check_api.last_released.api_file")
1012 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1013 "check_api.last_released.removed_api_file")
1014
1015 ctx.Build(pctx, android.BuildParams{
1016 Rule: apiCheck,
1017 Description: "Last Released API check",
1018 Output: d.checkLastReleasedApiTimestamp,
1019 Inputs: nil,
1020 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1021 checkApiClasspath...),
1022 Args: map[string]string{
1023 "classpath": checkApiClasspath.FormJavaClassPath(""),
1024 "opts": String(d.properties.Check_api.Last_released.Args),
1025 "apiFile": apiFile.String(),
1026 "apiFileToCheck": d.apiFile.String(),
1027 "removedApiFile": removedApiFile.String(),
1028 "removedApiFileToCheck": d.removedApiFile.String(),
1029 "msg": `\n******************************\n` +
1030 `You have tried to change the API from what has been previously released in\n` +
1031 `an SDK. Please fix the errors listed above.\n` +
1032 `******************************\n`,
1033 },
1034 })
1035 }
Nan Zhang581fd212018-01-10 16:06:12 -08001036}
Dan Willemsencc090972018-02-26 14:33:31 -08001037
1038var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
1039
1040type DroiddocTemplateProperties struct {
1041 // path to the directory containing the droiddoc templates.
1042 Path *string
1043}
1044
1045type DroiddocTemplate struct {
1046 android.ModuleBase
1047
1048 properties DroiddocTemplateProperties
1049
1050 deps android.Paths
1051 dir android.Path
1052}
1053
1054func DroiddocTemplateFactory() android.Module {
1055 module := &DroiddocTemplate{}
1056 module.AddProperties(&module.properties)
1057 android.InitAndroidModule(module)
1058 return module
1059}
1060
1061func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1062
1063func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1064 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1065 d.dir = path
1066 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1067}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001068
1069//
1070// Defaults
1071//
1072type DocDefaults struct {
1073 android.ModuleBase
1074 android.DefaultsModuleBase
1075}
1076
1077func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1078}
1079
1080func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1081}
1082
1083func DocDefaultsFactory() android.Module {
1084 module := &DocDefaults{}
1085
1086 module.AddProperties(
1087 &JavadocProperties{},
1088 &DroiddocProperties{},
1089 )
1090
1091 android.InitDefaultsModule(module)
1092
1093 return module
1094}