blob: 1d0b3c359c5965db3dfc01d7ca638b796d9327e1 [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 && ` +
Nan Zhange2ba5d42018-07-11 15:16:55 -070037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`,
Nan Zhang581fd212018-01-10 16:06:12 -080038 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 Zhange2ba5d42018-07-11 15:16:55 -070048 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "postDoclavaCmds")
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
Nan Zhange2ba5d42018-07-11 15:16:55 -0700204 // if set to true, collect the values used by the Dev tools and
205 // write them in files packaged with the SDK. Defaults to false.
206 Write_sdk_values *bool
207
208 // index.html under current module will be copied to docs out dir, if not null.
209 Static_doc_index_redirect *string
210
211 // source.properties under current module will be copied to docs out dir, if not null.
212 Static_doc_properties *string
213
Nan Zhang581fd212018-01-10 16:06:12 -0800214 // a list of files under current module source dir which contains known tags in Java sources.
215 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800216 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700217
218 // the tag name used to distinguish if the API files belong to public/system/test.
219 Api_tag_name *string
220
221 // the generated public API filename by Doclava.
222 Api_filename *string
223
David Brazdilfbe4cc32018-05-31 13:56:46 +0100224 // the generated public Dex API filename by Doclava.
225 Dex_api_filename *string
226
Nan Zhang28c68b92018-03-13 16:17:01 -0700227 // the generated private API filename by Doclava.
228 Private_api_filename *string
229
230 // the generated private Dex API filename by Doclava.
231 Private_dex_api_filename *string
232
233 // the generated removed API filename by Doclava.
234 Removed_api_filename *string
235
David Brazdilaac0c3c2018-04-24 16:23:29 +0100236 // the generated removed Dex API filename by Doclava.
237 Removed_dex_api_filename *string
238
Mathew Inwood76c3de12018-06-22 15:28:11 +0100239 // mapping of dex signatures to source file and line number. This is a temporary property and
240 // will be deleted; you probably shouldn't be using it.
241 Dex_mapping_filename *string
242
Nan Zhang28c68b92018-03-13 16:17:01 -0700243 // the generated exact API filename by Doclava.
244 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700245
246 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
247 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700248
249 Check_api struct {
250 Last_released ApiToCheck
251
252 Current ApiToCheck
253 }
Nan Zhang79614d12018-04-19 18:03:39 -0700254
255 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
256 // currently still used for documentation generation, and will be replaced by Dokka soon.
257 Metalava_enabled *bool
258
259 // user can specify the version of previous released API file in order to do compatibility check.
260 Metalava_previous_api *string
261
262 // is set to true, Metalava will allow framework SDK to contain annotations.
263 Metalava_annotations_enabled *bool
264
Pete Gillinb13a0152018-07-19 17:56:49 +0100265 // a list of top-level directories containing files to merge annotations from.
266 Metalava_merge_annotations_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800267}
268
269type Javadoc struct {
270 android.ModuleBase
271 android.DefaultableModuleBase
272
273 properties JavadocProperties
274
275 srcJars android.Paths
276 srcFiles android.Paths
277 sourcepaths android.Paths
278
Nan Zhangccff0f72018-03-08 17:26:16 -0800279 docZip android.WritablePath
280 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800281}
282
Nan Zhangb2b33de2018-02-23 11:18:47 -0800283func (j *Javadoc) Srcs() android.Paths {
284 return android.Paths{j.stubsSrcJar}
285}
286
287var _ android.SourceFileProducer = (*Javadoc)(nil)
288
Nan Zhang581fd212018-01-10 16:06:12 -0800289type Droiddoc struct {
290 Javadoc
291
Nan Zhang28c68b92018-03-13 16:17:01 -0700292 properties DroiddocProperties
293 apiFile android.WritablePath
David Brazdilfbe4cc32018-05-31 13:56:46 +0100294 dexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700295 privateApiFile android.WritablePath
296 privateDexApiFile android.WritablePath
297 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100298 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700299 exactApiFile android.WritablePath
Mathew Inwood76c3de12018-06-22 15:28:11 +0100300 apiMappingFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700301
302 checkCurrentApiTimestamp android.WritablePath
303 updateCurrentApiTimestamp android.WritablePath
304 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang03b733c2018-06-26 13:24:05 -0700305
306 annotationsZip android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800307}
308
309func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
310 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
311 android.InitDefaultableModule(module)
312}
313
314func JavadocFactory() android.Module {
315 module := &Javadoc{}
316
317 module.AddProperties(&module.properties)
318
319 InitDroiddocModule(module, android.HostAndDeviceSupported)
320 return module
321}
322
323func JavadocHostFactory() android.Module {
324 module := &Javadoc{}
325
326 module.AddProperties(&module.properties)
327
328 InitDroiddocModule(module, android.HostSupported)
329 return module
330}
331
332func DroiddocFactory() android.Module {
333 module := &Droiddoc{}
334
335 module.AddProperties(&module.properties,
336 &module.Javadoc.properties)
337
338 InitDroiddocModule(module, android.HostAndDeviceSupported)
339 return module
340}
341
342func DroiddocHostFactory() android.Module {
343 module := &Droiddoc{}
344
345 module.AddProperties(&module.properties,
346 &module.Javadoc.properties)
347
348 InitDroiddocModule(module, android.HostSupported)
349 return module
350}
351
Colin Cross83bb3162018-06-25 15:48:06 -0700352func (j *Javadoc) sdkVersion() string {
353 return String(j.properties.Sdk_version)
354}
355
356func (j *Javadoc) minSdkVersion() string {
357 return j.sdkVersion()
358}
359
Nan Zhang581fd212018-01-10 16:06:12 -0800360func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
361 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700362 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800363 if sdkDep.useDefaultLibs {
364 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700365 if ctx.Config().TargetOpenJDK9() {
366 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
367 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700368 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800369 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
370 }
Nan Zhang581fd212018-01-10 16:06:12 -0800371 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700372 if ctx.Config().TargetOpenJDK9() {
373 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
374 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700375 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800376 }
377 }
378
379 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700380 if j.properties.Srcs_lib != nil {
381 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
382 }
Nan Zhang581fd212018-01-10 16:06:12 -0800383
384 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
385
386 // exclude_srcs may contain filegroup or genrule.
387 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
388}
389
Nan Zhangb2b33de2018-02-23 11:18:47 -0800390func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
391 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
392 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900393 // convert foo.bar.baz to foo/bar/baz
394 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
395 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800396 if _, found := whitelistPathPrefixes[prefix]; !found {
397 whitelistPathPrefixes[prefix] = true
398 }
399 }
400 }
401}
402
Jiyong Park1e440682018-05-23 18:42:04 +0900403func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
404 var flags javaBuilderFlags
405
406 // aidl flags.
407 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
408 if len(aidlFlags) > 0 {
409 // optimization.
410 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
411 flags.aidlFlags = "$aidlFlags"
412 }
413
414 return flags
415}
416
417func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
418 aidlIncludeDirs android.Paths) []string {
419
420 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
421 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
422
423 var flags []string
424 if aidlPreprocess.Valid() {
425 flags = append(flags, "-p"+aidlPreprocess.String())
426 } else {
427 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
428 }
429
430 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
431 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
432 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
433 flags = append(flags, "-I"+src.String())
434 }
435
436 return flags
437}
438
439func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
440 flags javaBuilderFlags) android.Paths {
441
442 outSrcFiles := make(android.Paths, 0, len(srcFiles))
443
444 for _, srcFile := range srcFiles {
445 switch srcFile.Ext() {
446 case ".aidl":
447 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
448 outSrcFiles = append(outSrcFiles, javaFile)
449 default:
450 outSrcFiles = append(outSrcFiles, srcFile)
451 }
452 }
453
454 return outSrcFiles
455}
456
Nan Zhang581fd212018-01-10 16:06:12 -0800457func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
458 var deps deps
459
Colin Cross83bb3162018-06-25 15:48:06 -0700460 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800461 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700462 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800463 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700464 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800465 }
466
467 ctx.VisitDirectDeps(func(module android.Module) {
468 otherName := ctx.OtherModuleName(module)
469 tag := ctx.OtherModuleDependencyTag(module)
470
Colin Cross2d24c1b2018-05-23 10:59:18 -0700471 switch tag {
472 case bootClasspathTag:
473 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800474 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700475 } else {
476 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
477 }
478 case libTag:
479 switch dep := module.(type) {
480 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800481 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700482 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700483 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900484 linkType := javaSdk
485 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
486 linkType = javaSystem
487 } else if sdkVersion == "" {
488 linkType = javaPlatform
489 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900490 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700491 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800492 checkProducesJars(ctx, dep)
493 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800494 default:
495 ctx.ModuleErrorf("depends on non-java module %q", otherName)
496 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700497 case srcsLibTag:
498 switch dep := module.(type) {
499 case Dependency:
500 srcs := dep.(SrcDependency).CompiledSrcs()
501 whitelistPathPrefixes := make(map[string]bool)
502 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
503 for _, src := range srcs {
504 if _, ok := src.(android.WritablePath); ok { // generated sources
505 deps.srcs = append(deps.srcs, src)
506 } else { // select source path for documentation based on whitelist path prefixs.
507 for k, _ := range whitelistPathPrefixes {
508 if strings.HasPrefix(src.Rel(), k) {
509 deps.srcs = append(deps.srcs, src)
510 break
511 }
512 }
513 }
514 }
515 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
516 default:
517 ctx.ModuleErrorf("depends on non-java module %q", otherName)
518 }
Nan Zhang357466b2018-04-17 17:38:36 -0700519 case systemModulesTag:
520 if deps.systemModules != nil {
521 panic("Found two system module dependencies")
522 }
523 sm := module.(*SystemModules)
524 if sm.outputFile == nil {
525 panic("Missing directory for system module dependency")
526 }
527 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800528 }
529 })
530 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
531 // may contain filegroup or genrule.
532 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900533 flags := j.collectBuilderFlags(ctx, deps)
534 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800535
536 // srcs may depend on some genrule output.
537 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800538 j.srcJars = append(j.srcJars, deps.srcJars...)
539
Nan Zhang581fd212018-01-10 16:06:12 -0800540 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800541 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800542
543 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800544 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800545
546 if j.properties.Local_sourcepaths == nil {
547 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
548 }
549 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800550
551 return deps
552}
553
554func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
555 j.addDeps(ctx)
556}
557
558func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
559 deps := j.collectDeps(ctx)
560
561 var implicits android.Paths
562 implicits = append(implicits, deps.bootClasspath...)
563 implicits = append(implicits, deps.classpath...)
564
565 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700566
Colin Cross83bb3162018-06-25 15:48:06 -0700567 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700568 if len(deps.bootClasspath) > 0 {
569 var systemModules classpath
570 if deps.systemModules != nil {
571 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800572 }
Colin Cross997262f2018-06-19 22:49:39 -0700573 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
574 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800575 }
576 if len(deps.classpath.Strings()) > 0 {
577 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
578 }
579
580 implicits = append(implicits, j.srcJars...)
581
Nan Zhangaf322cc2018-06-19 15:15:38 -0700582 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800583
584 ctx.Build(pctx, android.BuildParams{
585 Rule: javadoc,
586 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800587 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800588 ImplicitOutput: j.docZip,
589 Inputs: j.srcFiles,
590 Implicits: implicits,
591 Args: map[string]string{
592 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
593 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
594 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
595 "srcJars": strings.Join(j.srcJars.Strings(), " "),
596 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700597 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800598 "classpathArgs": classpathArgs,
599 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
600 "docZip": j.docZip.String(),
601 },
602 })
603}
604
Nan Zhang61819ce2018-05-04 18:49:16 -0700605func (d *Droiddoc) checkCurrentApi() bool {
606 if String(d.properties.Check_api.Current.Api_file) != "" &&
607 String(d.properties.Check_api.Current.Removed_api_file) != "" {
608 return true
609 } else if String(d.properties.Check_api.Current.Api_file) != "" {
610 panic("check_api.current.removed_api_file: has to be non empty!")
611 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
612 panic("check_api.current.api_file: has to be non empty!")
613 }
614
615 return false
616}
617
618func (d *Droiddoc) checkLastReleasedApi() bool {
619 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
620 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
621 return true
622 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
623 panic("check_api.last_released.removed_api_file: has to be non empty!")
624 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
625 panic("check_api.last_released.api_file: has to be non empty!")
626 }
627
628 return false
629}
630
Nan Zhang581fd212018-01-10 16:06:12 -0800631func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
632 d.Javadoc.addDeps(ctx)
633
Nan Zhang79614d12018-04-19 18:03:39 -0700634 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800635 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
636 }
637
Nan Zhang581fd212018-01-10 16:06:12 -0800638 // extra_arg_files may contains filegroup or genrule.
639 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
640
641 // knowntags may contain filegroup or genrule.
642 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700643
Nan Zhange2ba5d42018-07-11 15:16:55 -0700644 if String(d.properties.Static_doc_index_redirect) != "" {
645 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
646 }
647
648 if String(d.properties.Static_doc_properties) != "" {
649 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
650 }
651
Nan Zhang61819ce2018-05-04 18:49:16 -0700652 if d.checkCurrentApi() {
653 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
654 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
655 }
656
657 if d.checkLastReleasedApi() {
658 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
659 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
660 }
Nan Zhang79614d12018-04-19 18:03:39 -0700661
662 if String(d.properties.Metalava_previous_api) != "" {
663 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
664 }
Nan Zhang581fd212018-01-10 16:06:12 -0800665}
666
667func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
668 deps := d.Javadoc.collectDeps(ctx)
669
670 var implicits android.Paths
671 implicits = append(implicits, deps.bootClasspath...)
672 implicits = append(implicits, deps.classpath...)
673
Nan Zhang357466b2018-04-17 17:38:36 -0700674 var bootClasspathArgs string
Colin Cross83bb3162018-06-25 15:48:06 -0700675 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang7ca46782018-06-25 13:00:25 -0700676 // Doclava has problem with "-source 1.9", so override javaVersion when Doclava
677 // is running with EXPERIMENTAL_USE_OPENJDK9=true. And eventually Doclava will be
678 // replaced by Metalava.
679 if !Bool(d.properties.Metalava_enabled) {
680 javaVersion = "1.8"
681 }
Nan Zhangc94f9d82018-06-26 10:02:26 -0700682 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
683 // since it doesn't support system modules yet.
684 if len(deps.bootClasspath.Strings()) > 0 {
685 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
686 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700687 }
Nan Zhang79614d12018-04-19 18:03:39 -0700688 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
689
Nan Zhang581fd212018-01-10 16:06:12 -0800690 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
691 argFilesMap := map[string]android.Path{}
692
693 for _, f := range argFiles {
694 implicits = append(implicits, f)
695 if _, exists := argFilesMap[f.Rel()]; !exists {
696 argFilesMap[f.Rel()] = f
697 } else {
698 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
699 f, argFilesMap[f.Rel()], f.Rel())
700 }
701 }
702
703 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
704 if strings.HasPrefix(name, "location ") {
705 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
706 if f, ok := argFilesMap[label]; ok {
707 return f.String(), nil
708 } else {
709 return "", fmt.Errorf("unknown location label %q", label)
710 }
711 } else if name == "genDir" {
712 return android.PathForModuleGen(ctx).String(), nil
713 }
714 return "", fmt.Errorf("unknown variable '$(%s)'", name)
715 })
716
717 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700718 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800719 return
720 }
721
Nan Zhang79614d12018-04-19 18:03:39 -0700722 genDocsForMetalava := false
723 var metalavaArgs string
724 if Bool(d.properties.Metalava_enabled) {
725 if strings.Contains(args, "--generate-documentation") {
726 if !strings.Contains(args, "-nodocs") {
727 genDocsForMetalava = true
728 }
729 // TODO(nanzhang): Add a Soong property to handle documentation args.
730 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800731 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700732 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800733 }
Nan Zhang581fd212018-01-10 16:06:12 -0800734 }
735
Nan Zhang79614d12018-04-19 18:03:39 -0700736 var templateDir, htmlDirArgs, htmlDir2Args string
737 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
738 if String(d.properties.Custom_template) == "" {
739 // TODO: This is almost always droiddoc-templates-sdk
740 ctx.PropertyErrorf("custom_template", "must specify a template")
741 }
742
743 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
744 if t, ok := m.(*DroiddocTemplate); ok {
745 implicits = append(implicits, t.deps...)
746 templateDir = t.dir.String()
747 } else {
748 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
749 }
750 })
751
752 if len(d.properties.Html_dirs) > 0 {
753 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
754 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
755 htmlDirArgs = "-htmldir " + htmlDir.String()
756 }
757
758 if len(d.properties.Html_dirs) > 1 {
759 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
760 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
761 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
762 }
763
764 if len(d.properties.Html_dirs) > 2 {
765 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
766 }
767
768 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
769 implicits = append(implicits, knownTags...)
770
771 for _, kt := range knownTags {
772 args = args + " -knowntags " + kt.String()
773 }
774
775 for _, hdf := range d.properties.Hdf {
776 args = args + " -hdf " + hdf
777 }
778
779 if String(d.properties.Proofread_file) != "" {
780 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
781 args = args + " -proofread " + proofreadFile.String()
782 }
783
784 if String(d.properties.Todo_file) != "" {
785 // tricky part:
786 // we should not compute full path for todo_file through PathForModuleOut().
787 // the non-standard doclet will get the full path relative to "-o".
788 args = args + " -todo " + String(d.properties.Todo_file)
789 }
790
791 if String(d.properties.Resourcesdir) != "" {
792 // TODO: should we add files under resourcesDir to the implicits? It seems that
793 // resourcesDir is one sub dir of htmlDir
794 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
795 args = args + " -resourcesdir " + resourcesDir.String()
796 }
797
798 if String(d.properties.Resourcesoutdir) != "" {
799 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
800 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
801 }
Dan Willemsencc090972018-02-26 14:33:31 -0800802 }
803
Nan Zhang79614d12018-04-19 18:03:39 -0700804 var docArgsForMetalava string
805 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
806 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800807 }
808
Nan Zhang28c68b92018-03-13 16:17:01 -0700809 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700810
811 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
812 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700813 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700814 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700815 implicitOutputs = append(implicitOutputs, d.apiFile)
816 }
817
Nan Zhang61819ce2018-05-04 18:49:16 -0700818 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
819 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
820 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700821 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700822 implicitOutputs = append(implicitOutputs, d.removedApiFile)
823 }
824
Nan Zhang28c68b92018-03-13 16:17:01 -0700825 if String(d.properties.Private_api_filename) != "" {
826 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
827 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700828 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700829 implicitOutputs = append(implicitOutputs, d.privateApiFile)
830 }
831
David Brazdilfbe4cc32018-05-31 13:56:46 +0100832 if String(d.properties.Dex_api_filename) != "" {
833 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
834 args = args + " -dexApi " + d.dexApiFile.String()
835 implicitOutputs = append(implicitOutputs, d.dexApiFile)
836 }
837
Nan Zhang28c68b92018-03-13 16:17:01 -0700838 if String(d.properties.Private_dex_api_filename) != "" {
839 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
840 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700841 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700842 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
843 }
844
David Brazdilaac0c3c2018-04-24 16:23:29 +0100845 if String(d.properties.Removed_dex_api_filename) != "" {
846 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
847 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700848 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100849 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
850 }
851
Nan Zhang28c68b92018-03-13 16:17:01 -0700852 if String(d.properties.Exact_api_filename) != "" {
853 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
854 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700855 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700856 implicitOutputs = append(implicitOutputs, d.exactApiFile)
857 }
858
Mathew Inwood76c3de12018-06-22 15:28:11 +0100859 if String(d.properties.Dex_mapping_filename) != "" {
860 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
861 args = args + " -apiMapping " + d.apiMappingFile.String()
862 // Omitted: metalava support
863 implicitOutputs = append(implicitOutputs, d.apiMappingFile)
864 }
865
Nan Zhang581fd212018-01-10 16:06:12 -0800866 implicits = append(implicits, d.Javadoc.srcJars...)
867
Nan Zhang79614d12018-04-19 18:03:39 -0700868 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
869 for _, o := range d.properties.Out {
870 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
871 }
872
Nan Zhang30963742018-04-23 09:59:14 -0700873 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
874 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700875
Nan Zhang46130972018-06-04 11:28:01 -0700876 var date string
877 if runtime.GOOS == "darwin" {
878 date = `date -r`
879 } else {
880 date = `date -d`
881 }
882
Nan Zhang357466b2018-04-17 17:38:36 -0700883 doclavaOpts := "-source " + javaVersion + " -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700884 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800885 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800886 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700887 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700888
Nan Zhang79614d12018-04-19 18:03:39 -0700889 if !Bool(d.properties.Metalava_enabled) {
890 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800891
Nan Zhang79614d12018-04-19 18:03:39 -0700892 implicits = append(implicits, jsilver)
893 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800894
Nan Zhang79614d12018-04-19 18:03:39 -0700895 if BoolDefault(d.properties.Create_stubs, true) {
896 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
897 }
898
Nan Zhange2ba5d42018-07-11 15:16:55 -0700899 if Bool(d.properties.Write_sdk_values) {
900 opts += " -sdkvalues " + android.PathForModuleOut(ctx, "docs").String()
901 }
902
903 var postDoclavaCmds string
904 if String(d.properties.Static_doc_index_redirect) != "" {
905 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
906 "static_doc_index_redirect")
907 implicits = append(implicits, static_doc_index_redirect)
908 postDoclavaCmds += " && cp " + static_doc_index_redirect.String() + " " +
909 android.PathForModuleOut(ctx, "docs", "out", "index.html").String()
910 }
911
912 if String(d.properties.Static_doc_properties) != "" {
913 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
914 "static_doc_properties")
915 implicits = append(implicits, static_doc_properties)
916 postDoclavaCmds += " && cp " + static_doc_properties.String() + " " +
917 android.PathForModuleOut(ctx, "docs", "out", "source.properties").String()
918 }
919
Nan Zhang79614d12018-04-19 18:03:39 -0700920 ctx.Build(pctx, android.BuildParams{
921 Rule: javadoc,
922 Description: "Droiddoc",
923 Output: d.Javadoc.stubsSrcJar,
924 Inputs: d.Javadoc.srcFiles,
925 Implicits: implicits,
926 ImplicitOutputs: implicitOutputs,
927 Args: map[string]string{
928 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
929 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
930 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
931 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
932 "opts": opts,
933 "bootclasspathArgs": bootClasspathArgs,
934 "classpathArgs": classpathArgs,
935 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
936 "docZip": d.Javadoc.docZip.String(),
Nan Zhange2ba5d42018-07-11 15:16:55 -0700937 "postDoclavaCmds": postDoclavaCmds,
Nan Zhang79614d12018-04-19 18:03:39 -0700938 },
939 })
940 } else {
941 opts := metalavaArgs
942
943 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800944 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
945 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
946 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
947 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang357466b2018-04-17 17:38:36 -0700948 "javaVersion": javaVersion,
Nan Zhang581fd212018-01-10 16:06:12 -0800949 "bootclasspathArgs": bootClasspathArgs,
950 "classpathArgs": classpathArgs,
951 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
952 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700953 }
954
955 var previousApi android.Path
956 if String(d.properties.Metalava_previous_api) != "" {
957 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
958 "metalava_previous_api")
Nan Zhang16c0a312018-06-13 17:42:48 -0700959 opts += " --previous-api " + previousApi.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700960 implicits = append(implicits, previousApi)
961 }
962
963 if Bool(d.properties.Metalava_annotations_enabled) {
964 if String(d.properties.Metalava_previous_api) == "" {
965 ctx.PropertyErrorf("metalava_previous_api",
966 "has to be non-empty if annotations was enabled!")
967 }
968 opts += " --include-annotations --migrate-nullness"
969
Nan Zhang03b733c2018-06-26 13:24:05 -0700970 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
971 implicitOutputs = append(implicitOutputs, d.annotationsZip)
Nan Zhang79614d12018-04-19 18:03:39 -0700972
Pete Gillinb13a0152018-07-19 17:56:49 +0100973 if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
974 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
Nan Zhang79614d12018-04-19 18:03:39 -0700975 "has to be non-empty if annotations was enabled!")
976 }
Pete Gillinb13a0152018-07-19 17:56:49 +0100977 mergeAnnotationsDirs := android.PathsForSource(ctx, d.properties.Metalava_merge_annotations_dirs)
Nan Zhang79614d12018-04-19 18:03:39 -0700978
Pete Gillinb13a0152018-07-19 17:56:49 +0100979 opts += " --extract-annotations " + d.annotationsZip.String()
980 for _, mergeAnnotationsDir := range mergeAnnotationsDirs {
981 opts += " --merge-annotations " + mergeAnnotationsDir.String()
982 }
Nan Zhang79614d12018-04-19 18:03:39 -0700983 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Nan Zhang16c0a312018-06-13 17:42:48 -0700984 opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhang79614d12018-04-19 18:03:39 -0700985 }
986
987 if genDocsForMetalava {
Nan Zhang16c0a312018-06-13 17:42:48 -0700988 opts += " --doc-stubs " + android.PathForModuleOut(ctx, "docs", "docStubsDir").String() +
989 " --write-doc-stubs-source-list $outDir/doc_stubs_src_list " +
990 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
Nan Zhang79614d12018-04-19 18:03:39 -0700991 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhang16c0a312018-06-13 17:42:48 -0700992 android.PathForModuleOut(ctx, "docs", "docStubsDir").String() + " -quiet -d $outDir "
Nan Zhang79614d12018-04-19 18:03:39 -0700993 implicits = append(implicits, jsilver)
994 implicits = append(implicits, doclava)
995 }
996
997 buildArgs["opts"] = opts
998 ctx.Build(pctx, android.BuildParams{
999 Rule: metalava,
1000 Description: "Metalava",
1001 Output: d.Javadoc.stubsSrcJar,
1002 Inputs: d.Javadoc.srcFiles,
1003 Implicits: implicits,
1004 ImplicitOutputs: implicitOutputs,
1005 Args: buildArgs,
1006 })
1007 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001008
1009 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1010
1011 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1012
1013 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
1014 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1015
1016 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1017 "check_api.current.api_file")
1018 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1019 "check_api.current_removed_api_file")
1020
1021 ctx.Build(pctx, android.BuildParams{
1022 Rule: apiCheck,
1023 Description: "Current API check",
1024 Output: d.checkCurrentApiTimestamp,
1025 Inputs: nil,
1026 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1027 checkApiClasspath...),
1028 Args: map[string]string{
1029 "classpath": checkApiClasspath.FormJavaClassPath(""),
1030 "opts": String(d.properties.Check_api.Current.Args),
1031 "apiFile": apiFile.String(),
1032 "apiFileToCheck": d.apiFile.String(),
1033 "removedApiFile": removedApiFile.String(),
1034 "removedApiFileToCheck": d.removedApiFile.String(),
1035 "msg": fmt.Sprintf(`\n******************************\n`+
1036 `You have tried to change the API from what has been previously approved.\n\n`+
1037 `To make these errors go away, you have two choices:\n`+
1038 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1039 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +09001040 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -07001041 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +09001042 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -07001043 ` you will need approval.\n`+
1044 `******************************\n`, ctx.ModuleName()),
1045 },
1046 })
1047
1048 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1049
1050 ctx.Build(pctx, android.BuildParams{
1051 Rule: updateApi,
1052 Description: "update current API",
1053 Output: d.updateCurrentApiTimestamp,
1054 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1055 Args: map[string]string{
1056 "apiFile": apiFile.String(),
1057 "apiFileToCheck": d.apiFile.String(),
1058 "removedApiFile": removedApiFile.String(),
1059 "removedApiFileToCheck": d.removedApiFile.String(),
1060 },
1061 })
1062 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001063 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
1064 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1065
1066 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1067 "check_api.last_released.api_file")
1068 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1069 "check_api.last_released.removed_api_file")
1070
1071 ctx.Build(pctx, android.BuildParams{
1072 Rule: apiCheck,
1073 Description: "Last Released API check",
1074 Output: d.checkLastReleasedApiTimestamp,
1075 Inputs: nil,
1076 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1077 checkApiClasspath...),
1078 Args: map[string]string{
1079 "classpath": checkApiClasspath.FormJavaClassPath(""),
1080 "opts": String(d.properties.Check_api.Last_released.Args),
1081 "apiFile": apiFile.String(),
1082 "apiFileToCheck": d.apiFile.String(),
1083 "removedApiFile": removedApiFile.String(),
1084 "removedApiFileToCheck": d.removedApiFile.String(),
1085 "msg": `\n******************************\n` +
1086 `You have tried to change the API from what has been previously released in\n` +
1087 `an SDK. Please fix the errors listed above.\n` +
1088 `******************************\n`,
1089 },
1090 })
1091 }
Nan Zhang581fd212018-01-10 16:06:12 -08001092}
Dan Willemsencc090972018-02-26 14:33:31 -08001093
1094var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
1095
1096type DroiddocTemplateProperties struct {
1097 // path to the directory containing the droiddoc templates.
1098 Path *string
1099}
1100
1101type DroiddocTemplate struct {
1102 android.ModuleBase
1103
1104 properties DroiddocTemplateProperties
1105
1106 deps android.Paths
1107 dir android.Path
1108}
1109
1110func DroiddocTemplateFactory() android.Module {
1111 module := &DroiddocTemplate{}
1112 module.AddProperties(&module.properties)
1113 android.InitAndroidModule(module)
1114 return module
1115}
1116
1117func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1118
1119func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1120 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1121 d.dir = path
1122 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1123}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001124
1125//
1126// Defaults
1127//
1128type DocDefaults struct {
1129 android.ModuleBase
1130 android.DefaultsModuleBase
1131}
1132
1133func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1134}
1135
1136func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1137}
1138
1139func DocDefaultsFactory() android.Module {
1140 module := &DocDefaults{}
1141
1142 module.AddProperties(
1143 &JavadocProperties{},
1144 &DroiddocProperties{},
1145 )
1146
1147 android.InitDefaultsModule(module)
1148
1149 return module
1150}