blob: ac4f86f2e9b9421dd47439d4f0e6e999a44eeeda [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{
Nan Zhangde860a42018-08-08 16:32:21 -070070 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
71 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070072 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070073 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang16c0a312018-06-13 17:42:48 -070074 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
75 `--stubs $stubsDir $opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070076 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
77 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
78 CommandDeps: []string{
79 "${config.ZipSyncCmd}",
80 "${config.JavaCmd}",
81 "${config.MetalavaJar}",
82 "${config.JavadocCmd}",
83 "${config.SoongZipCmd}",
84 },
85 Rspfile: "$out.rsp",
86 RspfileContent: "$in",
87 Restat: true,
88 },
Nan Zhangde860a42018-08-08 16:32:21 -070089 "outDir", "srcJarDir", "stubsDir", "docStubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
Nan Zhang357466b2018-04-17 17:38:36 -070090 "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -080091)
92
93func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080094 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
95
Nan Zhang581fd212018-01-10 16:06:12 -080096 android.RegisterModuleType("droiddoc", DroiddocFactory)
97 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -070098 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080099 android.RegisterModuleType("javadoc", JavadocFactory)
100 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
101}
102
Colin Crossa1ce2a02018-06-20 15:19:39 -0700103var (
104 srcsLibTag = dependencyTag{name: "sources from javalib"}
105)
106
Nan Zhang581fd212018-01-10 16:06:12 -0800107type JavadocProperties struct {
108 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
109 // or .aidl files.
110 Srcs []string `android:"arch_variant"`
111
112 // list of directories rooted at the Android.bp file that will
113 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800114 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800115
116 // list of source files that should not be used to build the Java module.
117 // This is most useful in the arch/multilib variants to remove non-common files
118 // filegroup or genrule can be included within this property.
119 Exclude_srcs []string `android:"arch_variant"`
120
Nan Zhangb2b33de2018-02-23 11:18:47 -0800121 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800122 Libs []string `android:"arch_variant"`
123
Nan Zhange66c7272018-03-06 12:59:27 -0800124 // don't build against the framework libraries (legacy-test, core-junit,
125 // ext, and framework for device targets)
126 No_framework_libs *bool
127
Nan Zhangb2b33de2018-02-23 11:18:47 -0800128 // the java library (in classpath) for documentation that provides java srcs and srcjars.
129 Srcs_lib *string
130
131 // the base dirs under srcs_lib will be scanned for java srcs.
132 Srcs_lib_whitelist_dirs []string
133
134 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
135 Srcs_lib_whitelist_pkgs []string
136
Nan Zhang581fd212018-01-10 16:06:12 -0800137 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800138 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800139
140 // if not blank, set to the version of the sdk to compile against
141 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900142
143 Aidl struct {
144 // Top level directories to pass to aidl tool
145 Include_dirs []string
146
147 // Directories rooted at the Android.bp file to pass to aidl tool
148 Local_include_dirs []string
149 }
Nan Zhang357466b2018-04-17 17:38:36 -0700150
151 // If not blank, set the java version passed to javadoc as -source
152 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800153}
154
Nan Zhang61819ce2018-05-04 18:49:16 -0700155type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900156 // path to the API txt file that the new API extracted from source code is checked
157 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700158 Api_file *string
159
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900160 // path to the API txt file that the new @removed API extractd from source code is
161 // checked against. The path can be local to the module or from other module (via
162 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700163 Removed_api_file *string
164
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900165 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700166 Args *string
167}
168
Nan Zhang581fd212018-01-10 16:06:12 -0800169type DroiddocProperties struct {
170 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800171 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800172
Nan Zhanga40da042018-08-01 12:48:00 -0700173 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800174 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800175
176 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800177 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800178
179 // proofread file contains all of the text content of the javadocs concatenated into one file,
180 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800181 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800182
183 // a todo file lists the program elements that are missing documentation.
184 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800185 Todo_file *string
186
187 // directory under current module source that provide additional resources (images).
188 Resourcesdir *string
189
190 // resources output directory under out/soong/.intermediates.
191 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800192
193 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800194 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800195
196 // user customized droiddoc args.
197 // Available variables for substitution:
198 //
199 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800200 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800201
202 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800203 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800204
Nan Zhange2ba5d42018-07-11 15:16:55 -0700205 // if set to true, collect the values used by the Dev tools and
206 // write them in files packaged with the SDK. Defaults to false.
207 Write_sdk_values *bool
208
209 // index.html under current module will be copied to docs out dir, if not null.
210 Static_doc_index_redirect *string
211
212 // source.properties under current module will be copied to docs out dir, if not null.
213 Static_doc_properties *string
214
Nan Zhang581fd212018-01-10 16:06:12 -0800215 // a list of files under current module source dir which contains known tags in Java sources.
216 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800217 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700218
219 // the tag name used to distinguish if the API files belong to public/system/test.
220 Api_tag_name *string
221
222 // the generated public API filename by Doclava.
223 Api_filename *string
224
David Brazdilfbe4cc32018-05-31 13:56:46 +0100225 // the generated public Dex API filename by Doclava.
226 Dex_api_filename *string
227
Nan Zhang28c68b92018-03-13 16:17:01 -0700228 // the generated private API filename by Doclava.
229 Private_api_filename *string
230
231 // the generated private Dex API filename by Doclava.
232 Private_dex_api_filename *string
233
234 // the generated removed API filename by Doclava.
235 Removed_api_filename *string
236
David Brazdilaac0c3c2018-04-24 16:23:29 +0100237 // the generated removed Dex API filename by Doclava.
238 Removed_dex_api_filename *string
239
Mathew Inwood76c3de12018-06-22 15:28:11 +0100240 // mapping of dex signatures to source file and line number. This is a temporary property and
241 // will be deleted; you probably shouldn't be using it.
242 Dex_mapping_filename *string
243
Nan Zhang28c68b92018-03-13 16:17:01 -0700244 // the generated exact API filename by Doclava.
245 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700246
Nan Zhang66dc2362018-08-14 20:41:04 -0700247 // the generated proguard filename by Doclava.
248 Proguard_filename *string
249
Nan Zhang853f4202018-04-12 16:55:56 -0700250 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
251 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700252
253 Check_api struct {
254 Last_released ApiToCheck
255
256 Current ApiToCheck
257 }
Nan Zhang79614d12018-04-19 18:03:39 -0700258
259 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
260 // currently still used for documentation generation, and will be replaced by Dokka soon.
261 Metalava_enabled *bool
262
263 // user can specify the version of previous released API file in order to do compatibility check.
264 Metalava_previous_api *string
265
266 // is set to true, Metalava will allow framework SDK to contain annotations.
267 Metalava_annotations_enabled *bool
268
Pete Gillinb13a0152018-07-19 17:56:49 +0100269 // a list of top-level directories containing files to merge annotations from.
270 Metalava_merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700271
272 // if set to true, generate docs through Dokka instead of Doclava. Valid only when
273 // metalava_enabled is set to true.
274 Dokka_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800275}
276
Nan Zhanga40da042018-08-01 12:48:00 -0700277//
278// Common flags passed down to build rule
279//
280type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700281 args string
282 bootClasspathArgs string
283 classpathArgs string
284 dokkaClasspathArgs string
285 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700286
Nan Zhanga40da042018-08-01 12:48:00 -0700287 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700288 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700289 postDoclavaCmds string
290
Nan Zhanga05ff572018-08-20 20:33:38 -0700291 metalavaStubsFlags string
292 metalavaAnnotationsFlags string
293 metalavaJavadocFlags string
294 metalavaCompatibilityCheckFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700295
Nan Zhang86d2d552018-08-09 15:33:27 -0700296 metalavaDokkaFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700297}
298
299func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
300 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
301 android.InitDefaultableModule(module)
302}
303
304//
305// Javadoc
306//
Nan Zhang581fd212018-01-10 16:06:12 -0800307type Javadoc struct {
308 android.ModuleBase
309 android.DefaultableModuleBase
310
311 properties JavadocProperties
312
313 srcJars android.Paths
314 srcFiles android.Paths
315 sourcepaths android.Paths
316
Nan Zhangccff0f72018-03-08 17:26:16 -0800317 docZip android.WritablePath
318 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800319}
320
Nan Zhangb2b33de2018-02-23 11:18:47 -0800321func (j *Javadoc) Srcs() android.Paths {
322 return android.Paths{j.stubsSrcJar}
323}
324
Nan Zhang581fd212018-01-10 16:06:12 -0800325func JavadocFactory() android.Module {
326 module := &Javadoc{}
327
328 module.AddProperties(&module.properties)
329
330 InitDroiddocModule(module, android.HostAndDeviceSupported)
331 return module
332}
333
334func JavadocHostFactory() android.Module {
335 module := &Javadoc{}
336
337 module.AddProperties(&module.properties)
338
339 InitDroiddocModule(module, android.HostSupported)
340 return module
341}
342
Nan Zhanga40da042018-08-01 12:48:00 -0700343var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800344
Colin Cross83bb3162018-06-25 15:48:06 -0700345func (j *Javadoc) sdkVersion() string {
346 return String(j.properties.Sdk_version)
347}
348
349func (j *Javadoc) minSdkVersion() string {
350 return j.sdkVersion()
351}
352
Nan Zhang581fd212018-01-10 16:06:12 -0800353func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
354 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700355 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800356 if sdkDep.useDefaultLibs {
357 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700358 if ctx.Config().TargetOpenJDK9() {
359 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
360 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700361 if !Bool(j.properties.No_framework_libs) {
Nan Zhang77a69ec2018-08-02 16:28:26 -0700362 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800363 }
Nan Zhang581fd212018-01-10 16:06:12 -0800364 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700365 if ctx.Config().TargetOpenJDK9() {
366 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
367 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700368 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800369 }
370 }
371
372 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700373 if j.properties.Srcs_lib != nil {
374 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
375 }
Nan Zhang581fd212018-01-10 16:06:12 -0800376
377 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
378
379 // exclude_srcs may contain filegroup or genrule.
380 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
381}
382
Nan Zhangb2b33de2018-02-23 11:18:47 -0800383func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
384 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
385 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900386 // convert foo.bar.baz to foo/bar/baz
387 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
388 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800389 if _, found := whitelistPathPrefixes[prefix]; !found {
390 whitelistPathPrefixes[prefix] = true
391 }
392 }
393 }
394}
395
Nan Zhanga40da042018-08-01 12:48:00 -0700396func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
397 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900398
399 // aidl flags.
400 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
401 if len(aidlFlags) > 0 {
402 // optimization.
403 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
404 flags.aidlFlags = "$aidlFlags"
405 }
406
407 return flags
408}
409
410func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
411 aidlIncludeDirs android.Paths) []string {
412
413 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
414 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
415
416 var flags []string
417 if aidlPreprocess.Valid() {
418 flags = append(flags, "-p"+aidlPreprocess.String())
419 } else {
420 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
421 }
422
423 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
424 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
425 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
426 flags = append(flags, "-I"+src.String())
427 }
428
429 return flags
430}
431
432func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700433 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900434
435 outSrcFiles := make(android.Paths, 0, len(srcFiles))
436
437 for _, srcFile := range srcFiles {
438 switch srcFile.Ext() {
439 case ".aidl":
440 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
441 outSrcFiles = append(outSrcFiles, javaFile)
442 default:
443 outSrcFiles = append(outSrcFiles, srcFile)
444 }
445 }
446
447 return outSrcFiles
448}
449
Nan Zhang581fd212018-01-10 16:06:12 -0800450func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
451 var deps deps
452
Colin Cross83bb3162018-06-25 15:48:06 -0700453 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800454 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700455 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800456 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700457 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800458 }
459
460 ctx.VisitDirectDeps(func(module android.Module) {
461 otherName := ctx.OtherModuleName(module)
462 tag := ctx.OtherModuleDependencyTag(module)
463
Colin Cross2d24c1b2018-05-23 10:59:18 -0700464 switch tag {
465 case bootClasspathTag:
466 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800467 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700468 } else {
469 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
470 }
471 case libTag:
472 switch dep := module.(type) {
473 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800474 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700475 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700476 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900477 linkType := javaSdk
478 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
479 linkType = javaSystem
480 } else if sdkVersion == "" {
481 linkType = javaPlatform
482 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900483 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700484 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800485 checkProducesJars(ctx, dep)
486 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800487 default:
488 ctx.ModuleErrorf("depends on non-java module %q", otherName)
489 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700490 case srcsLibTag:
491 switch dep := module.(type) {
492 case Dependency:
493 srcs := dep.(SrcDependency).CompiledSrcs()
494 whitelistPathPrefixes := make(map[string]bool)
495 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
496 for _, src := range srcs {
497 if _, ok := src.(android.WritablePath); ok { // generated sources
498 deps.srcs = append(deps.srcs, src)
499 } else { // select source path for documentation based on whitelist path prefixs.
500 for k, _ := range whitelistPathPrefixes {
501 if strings.HasPrefix(src.Rel(), k) {
502 deps.srcs = append(deps.srcs, src)
503 break
504 }
505 }
506 }
507 }
508 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
509 default:
510 ctx.ModuleErrorf("depends on non-java module %q", otherName)
511 }
Nan Zhang357466b2018-04-17 17:38:36 -0700512 case systemModulesTag:
513 if deps.systemModules != nil {
514 panic("Found two system module dependencies")
515 }
516 sm := module.(*SystemModules)
517 if sm.outputFile == nil {
518 panic("Missing directory for system module dependency")
519 }
520 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800521 }
522 })
523 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
524 // may contain filegroup or genrule.
525 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700526 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900527 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800528
529 // srcs may depend on some genrule output.
530 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800531 j.srcJars = append(j.srcJars, deps.srcJars...)
532
Nan Zhang581fd212018-01-10 16:06:12 -0800533 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800534 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800535
536 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800537 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800538
539 if j.properties.Local_sourcepaths == nil {
540 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
541 }
542 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800543
544 return deps
545}
546
547func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
548 j.addDeps(ctx)
549}
550
551func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
552 deps := j.collectDeps(ctx)
553
554 var implicits android.Paths
555 implicits = append(implicits, deps.bootClasspath...)
556 implicits = append(implicits, deps.classpath...)
557
558 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700559
Colin Cross83bb3162018-06-25 15:48:06 -0700560 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700561 if len(deps.bootClasspath) > 0 {
562 var systemModules classpath
563 if deps.systemModules != nil {
564 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800565 }
Colin Cross997262f2018-06-19 22:49:39 -0700566 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
567 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800568 }
569 if len(deps.classpath.Strings()) > 0 {
570 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
571 }
572
573 implicits = append(implicits, j.srcJars...)
574
Nan Zhangaf322cc2018-06-19 15:15:38 -0700575 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800576
577 ctx.Build(pctx, android.BuildParams{
578 Rule: javadoc,
579 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800580 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800581 ImplicitOutput: j.docZip,
582 Inputs: j.srcFiles,
583 Implicits: implicits,
584 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700585 "outDir": android.PathForModuleOut(ctx, "out").String(),
586 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
587 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800588 "srcJars": strings.Join(j.srcJars.Strings(), " "),
589 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700590 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800591 "classpathArgs": classpathArgs,
592 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
593 "docZip": j.docZip.String(),
594 },
595 })
596}
597
Nan Zhanga40da042018-08-01 12:48:00 -0700598//
599// Droiddoc
600//
601type Droiddoc struct {
602 Javadoc
603
604 properties DroiddocProperties
605 apiFile android.WritablePath
606 dexApiFile android.WritablePath
607 privateApiFile android.WritablePath
608 privateDexApiFile android.WritablePath
609 removedApiFile android.WritablePath
610 removedDexApiFile android.WritablePath
611 exactApiFile android.WritablePath
612 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700613 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700614
615 checkCurrentApiTimestamp android.WritablePath
616 updateCurrentApiTimestamp android.WritablePath
617 checkLastReleasedApiTimestamp android.WritablePath
618
619 annotationsZip android.WritablePath
620
621 apiFilePath android.Path
622}
623
624type ApiFilePath interface {
625 ApiFilePath() android.Path
626}
627
628func DroiddocFactory() android.Module {
629 module := &Droiddoc{}
630
631 module.AddProperties(&module.properties,
632 &module.Javadoc.properties)
633
634 InitDroiddocModule(module, android.HostAndDeviceSupported)
635 return module
636}
637
638func DroiddocHostFactory() android.Module {
639 module := &Droiddoc{}
640
641 module.AddProperties(&module.properties,
642 &module.Javadoc.properties)
643
644 InitDroiddocModule(module, android.HostSupported)
645 return module
646}
647
648func (d *Droiddoc) ApiFilePath() android.Path {
649 return d.apiFilePath
650}
651
Nan Zhang61819ce2018-05-04 18:49:16 -0700652func (d *Droiddoc) checkCurrentApi() bool {
653 if String(d.properties.Check_api.Current.Api_file) != "" &&
654 String(d.properties.Check_api.Current.Removed_api_file) != "" {
655 return true
656 } else if String(d.properties.Check_api.Current.Api_file) != "" {
657 panic("check_api.current.removed_api_file: has to be non empty!")
658 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
659 panic("check_api.current.api_file: has to be non empty!")
660 }
661
662 return false
663}
664
665func (d *Droiddoc) checkLastReleasedApi() bool {
666 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
667 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
668 return true
669 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
670 panic("check_api.last_released.removed_api_file: has to be non empty!")
671 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
672 panic("check_api.last_released.api_file: has to be non empty!")
673 }
674
675 return false
676}
677
Nan Zhang581fd212018-01-10 16:06:12 -0800678func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
679 d.Javadoc.addDeps(ctx)
680
Nan Zhang79614d12018-04-19 18:03:39 -0700681 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800682 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
683 }
684
Nan Zhanga40da042018-08-01 12:48:00 -0700685 // arg_files may contains filegroup or genrule.
Nan Zhang581fd212018-01-10 16:06:12 -0800686 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
687
688 // knowntags may contain filegroup or genrule.
689 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700690
Nan Zhange2ba5d42018-07-11 15:16:55 -0700691 if String(d.properties.Static_doc_index_redirect) != "" {
692 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
693 }
694
695 if String(d.properties.Static_doc_properties) != "" {
696 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
697 }
698
Nan Zhang61819ce2018-05-04 18:49:16 -0700699 if d.checkCurrentApi() {
700 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
701 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
702 }
703
704 if d.checkLastReleasedApi() {
705 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
706 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
707 }
Nan Zhang79614d12018-04-19 18:03:39 -0700708
709 if String(d.properties.Metalava_previous_api) != "" {
710 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
711 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700712
713 if len(d.properties.Metalava_merge_annotations_dirs) != 0 {
714 for _, mergeAnnotationsDir := range d.properties.Metalava_merge_annotations_dirs {
715 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
716 }
717 }
Nan Zhang581fd212018-01-10 16:06:12 -0800718}
719
Nan Zhang66dc2362018-08-14 20:41:04 -0700720func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
721 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700722 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800723
Nan Zhanga40da042018-08-01 12:48:00 -0700724 *implicits = append(*implicits, deps.bootClasspath...)
725 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800726
Nan Zhangc94f9d82018-06-26 10:02:26 -0700727 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
728 // since it doesn't support system modules yet.
729 if len(deps.bootClasspath.Strings()) > 0 {
730 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700731 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700732 }
Nan Zhanga40da042018-08-01 12:48:00 -0700733 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang86d2d552018-08-09 15:33:27 -0700734 // Dokka doesn't support boocClasspath, so combine these two classpath vars for Dokka.
735 dokkaClasspath := classpath{}
736 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
737 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
738 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700739
Nan Zhang581fd212018-01-10 16:06:12 -0800740 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
741 argFilesMap := map[string]android.Path{}
742
743 for _, f := range argFiles {
Nan Zhanga40da042018-08-01 12:48:00 -0700744 *implicits = append(*implicits, f)
Nan Zhang581fd212018-01-10 16:06:12 -0800745 if _, exists := argFilesMap[f.Rel()]; !exists {
746 argFilesMap[f.Rel()] = f
747 } else {
748 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
749 f, argFilesMap[f.Rel()], f.Rel())
750 }
751 }
752
Nan Zhanga40da042018-08-01 12:48:00 -0700753 var err error
754 flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) {
Nan Zhang581fd212018-01-10 16:06:12 -0800755 if strings.HasPrefix(name, "location ") {
756 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
757 if f, ok := argFilesMap[label]; ok {
758 return f.String(), nil
759 } else {
760 return "", fmt.Errorf("unknown location label %q", label)
761 }
762 } else if name == "genDir" {
763 return android.PathForModuleGen(ctx).String(), nil
764 }
765 return "", fmt.Errorf("unknown variable '$(%s)'", name)
766 })
767
768 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700769 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhanga40da042018-08-01 12:48:00 -0700770 return droiddocBuilderFlags{}, err
Nan Zhang581fd212018-01-10 16:06:12 -0800771 }
Nan Zhanga40da042018-08-01 12:48:00 -0700772 return flags, nil
773}
Nan Zhang581fd212018-01-10 16:06:12 -0800774
Nan Zhanga40da042018-08-01 12:48:00 -0700775func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700776 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800777
Nan Zhanga40da042018-08-01 12:48:00 -0700778 *implicits = append(*implicits, jsilver)
779 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700780
Nan Zhang46130972018-06-04 11:28:01 -0700781 var date string
782 if runtime.GOOS == "darwin" {
783 date = `date -r`
784 } else {
785 date = `date -d`
786 }
787
Nan Zhang443fa522018-08-20 20:58:28 -0700788 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
789 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
790 // 1.9 language features.
791 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700792 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800793 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700794 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700795
Nan Zhanga40da042018-08-01 12:48:00 -0700796 if String(d.properties.Custom_template) == "" {
797 // TODO: This is almost always droiddoc-templates-sdk
798 ctx.PropertyErrorf("custom_template", "must specify a template")
799 }
800
801 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700802 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700803 *implicits = append(*implicits, t.deps...)
804 args = args + " -templatedir " + t.dir.String()
805 } else {
806 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
807 }
808 })
809
810 if len(d.properties.Html_dirs) > 0 {
811 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
812 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
813 args = args + " -htmldir " + htmlDir.String()
814 }
815
816 if len(d.properties.Html_dirs) > 1 {
817 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
818 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
819 args = args + " -htmldir2 " + htmlDir2.String()
820 }
821
822 if len(d.properties.Html_dirs) > 2 {
823 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
824 }
825
826 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
827 *implicits = append(*implicits, knownTags...)
828
829 for _, kt := range knownTags {
830 args = args + " -knowntags " + kt.String()
831 }
832
833 for _, hdf := range d.properties.Hdf {
834 args = args + " -hdf " + hdf
835 }
836
837 if String(d.properties.Proofread_file) != "" {
838 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
839 args = args + " -proofread " + proofreadFile.String()
840 }
841
842 if String(d.properties.Todo_file) != "" {
843 // tricky part:
844 // we should not compute full path for todo_file through PathForModuleOut().
845 // the non-standard doclet will get the full path relative to "-o".
846 args = args + " -todo " + String(d.properties.Todo_file)
847 }
848
849 if String(d.properties.Resourcesdir) != "" {
850 // TODO: should we add files under resourcesDir to the implicits? It seems that
851 // resourcesDir is one sub dir of htmlDir
852 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
853 args = args + " -resourcesdir " + resourcesDir.String()
854 }
855
856 if String(d.properties.Resourcesoutdir) != "" {
857 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
858 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
859 }
860 return args
861}
862
863func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) {
864 var doclavaFlags, MetalavaFlags string
865 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
866 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
867 doclavaFlags += " -api " + d.apiFile.String()
868 MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String()
869 *implicitOutputs = append(*implicitOutputs, d.apiFile)
870 d.apiFilePath = d.apiFile
871 }
872
873 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
874 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
875 doclavaFlags += " -removedApi " + d.removedApiFile.String()
876 MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String()
877 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
878 }
879
880 if String(d.properties.Private_api_filename) != "" {
881 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
882 doclavaFlags += " -privateApi " + d.privateApiFile.String()
883 MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String()
884 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
885 }
886
887 if String(d.properties.Dex_api_filename) != "" {
888 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
889 doclavaFlags += " -dexApi " + d.dexApiFile.String()
890 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
891 }
892
893 if String(d.properties.Private_dex_api_filename) != "" {
894 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
895 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
896 MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
897 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
898 }
899
900 if String(d.properties.Removed_dex_api_filename) != "" {
901 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
902 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
903 MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
904 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
905 }
906
907 if String(d.properties.Exact_api_filename) != "" {
908 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
909 doclavaFlags += " -exactApi " + d.exactApiFile.String()
910 MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String()
911 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
912 }
913
914 if String(d.properties.Dex_mapping_filename) != "" {
915 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
916 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
917 // Omitted: metalava support
918 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
919 }
920
Nan Zhang66dc2362018-08-14 20:41:04 -0700921 if String(d.properties.Proguard_filename) != "" {
922 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
923 doclavaFlags += " -proguard " + d.proguardFile.String()
924 // Omitted: metalava support
925 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
926 }
927
Nan Zhanga40da042018-08-01 12:48:00 -0700928 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -0700929 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700930 }
931
932 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -0700933 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700934 }
935 return doclavaFlags, MetalavaFlags
936}
937
938func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
939 var cmds string
940 if String(d.properties.Static_doc_index_redirect) != "" {
941 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
942 "static_doc_index_redirect")
943 *implicits = append(*implicits, static_doc_index_redirect)
944 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700945 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700946 }
947
948 if String(d.properties.Static_doc_properties) != "" {
949 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
950 "static_doc_properties")
951 *implicits = append(*implicits, static_doc_properties)
952 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700953 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700954 }
955 return cmds
956}
957
958func (d *Droiddoc) collectMetalavaAnnotationsFlags(
959 ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
960 var flags string
Nan Zhanga40da042018-08-01 12:48:00 -0700961 if Bool(d.properties.Metalava_annotations_enabled) {
962 if String(d.properties.Metalava_previous_api) == "" {
963 ctx.PropertyErrorf("metalava_previous_api",
964 "has to be non-empty if annotations was enabled!")
965 }
Nan Zhangde860a42018-08-08 16:32:21 -0700966 previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api),
967 "metalava_previous_api")
968 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -0700969
Nan Zhangd05a4362018-08-15 13:28:54 -0700970 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700971
972 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
973 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
974
Nan Zhangf4936b02018-08-01 15:00:28 -0700975 flags += " --extract-annotations " + d.annotationsZip.String()
976
Nan Zhanga40da042018-08-01 12:48:00 -0700977 if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
978 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
979 "has to be non-empty if annotations was enabled!")
980 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700981 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
982 if t, ok := m.(*ExportedDroiddocDir); ok {
983 *implicits = append(*implicits, t.deps...)
984 flags += " --merge-annotations " + t.dir.String()
985 } else {
986 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
987 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
988 }
989 })
Nan Zhanga40da042018-08-01 12:48:00 -0700990 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
991 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
992 }
993
994 return flags
995}
996
Nan Zhang86d2d552018-08-09 15:33:27 -0700997func (d *Droiddoc) collectMetalavaJavadocFlags(ctx android.ModuleContext,
Nan Zhangde860a42018-08-08 16:32:21 -0700998 bootClasspathArgs, classpathArgs, outDir, docStubsDir string) string {
999 return " --doc-stubs " + docStubsDir +
1000 " --write-doc-stubs-source-list " + android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
Nan Zhanga40da042018-08-01 12:48:00 -07001001 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
1002 bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhangde860a42018-08-08 16:32:21 -07001003 docStubsDir + " -quiet -d " + outDir
Nan Zhanga40da042018-08-01 12:48:00 -07001004}
1005
Nan Zhang86d2d552018-08-09 15:33:27 -07001006func (d *Droiddoc) collectMetalavaDokkaFlags(ctx android.ModuleContext, implicits *android.Paths,
1007 classpathArgs, outDir, docStubsDir string) string {
1008 dokka := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "dokka.jar")
1009 *implicits = append(*implicits, dokka)
1010
1011 return " --doc-stubs " + docStubsDir + " --write-doc-stubs-source-list " +
1012 android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
1013 " --generate-documentation ${config.JavaCmd} -jar " + dokka.String() + " " +
1014 docStubsDir + " " + classpathArgs + " -format dac -dacRoot /reference/kotlin -output " + outDir
1015}
1016
Nan Zhanga05ff572018-08-20 20:33:38 -07001017func (d *Droiddoc) collectMetalavaCompatibilityCheckFlags(ctx android.ModuleContext,
1018 implicits *android.Paths) string {
1019 var flags string
1020 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
1021 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1022 "check_api.current.api_file")
1023 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1024 "check_api.current_removed_api_file")
1025
1026 *implicits = append(*implicits, apiFile)
1027 *implicits = append(*implicits, removedApiFile)
1028
1029 flags = " --check-compatibility:api:current " + apiFile.String() +
1030 " --check-compatibility:removed:current " + removedApiFile.String() + " "
1031 }
1032
1033 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
1034 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1035 "check_api.last_released.api_file")
1036 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1037 "check_api.last_released.removed_api_file")
1038
1039 *implicits = append(*implicits, apiFile)
1040 *implicits = append(*implicits, removedApiFile)
1041
1042 flags = flags + " --check-compatibility:api:released " + apiFile.String() +
1043 " --check-compatibility:removed:released " + removedApiFile.String() + " "
1044 }
1045
1046 return flags
1047}
1048
Nan Zhang86d2d552018-08-09 15:33:27 -07001049func (d *Droiddoc) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1050 implicitOutputs android.WritablePaths, outDir, docStubsDir, javaVersion,
1051 bootclasspathArgs, classpathArgs, opts string) {
1052 ctx.Build(pctx, android.BuildParams{
1053 Rule: metalava,
1054 Description: "Metalava",
1055 Output: d.Javadoc.stubsSrcJar,
1056 Inputs: d.Javadoc.srcFiles,
1057 Implicits: implicits,
1058 ImplicitOutputs: implicitOutputs,
1059 Args: map[string]string{
1060 "outDir": outDir,
1061 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1062 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1063 "docStubsDir": docStubsDir,
1064 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1065 "javaVersion": javaVersion,
1066 "bootclasspathArgs": bootclasspathArgs,
1067 "classpathArgs": classpathArgs,
1068 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1069 "docZip": d.Javadoc.docZip.String(),
1070 "opts": opts,
1071 },
1072 })
1073}
1074
1075func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1076 implicitOutputs android.WritablePaths, bootclasspathArgs, classpathArgs, opts, postDoclavaCmds string) {
1077 ctx.Build(pctx, android.BuildParams{
1078 Rule: javadoc,
1079 Description: "Doclava",
1080 Output: d.Javadoc.stubsSrcJar,
1081 Inputs: d.Javadoc.srcFiles,
1082 Implicits: implicits,
1083 ImplicitOutputs: implicitOutputs,
1084 Args: map[string]string{
1085 "outDir": android.PathForModuleOut(ctx, "out").String(),
1086 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1087 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1088 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1089 "opts": opts,
1090 "bootclasspathArgs": bootclasspathArgs,
1091 "classpathArgs": classpathArgs,
1092 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1093 "docZip": d.Javadoc.docZip.String(),
1094 "postDoclavaCmds": postDoclavaCmds,
1095 },
1096 })
1097}
1098
1099func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1100 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1101 ctx.Build(pctx, android.BuildParams{
1102 Rule: apiCheck,
Nan Zhanga05ff572018-08-20 20:33:38 -07001103 Description: "Doclava Check API",
Nan Zhang86d2d552018-08-09 15:33:27 -07001104 Output: output,
1105 Inputs: nil,
1106 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1107 checkApiClasspath...),
1108 Args: map[string]string{
1109 "classpath": checkApiClasspath.FormJavaClassPath(""),
1110 "opts": opts,
1111 "apiFile": apiFile.String(),
1112 "apiFileToCheck": d.apiFile.String(),
1113 "removedApiFile": removedApiFile.String(),
1114 "removedApiFileToCheck": d.removedApiFile.String(),
1115 "msg": msg,
1116 },
1117 })
1118}
1119
1120func (d *Droiddoc) transformUpdateApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1121 output android.WritablePath) {
1122 ctx.Build(pctx, android.BuildParams{
1123 Rule: updateApi,
1124 Description: "Update API",
1125 Output: output,
1126 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1127 Args: map[string]string{
1128 "apiFile": apiFile.String(),
1129 "apiFileToCheck": d.apiFile.String(),
1130 "removedApiFile": removedApiFile.String(),
1131 "removedApiFileToCheck": d.removedApiFile.String(),
1132 },
1133 })
1134}
1135
Nan Zhanga40da042018-08-01 12:48:00 -07001136func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1137 deps := d.Javadoc.collectDeps(ctx)
1138
1139 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhanga40da042018-08-01 12:48:00 -07001140 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1141 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1142 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1143 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
Nan Zhang581fd212018-01-10 16:06:12 -08001144
Nan Zhanga40da042018-08-01 12:48:00 -07001145 var implicits android.Paths
1146 implicits = append(implicits, d.Javadoc.srcJars...)
1147
1148 var implicitOutputs android.WritablePaths
1149 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1150 for _, o := range d.properties.Out {
1151 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1152 }
1153
1154 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1155 if err != nil {
1156 return
1157 }
1158
1159 flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1160 if Bool(d.properties.Metalava_enabled) {
Nan Zhanga40da042018-08-01 12:48:00 -07001161 flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhanga05ff572018-08-20 20:33:38 -07001162 flags.metalavaCompatibilityCheckFlags = d.collectMetalavaCompatibilityCheckFlags(ctx, &implicits)
Nan Zhang86d2d552018-08-09 15:33:27 -07001163 outDir := android.PathForModuleOut(ctx, "out").String()
Nan Zhangde860a42018-08-08 16:32:21 -07001164 docStubsDir := android.PathForModuleOut(ctx, "docStubsDir").String()
Nan Zhang86d2d552018-08-09 15:33:27 -07001165 // TODO(nanzhang): Add a Soong property to handle documentation args.
1166 if strings.Contains(flags.args, "--generate-documentation") { // enable docs generation
1167 if Bool(d.properties.Dokka_enabled) {
1168 flags.metalavaDokkaFlags = d.collectMetalavaDokkaFlags(ctx, &implicits,
1169 flags.dokkaClasspathArgs, outDir, docStubsDir)
1170 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1171 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhanga05ff572018-08-20 20:33:38 -07001172 flags.metalavaAnnotationsFlags+" "+flags.metalavaCompatibilityCheckFlags+" "+
1173 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001174 flags.metalavaDokkaFlags+" "+strings.Split(flags.args, "--generate-documentation")[1])
1175 } else {
1176 flags.metalavaJavadocFlags = d.collectMetalavaJavadocFlags(
1177 ctx, flags.bootClasspathArgs, flags.classpathArgs, outDir, docStubsDir)
Nan Zhang443fa522018-08-20 20:58:28 -07001178 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhang86d2d552018-08-09 15:33:27 -07001179 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1180 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhanga05ff572018-08-20 20:33:38 -07001181 flags.metalavaAnnotationsFlags+" "+flags.metalavaCompatibilityCheckFlags+" "+
1182 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001183 flags.metalavaJavadocFlags+flags.doclavaDocsFlags+
1184 " "+strings.Split(flags.args, "--generate-documentation")[1])
1185 }
Nan Zhanga40da042018-08-01 12:48:00 -07001186 } else {
Nan Zhang86d2d552018-08-09 15:33:27 -07001187 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1188 flags.bootClasspathArgs, flags.classpathArgs,
Nan Zhanga05ff572018-08-20 20:33:38 -07001189 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+
1190 flags.metalavaCompatibilityCheckFlags+flags.args)
Nan Zhang79614d12018-04-19 18:03:39 -07001191 }
Nan Zhanga40da042018-08-01 12:48:00 -07001192 } else {
Nan Zhang443fa522018-08-20 20:58:28 -07001193 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhanga40da042018-08-01 12:48:00 -07001194 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
Nan Zhang86d2d552018-08-09 15:33:27 -07001195 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1196 flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+flags.args,
1197 flags.postDoclavaCmds)
Nan Zhang79614d12018-04-19 18:03:39 -07001198 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001199
Nan Zhang61819ce2018-05-04 18:49:16 -07001200 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001201 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1202 "check_api.current.api_file")
1203 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1204 "check_api.current_removed_api_file")
1205
Nan Zhang55e0bf42018-08-16 16:23:11 -07001206 if !Bool(d.properties.Metalava_enabled) {
1207 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1208 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1209 fmt.Sprintf(`\n******************************\n`+
1210 `You have tried to change the API from what has been previously approved.\n\n`+
1211 `To make these errors go away, you have two choices:\n`+
1212 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1213 ` errors above.\n\n`+
1214 ` 2. You can update current.txt by executing the following command:\n`+
1215 ` make %s-update-current-api\n\n`+
1216 ` To submit the revised current.txt to the main Android repository,\n`+
1217 ` you will need approval.\n`+
1218 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1219 d.checkCurrentApiTimestamp)
Nan Zhang55e0bf42018-08-16 16:23:11 -07001220 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001221
1222 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang86d2d552018-08-09 15:33:27 -07001223 d.transformUpdateApi(ctx, apiFile, removedApiFile, d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001224 }
Nan Zhanga40da042018-08-01 12:48:00 -07001225
Nan Zhang61819ce2018-05-04 18:49:16 -07001226 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001227 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1228 "check_api.last_released.api_file")
1229 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1230 "check_api.last_released.removed_api_file")
1231
Nan Zhanga05ff572018-08-20 20:33:38 -07001232 if !Bool(d.properties.Metalava_enabled) {
1233 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1234
1235 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1236 `\n******************************\n`+
1237 `You have tried to change the API from what has been previously released in\n`+
1238 `an SDK. Please fix the errors listed above.\n`+
1239 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1240 d.checkLastReleasedApiTimestamp)
1241 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001242 }
Nan Zhang581fd212018-01-10 16:06:12 -08001243}
Dan Willemsencc090972018-02-26 14:33:31 -08001244
Nan Zhanga40da042018-08-01 12:48:00 -07001245//
Nan Zhangf4936b02018-08-01 15:00:28 -07001246// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001247//
Dan Willemsencc090972018-02-26 14:33:31 -08001248var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001249var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001250
Nan Zhangf4936b02018-08-01 15:00:28 -07001251type ExportedDroiddocDirProperties struct {
1252 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001253 Path *string
1254}
1255
Nan Zhangf4936b02018-08-01 15:00:28 -07001256type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001257 android.ModuleBase
1258
Nan Zhangf4936b02018-08-01 15:00:28 -07001259 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001260
1261 deps android.Paths
1262 dir android.Path
1263}
1264
Nan Zhangf4936b02018-08-01 15:00:28 -07001265func ExportedDroiddocDirFactory() android.Module {
1266 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001267 module.AddProperties(&module.properties)
1268 android.InitAndroidModule(module)
1269 return module
1270}
1271
Nan Zhangf4936b02018-08-01 15:00:28 -07001272func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001273
Nan Zhangf4936b02018-08-01 15:00:28 -07001274func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001275 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1276 d.dir = path
1277 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1278}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001279
1280//
1281// Defaults
1282//
1283type DocDefaults struct {
1284 android.ModuleBase
1285 android.DefaultsModuleBase
1286}
1287
1288func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1289}
1290
1291func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1292}
1293
1294func DocDefaultsFactory() android.Module {
1295 module := &DocDefaults{}
1296
1297 module.AddProperties(
1298 &JavadocProperties{},
1299 &DroiddocProperties{},
1300 )
1301
1302 android.InitDefaultsModule(module)
1303
1304 return module
1305}