blob: 1538d91b8a845e9f3f3afcf930b2fc16ff595832 [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 Zhanged0a39d2018-08-23 17:30:38 -070091
92 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
93 blueprint.RuleParams{
94 Command: `( ${config.JavaCmd} -jar ${config.MetalavaJar} $opts && touch $out ) || (echo -e "$msg" ; exit 38)`,
95 CommandDeps: []string{
96 "${config.JavaCmd}",
97 "${config.MetalavaJar}",
98 },
99 },
100 "opts", "msg")
Nan Zhang581fd212018-01-10 16:06:12 -0800101)
102
103func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800104 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
105
Nan Zhang581fd212018-01-10 16:06:12 -0800106 android.RegisterModuleType("droiddoc", DroiddocFactory)
107 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700108 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800109 android.RegisterModuleType("javadoc", JavadocFactory)
110 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
111}
112
Colin Crossa1ce2a02018-06-20 15:19:39 -0700113var (
114 srcsLibTag = dependencyTag{name: "sources from javalib"}
115)
116
Nan Zhang581fd212018-01-10 16:06:12 -0800117type JavadocProperties struct {
118 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
119 // or .aidl files.
120 Srcs []string `android:"arch_variant"`
121
122 // list of directories rooted at the Android.bp file that will
123 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800124 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800125
126 // list of source files that should not be used to build the Java module.
127 // This is most useful in the arch/multilib variants to remove non-common files
128 // filegroup or genrule can be included within this property.
129 Exclude_srcs []string `android:"arch_variant"`
130
Nan Zhangb2b33de2018-02-23 11:18:47 -0800131 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800132 Libs []string `android:"arch_variant"`
133
Nan Zhange66c7272018-03-06 12:59:27 -0800134 // don't build against the framework libraries (legacy-test, core-junit,
135 // ext, and framework for device targets)
136 No_framework_libs *bool
137
Nan Zhangb2b33de2018-02-23 11:18:47 -0800138 // the java library (in classpath) for documentation that provides java srcs and srcjars.
139 Srcs_lib *string
140
141 // the base dirs under srcs_lib will be scanned for java srcs.
142 Srcs_lib_whitelist_dirs []string
143
144 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
145 Srcs_lib_whitelist_pkgs []string
146
Nan Zhang581fd212018-01-10 16:06:12 -0800147 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800148 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800149
150 // if not blank, set to the version of the sdk to compile against
151 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900152
153 Aidl struct {
154 // Top level directories to pass to aidl tool
155 Include_dirs []string
156
157 // Directories rooted at the Android.bp file to pass to aidl tool
158 Local_include_dirs []string
159 }
Nan Zhang357466b2018-04-17 17:38:36 -0700160
161 // If not blank, set the java version passed to javadoc as -source
162 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800163}
164
Nan Zhang61819ce2018-05-04 18:49:16 -0700165type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900166 // path to the API txt file that the new API extracted from source code is checked
167 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700168 Api_file *string
169
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900170 // path to the API txt file that the new @removed API extractd from source code is
171 // checked against. The path can be local to the module or from other module (via
172 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700173 Removed_api_file *string
174
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900175 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700176 Args *string
177}
178
Nan Zhang581fd212018-01-10 16:06:12 -0800179type DroiddocProperties struct {
180 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800181 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800182
Nan Zhanga40da042018-08-01 12:48:00 -0700183 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800184 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800185
186 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800187 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800188
189 // proofread file contains all of the text content of the javadocs concatenated into one file,
190 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800191 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800192
193 // a todo file lists the program elements that are missing documentation.
194 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800195 Todo_file *string
196
197 // directory under current module source that provide additional resources (images).
198 Resourcesdir *string
199
200 // resources output directory under out/soong/.intermediates.
201 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800202
203 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800204 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800205
206 // user customized droiddoc args.
207 // Available variables for substitution:
208 //
209 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800210 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800211
212 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800213 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800214
Nan Zhange2ba5d42018-07-11 15:16:55 -0700215 // if set to true, collect the values used by the Dev tools and
216 // write them in files packaged with the SDK. Defaults to false.
217 Write_sdk_values *bool
218
219 // index.html under current module will be copied to docs out dir, if not null.
220 Static_doc_index_redirect *string
221
222 // source.properties under current module will be copied to docs out dir, if not null.
223 Static_doc_properties *string
224
Nan Zhang581fd212018-01-10 16:06:12 -0800225 // a list of files under current module source dir which contains known tags in Java sources.
226 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800227 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700228
229 // the tag name used to distinguish if the API files belong to public/system/test.
230 Api_tag_name *string
231
232 // the generated public API filename by Doclava.
233 Api_filename *string
234
David Brazdilfbe4cc32018-05-31 13:56:46 +0100235 // the generated public Dex API filename by Doclava.
236 Dex_api_filename *string
237
Nan Zhang28c68b92018-03-13 16:17:01 -0700238 // the generated private API filename by Doclava.
239 Private_api_filename *string
240
241 // the generated private Dex API filename by Doclava.
242 Private_dex_api_filename *string
243
244 // the generated removed API filename by Doclava.
245 Removed_api_filename *string
246
David Brazdilaac0c3c2018-04-24 16:23:29 +0100247 // the generated removed Dex API filename by Doclava.
248 Removed_dex_api_filename *string
249
Mathew Inwood76c3de12018-06-22 15:28:11 +0100250 // mapping of dex signatures to source file and line number. This is a temporary property and
251 // will be deleted; you probably shouldn't be using it.
252 Dex_mapping_filename *string
253
Nan Zhang28c68b92018-03-13 16:17:01 -0700254 // the generated exact API filename by Doclava.
255 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700256
Nan Zhang66dc2362018-08-14 20:41:04 -0700257 // the generated proguard filename by Doclava.
258 Proguard_filename *string
259
Nan Zhang853f4202018-04-12 16:55:56 -0700260 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
261 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700262
263 Check_api struct {
264 Last_released ApiToCheck
265
266 Current ApiToCheck
267 }
Nan Zhang79614d12018-04-19 18:03:39 -0700268
269 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
270 // currently still used for documentation generation, and will be replaced by Dokka soon.
271 Metalava_enabled *bool
272
273 // user can specify the version of previous released API file in order to do compatibility check.
274 Metalava_previous_api *string
275
276 // is set to true, Metalava will allow framework SDK to contain annotations.
277 Metalava_annotations_enabled *bool
278
Pete Gillinb13a0152018-07-19 17:56:49 +0100279 // a list of top-level directories containing files to merge annotations from.
280 Metalava_merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700281
282 // if set to true, generate docs through Dokka instead of Doclava. Valid only when
283 // metalava_enabled is set to true.
284 Dokka_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800285}
286
Nan Zhanga40da042018-08-01 12:48:00 -0700287//
288// Common flags passed down to build rule
289//
290type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700291 args string
292 bootClasspathArgs string
293 classpathArgs string
294 dokkaClasspathArgs string
295 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700296
Nan Zhanga40da042018-08-01 12:48:00 -0700297 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700298 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700299 postDoclavaCmds string
300
Nan Zhanged0a39d2018-08-23 17:30:38 -0700301 metalavaStubsFlags string
302 metalavaAnnotationsFlags string
303 metalavaJavadocFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700304
Nan Zhang86d2d552018-08-09 15:33:27 -0700305 metalavaDokkaFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700306}
307
308func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
309 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
310 android.InitDefaultableModule(module)
311}
312
313//
314// Javadoc
315//
Nan Zhang581fd212018-01-10 16:06:12 -0800316type Javadoc struct {
317 android.ModuleBase
318 android.DefaultableModuleBase
319
320 properties JavadocProperties
321
322 srcJars android.Paths
323 srcFiles android.Paths
324 sourcepaths android.Paths
325
Nan Zhangccff0f72018-03-08 17:26:16 -0800326 docZip android.WritablePath
327 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800328}
329
Nan Zhangb2b33de2018-02-23 11:18:47 -0800330func (j *Javadoc) Srcs() android.Paths {
331 return android.Paths{j.stubsSrcJar}
332}
333
Nan Zhang581fd212018-01-10 16:06:12 -0800334func JavadocFactory() android.Module {
335 module := &Javadoc{}
336
337 module.AddProperties(&module.properties)
338
339 InitDroiddocModule(module, android.HostAndDeviceSupported)
340 return module
341}
342
343func JavadocHostFactory() android.Module {
344 module := &Javadoc{}
345
346 module.AddProperties(&module.properties)
347
348 InitDroiddocModule(module, android.HostSupported)
349 return module
350}
351
Nan Zhanga40da042018-08-01 12:48:00 -0700352var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800353
Colin Cross83bb3162018-06-25 15:48:06 -0700354func (j *Javadoc) sdkVersion() string {
355 return String(j.properties.Sdk_version)
356}
357
358func (j *Javadoc) minSdkVersion() string {
359 return j.sdkVersion()
360}
361
Nan Zhang581fd212018-01-10 16:06:12 -0800362func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
363 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700364 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800365 if sdkDep.useDefaultLibs {
366 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700367 if ctx.Config().TargetOpenJDK9() {
368 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
369 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700370 if !Bool(j.properties.No_framework_libs) {
Nan Zhang77a69ec2018-08-02 16:28:26 -0700371 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800372 }
Nan Zhang581fd212018-01-10 16:06:12 -0800373 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700374 if ctx.Config().TargetOpenJDK9() {
375 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
376 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700377 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800378 }
379 }
380
381 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700382 if j.properties.Srcs_lib != nil {
383 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
384 }
Nan Zhang581fd212018-01-10 16:06:12 -0800385
386 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
387
388 // exclude_srcs may contain filegroup or genrule.
389 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
390}
391
Nan Zhangb2b33de2018-02-23 11:18:47 -0800392func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
393 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
394 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900395 // convert foo.bar.baz to foo/bar/baz
396 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
397 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800398 if _, found := whitelistPathPrefixes[prefix]; !found {
399 whitelistPathPrefixes[prefix] = true
400 }
401 }
402 }
403}
404
Nan Zhanga40da042018-08-01 12:48:00 -0700405func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
406 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900407
408 // aidl flags.
409 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
410 if len(aidlFlags) > 0 {
411 // optimization.
412 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
413 flags.aidlFlags = "$aidlFlags"
414 }
415
416 return flags
417}
418
419func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
420 aidlIncludeDirs android.Paths) []string {
421
422 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
423 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
424
425 var flags []string
426 if aidlPreprocess.Valid() {
427 flags = append(flags, "-p"+aidlPreprocess.String())
428 } else {
429 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
430 }
431
432 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
433 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
434 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
435 flags = append(flags, "-I"+src.String())
436 }
437
438 return flags
439}
440
441func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700442 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900443
444 outSrcFiles := make(android.Paths, 0, len(srcFiles))
445
446 for _, srcFile := range srcFiles {
447 switch srcFile.Ext() {
448 case ".aidl":
449 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
450 outSrcFiles = append(outSrcFiles, javaFile)
451 default:
452 outSrcFiles = append(outSrcFiles, srcFile)
453 }
454 }
455
456 return outSrcFiles
457}
458
Nan Zhang581fd212018-01-10 16:06:12 -0800459func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
460 var deps deps
461
Colin Cross83bb3162018-06-25 15:48:06 -0700462 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800463 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700464 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800465 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700466 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800467 }
468
469 ctx.VisitDirectDeps(func(module android.Module) {
470 otherName := ctx.OtherModuleName(module)
471 tag := ctx.OtherModuleDependencyTag(module)
472
Colin Cross2d24c1b2018-05-23 10:59:18 -0700473 switch tag {
474 case bootClasspathTag:
475 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800476 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700477 } else {
478 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
479 }
480 case libTag:
481 switch dep := module.(type) {
482 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800483 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700484 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700485 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900486 linkType := javaSdk
487 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
488 linkType = javaSystem
489 } else if sdkVersion == "" {
490 linkType = javaPlatform
491 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900492 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700493 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800494 checkProducesJars(ctx, dep)
495 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800496 default:
497 ctx.ModuleErrorf("depends on non-java module %q", otherName)
498 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700499 case srcsLibTag:
500 switch dep := module.(type) {
501 case Dependency:
502 srcs := dep.(SrcDependency).CompiledSrcs()
503 whitelistPathPrefixes := make(map[string]bool)
504 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
505 for _, src := range srcs {
506 if _, ok := src.(android.WritablePath); ok { // generated sources
507 deps.srcs = append(deps.srcs, src)
508 } else { // select source path for documentation based on whitelist path prefixs.
509 for k, _ := range whitelistPathPrefixes {
510 if strings.HasPrefix(src.Rel(), k) {
511 deps.srcs = append(deps.srcs, src)
512 break
513 }
514 }
515 }
516 }
517 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
518 default:
519 ctx.ModuleErrorf("depends on non-java module %q", otherName)
520 }
Nan Zhang357466b2018-04-17 17:38:36 -0700521 case systemModulesTag:
522 if deps.systemModules != nil {
523 panic("Found two system module dependencies")
524 }
525 sm := module.(*SystemModules)
526 if sm.outputFile == nil {
527 panic("Missing directory for system module dependency")
528 }
529 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800530 }
531 })
532 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
533 // may contain filegroup or genrule.
534 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700535 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900536 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800537
538 // srcs may depend on some genrule output.
539 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800540 j.srcJars = append(j.srcJars, deps.srcJars...)
541
Nan Zhang581fd212018-01-10 16:06:12 -0800542 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800543 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800544
545 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800546 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800547
548 if j.properties.Local_sourcepaths == nil {
549 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
550 }
551 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800552
553 return deps
554}
555
556func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
557 j.addDeps(ctx)
558}
559
560func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
561 deps := j.collectDeps(ctx)
562
563 var implicits android.Paths
564 implicits = append(implicits, deps.bootClasspath...)
565 implicits = append(implicits, deps.classpath...)
566
567 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700568
Colin Cross83bb3162018-06-25 15:48:06 -0700569 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700570 if len(deps.bootClasspath) > 0 {
571 var systemModules classpath
572 if deps.systemModules != nil {
573 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800574 }
Colin Cross997262f2018-06-19 22:49:39 -0700575 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
576 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800577 }
578 if len(deps.classpath.Strings()) > 0 {
579 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
580 }
581
582 implicits = append(implicits, j.srcJars...)
583
Nan Zhangaf322cc2018-06-19 15:15:38 -0700584 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800585
586 ctx.Build(pctx, android.BuildParams{
587 Rule: javadoc,
588 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800589 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800590 ImplicitOutput: j.docZip,
591 Inputs: j.srcFiles,
592 Implicits: implicits,
593 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700594 "outDir": android.PathForModuleOut(ctx, "out").String(),
595 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
596 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800597 "srcJars": strings.Join(j.srcJars.Strings(), " "),
598 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700599 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800600 "classpathArgs": classpathArgs,
601 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
602 "docZip": j.docZip.String(),
603 },
604 })
605}
606
Nan Zhanga40da042018-08-01 12:48:00 -0700607//
608// Droiddoc
609//
610type Droiddoc struct {
611 Javadoc
612
613 properties DroiddocProperties
614 apiFile android.WritablePath
615 dexApiFile android.WritablePath
616 privateApiFile android.WritablePath
617 privateDexApiFile android.WritablePath
618 removedApiFile android.WritablePath
619 removedDexApiFile android.WritablePath
620 exactApiFile android.WritablePath
621 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700622 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700623
624 checkCurrentApiTimestamp android.WritablePath
625 updateCurrentApiTimestamp android.WritablePath
626 checkLastReleasedApiTimestamp android.WritablePath
627
628 annotationsZip android.WritablePath
629
630 apiFilePath android.Path
631}
632
633type ApiFilePath interface {
634 ApiFilePath() android.Path
635}
636
637func DroiddocFactory() android.Module {
638 module := &Droiddoc{}
639
640 module.AddProperties(&module.properties,
641 &module.Javadoc.properties)
642
643 InitDroiddocModule(module, android.HostAndDeviceSupported)
644 return module
645}
646
647func DroiddocHostFactory() android.Module {
648 module := &Droiddoc{}
649
650 module.AddProperties(&module.properties,
651 &module.Javadoc.properties)
652
653 InitDroiddocModule(module, android.HostSupported)
654 return module
655}
656
657func (d *Droiddoc) ApiFilePath() android.Path {
658 return d.apiFilePath
659}
660
Nan Zhang61819ce2018-05-04 18:49:16 -0700661func (d *Droiddoc) checkCurrentApi() bool {
662 if String(d.properties.Check_api.Current.Api_file) != "" &&
663 String(d.properties.Check_api.Current.Removed_api_file) != "" {
664 return true
665 } else if String(d.properties.Check_api.Current.Api_file) != "" {
666 panic("check_api.current.removed_api_file: has to be non empty!")
667 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
668 panic("check_api.current.api_file: has to be non empty!")
669 }
670
671 return false
672}
673
674func (d *Droiddoc) checkLastReleasedApi() bool {
675 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
676 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
677 return true
678 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
679 panic("check_api.last_released.removed_api_file: has to be non empty!")
680 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
681 panic("check_api.last_released.api_file: has to be non empty!")
682 }
683
684 return false
685}
686
Nan Zhang581fd212018-01-10 16:06:12 -0800687func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
688 d.Javadoc.addDeps(ctx)
689
Nan Zhang79614d12018-04-19 18:03:39 -0700690 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800691 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
692 }
693
Nan Zhanga40da042018-08-01 12:48:00 -0700694 // arg_files may contains filegroup or genrule.
Nan Zhang581fd212018-01-10 16:06:12 -0800695 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
696
697 // knowntags may contain filegroup or genrule.
698 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700699
Nan Zhange2ba5d42018-07-11 15:16:55 -0700700 if String(d.properties.Static_doc_index_redirect) != "" {
701 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
702 }
703
704 if String(d.properties.Static_doc_properties) != "" {
705 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
706 }
707
Nan Zhang61819ce2018-05-04 18:49:16 -0700708 if d.checkCurrentApi() {
709 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
710 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
711 }
712
713 if d.checkLastReleasedApi() {
714 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
715 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
716 }
Nan Zhang79614d12018-04-19 18:03:39 -0700717
718 if String(d.properties.Metalava_previous_api) != "" {
719 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
720 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700721
722 if len(d.properties.Metalava_merge_annotations_dirs) != 0 {
723 for _, mergeAnnotationsDir := range d.properties.Metalava_merge_annotations_dirs {
724 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
725 }
726 }
Nan Zhang581fd212018-01-10 16:06:12 -0800727}
728
Nan Zhang66dc2362018-08-14 20:41:04 -0700729func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
730 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700731 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800732
Nan Zhanga40da042018-08-01 12:48:00 -0700733 *implicits = append(*implicits, deps.bootClasspath...)
734 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800735
Nan Zhangc94f9d82018-06-26 10:02:26 -0700736 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
737 // since it doesn't support system modules yet.
738 if len(deps.bootClasspath.Strings()) > 0 {
739 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700740 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700741 }
Nan Zhanga40da042018-08-01 12:48:00 -0700742 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang86d2d552018-08-09 15:33:27 -0700743 // Dokka doesn't support boocClasspath, so combine these two classpath vars for Dokka.
744 dokkaClasspath := classpath{}
745 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
746 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
747 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700748
Nan Zhang581fd212018-01-10 16:06:12 -0800749 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
750 argFilesMap := map[string]android.Path{}
751
752 for _, f := range argFiles {
Nan Zhanga40da042018-08-01 12:48:00 -0700753 *implicits = append(*implicits, f)
Nan Zhang581fd212018-01-10 16:06:12 -0800754 if _, exists := argFilesMap[f.Rel()]; !exists {
755 argFilesMap[f.Rel()] = f
756 } else {
757 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
758 f, argFilesMap[f.Rel()], f.Rel())
759 }
760 }
761
Nan Zhanga40da042018-08-01 12:48:00 -0700762 var err error
763 flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) {
Nan Zhang581fd212018-01-10 16:06:12 -0800764 if strings.HasPrefix(name, "location ") {
765 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
766 if f, ok := argFilesMap[label]; ok {
767 return f.String(), nil
768 } else {
769 return "", fmt.Errorf("unknown location label %q", label)
770 }
771 } else if name == "genDir" {
772 return android.PathForModuleGen(ctx).String(), nil
773 }
774 return "", fmt.Errorf("unknown variable '$(%s)'", name)
775 })
776
777 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700778 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhanga40da042018-08-01 12:48:00 -0700779 return droiddocBuilderFlags{}, err
Nan Zhang581fd212018-01-10 16:06:12 -0800780 }
Nan Zhanga40da042018-08-01 12:48:00 -0700781 return flags, nil
782}
Nan Zhang581fd212018-01-10 16:06:12 -0800783
Nan Zhanga40da042018-08-01 12:48:00 -0700784func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700785 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800786
Nan Zhanga40da042018-08-01 12:48:00 -0700787 *implicits = append(*implicits, jsilver)
788 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700789
Nan Zhang46130972018-06-04 11:28:01 -0700790 var date string
791 if runtime.GOOS == "darwin" {
792 date = `date -r`
793 } else {
794 date = `date -d`
795 }
796
Nan Zhang443fa522018-08-20 20:58:28 -0700797 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
798 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
799 // 1.9 language features.
800 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700801 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800802 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700803 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700804
Nan Zhanga40da042018-08-01 12:48:00 -0700805 if String(d.properties.Custom_template) == "" {
806 // TODO: This is almost always droiddoc-templates-sdk
807 ctx.PropertyErrorf("custom_template", "must specify a template")
808 }
809
810 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700811 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700812 *implicits = append(*implicits, t.deps...)
813 args = args + " -templatedir " + t.dir.String()
814 } else {
815 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
816 }
817 })
818
819 if len(d.properties.Html_dirs) > 0 {
820 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
821 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
822 args = args + " -htmldir " + htmlDir.String()
823 }
824
825 if len(d.properties.Html_dirs) > 1 {
826 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
827 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
828 args = args + " -htmldir2 " + htmlDir2.String()
829 }
830
831 if len(d.properties.Html_dirs) > 2 {
832 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
833 }
834
835 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
836 *implicits = append(*implicits, knownTags...)
837
838 for _, kt := range knownTags {
839 args = args + " -knowntags " + kt.String()
840 }
841
842 for _, hdf := range d.properties.Hdf {
843 args = args + " -hdf " + hdf
844 }
845
846 if String(d.properties.Proofread_file) != "" {
847 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
848 args = args + " -proofread " + proofreadFile.String()
849 }
850
851 if String(d.properties.Todo_file) != "" {
852 // tricky part:
853 // we should not compute full path for todo_file through PathForModuleOut().
854 // the non-standard doclet will get the full path relative to "-o".
855 args = args + " -todo " + String(d.properties.Todo_file)
856 }
857
858 if String(d.properties.Resourcesdir) != "" {
859 // TODO: should we add files under resourcesDir to the implicits? It seems that
860 // resourcesDir is one sub dir of htmlDir
861 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
862 args = args + " -resourcesdir " + resourcesDir.String()
863 }
864
865 if String(d.properties.Resourcesoutdir) != "" {
866 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
867 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
868 }
869 return args
870}
871
872func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) {
873 var doclavaFlags, MetalavaFlags string
874 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
875 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
876 doclavaFlags += " -api " + d.apiFile.String()
877 MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String()
878 *implicitOutputs = append(*implicitOutputs, d.apiFile)
879 d.apiFilePath = d.apiFile
880 }
881
882 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
883 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
884 doclavaFlags += " -removedApi " + d.removedApiFile.String()
885 MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String()
886 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
887 }
888
889 if String(d.properties.Private_api_filename) != "" {
890 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
891 doclavaFlags += " -privateApi " + d.privateApiFile.String()
892 MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String()
893 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
894 }
895
896 if String(d.properties.Dex_api_filename) != "" {
897 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
898 doclavaFlags += " -dexApi " + d.dexApiFile.String()
899 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
900 }
901
902 if String(d.properties.Private_dex_api_filename) != "" {
903 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
904 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
905 MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
906 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
907 }
908
909 if String(d.properties.Removed_dex_api_filename) != "" {
910 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
911 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
912 MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
913 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
914 }
915
916 if String(d.properties.Exact_api_filename) != "" {
917 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
918 doclavaFlags += " -exactApi " + d.exactApiFile.String()
919 MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String()
920 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
921 }
922
923 if String(d.properties.Dex_mapping_filename) != "" {
924 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
925 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
926 // Omitted: metalava support
927 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
928 }
929
Nan Zhang66dc2362018-08-14 20:41:04 -0700930 if String(d.properties.Proguard_filename) != "" {
931 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
932 doclavaFlags += " -proguard " + d.proguardFile.String()
933 // Omitted: metalava support
934 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
935 }
936
Nan Zhanga40da042018-08-01 12:48:00 -0700937 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -0700938 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700939 }
940
941 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -0700942 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700943 }
944 return doclavaFlags, MetalavaFlags
945}
946
947func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
948 var cmds string
949 if String(d.properties.Static_doc_index_redirect) != "" {
950 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
951 "static_doc_index_redirect")
952 *implicits = append(*implicits, static_doc_index_redirect)
953 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700954 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700955 }
956
957 if String(d.properties.Static_doc_properties) != "" {
958 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
959 "static_doc_properties")
960 *implicits = append(*implicits, static_doc_properties)
961 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700962 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700963 }
964 return cmds
965}
966
967func (d *Droiddoc) collectMetalavaAnnotationsFlags(
968 ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
969 var flags string
Nan Zhanga40da042018-08-01 12:48:00 -0700970 if Bool(d.properties.Metalava_annotations_enabled) {
971 if String(d.properties.Metalava_previous_api) == "" {
972 ctx.PropertyErrorf("metalava_previous_api",
973 "has to be non-empty if annotations was enabled!")
974 }
Nan Zhangde860a42018-08-08 16:32:21 -0700975 previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api),
976 "metalava_previous_api")
977 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -0700978
Nan Zhangd05a4362018-08-15 13:28:54 -0700979 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700980
981 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
982 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
983
Nan Zhangf4936b02018-08-01 15:00:28 -0700984 flags += " --extract-annotations " + d.annotationsZip.String()
985
Nan Zhanga40da042018-08-01 12:48:00 -0700986 if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
987 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
988 "has to be non-empty if annotations was enabled!")
989 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700990 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
991 if t, ok := m.(*ExportedDroiddocDir); ok {
992 *implicits = append(*implicits, t.deps...)
993 flags += " --merge-annotations " + t.dir.String()
994 } else {
995 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
996 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
997 }
998 })
Nan Zhanga40da042018-08-01 12:48:00 -0700999 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1000 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1001 }
1002
1003 return flags
1004}
1005
Nan Zhang86d2d552018-08-09 15:33:27 -07001006func (d *Droiddoc) collectMetalavaJavadocFlags(ctx android.ModuleContext,
Nan Zhangde860a42018-08-08 16:32:21 -07001007 bootClasspathArgs, classpathArgs, outDir, docStubsDir string) string {
1008 return " --doc-stubs " + docStubsDir +
1009 " --write-doc-stubs-source-list " + android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
Nan Zhanga40da042018-08-01 12:48:00 -07001010 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
1011 bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhangde860a42018-08-08 16:32:21 -07001012 docStubsDir + " -quiet -d " + outDir
Nan Zhanga40da042018-08-01 12:48:00 -07001013}
1014
Nan Zhang86d2d552018-08-09 15:33:27 -07001015func (d *Droiddoc) collectMetalavaDokkaFlags(ctx android.ModuleContext, implicits *android.Paths,
1016 classpathArgs, outDir, docStubsDir string) string {
1017 dokka := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "dokka.jar")
1018 *implicits = append(*implicits, dokka)
1019
1020 return " --doc-stubs " + docStubsDir + " --write-doc-stubs-source-list " +
1021 android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
1022 " --generate-documentation ${config.JavaCmd} -jar " + dokka.String() + " " +
1023 docStubsDir + " " + classpathArgs + " -format dac -dacRoot /reference/kotlin -output " + outDir
1024}
1025
1026func (d *Droiddoc) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1027 implicitOutputs android.WritablePaths, outDir, docStubsDir, javaVersion,
1028 bootclasspathArgs, classpathArgs, opts string) {
1029 ctx.Build(pctx, android.BuildParams{
1030 Rule: metalava,
1031 Description: "Metalava",
1032 Output: d.Javadoc.stubsSrcJar,
1033 Inputs: d.Javadoc.srcFiles,
1034 Implicits: implicits,
1035 ImplicitOutputs: implicitOutputs,
1036 Args: map[string]string{
1037 "outDir": outDir,
1038 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1039 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1040 "docStubsDir": docStubsDir,
1041 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1042 "javaVersion": javaVersion,
1043 "bootclasspathArgs": bootclasspathArgs,
1044 "classpathArgs": classpathArgs,
1045 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1046 "docZip": d.Javadoc.docZip.String(),
1047 "opts": opts,
1048 },
1049 })
1050}
1051
1052func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1053 implicitOutputs android.WritablePaths, bootclasspathArgs, classpathArgs, opts, postDoclavaCmds string) {
1054 ctx.Build(pctx, android.BuildParams{
1055 Rule: javadoc,
1056 Description: "Doclava",
1057 Output: d.Javadoc.stubsSrcJar,
1058 Inputs: d.Javadoc.srcFiles,
1059 Implicits: implicits,
1060 ImplicitOutputs: implicitOutputs,
1061 Args: map[string]string{
1062 "outDir": android.PathForModuleOut(ctx, "out").String(),
1063 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1064 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1065 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1066 "opts": opts,
1067 "bootclasspathArgs": bootclasspathArgs,
1068 "classpathArgs": classpathArgs,
1069 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1070 "docZip": d.Javadoc.docZip.String(),
1071 "postDoclavaCmds": postDoclavaCmds,
1072 },
1073 })
1074}
1075
1076func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1077 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1078 ctx.Build(pctx, android.BuildParams{
1079 Rule: apiCheck,
Nan Zhanga05ff572018-08-20 20:33:38 -07001080 Description: "Doclava Check API",
Nan Zhang86d2d552018-08-09 15:33:27 -07001081 Output: output,
1082 Inputs: nil,
1083 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1084 checkApiClasspath...),
1085 Args: map[string]string{
1086 "classpath": checkApiClasspath.FormJavaClassPath(""),
1087 "opts": opts,
1088 "apiFile": apiFile.String(),
1089 "apiFileToCheck": d.apiFile.String(),
1090 "removedApiFile": removedApiFile.String(),
1091 "removedApiFileToCheck": d.removedApiFile.String(),
1092 "msg": msg,
1093 },
1094 })
1095}
1096
Nan Zhanged0a39d2018-08-23 17:30:38 -07001097func (d *Droiddoc) transformMetalavaCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1098 msg, opts string, output android.WritablePath) {
1099 ctx.Build(pctx, android.BuildParams{
1100 Rule: metalavaApiCheck,
1101 Description: "Metalava Check API",
1102 Output: output,
1103 Inputs: nil,
1104 Implicits: android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1105 Args: map[string]string{
1106 "opts": opts,
1107 "msg": msg,
1108 },
1109 })
1110}
1111
Nan Zhang86d2d552018-08-09 15:33:27 -07001112func (d *Droiddoc) transformUpdateApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1113 output android.WritablePath) {
1114 ctx.Build(pctx, android.BuildParams{
1115 Rule: updateApi,
1116 Description: "Update API",
1117 Output: output,
1118 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1119 Args: map[string]string{
1120 "apiFile": apiFile.String(),
1121 "apiFileToCheck": d.apiFile.String(),
1122 "removedApiFile": removedApiFile.String(),
1123 "removedApiFileToCheck": d.removedApiFile.String(),
1124 },
1125 })
1126}
1127
Nan Zhanga40da042018-08-01 12:48:00 -07001128func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1129 deps := d.Javadoc.collectDeps(ctx)
1130
1131 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhanga40da042018-08-01 12:48:00 -07001132 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1133 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1134 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1135 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
Nan Zhang581fd212018-01-10 16:06:12 -08001136
Nan Zhanga40da042018-08-01 12:48:00 -07001137 var implicits android.Paths
1138 implicits = append(implicits, d.Javadoc.srcJars...)
1139
1140 var implicitOutputs android.WritablePaths
1141 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1142 for _, o := range d.properties.Out {
1143 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1144 }
1145
1146 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1147 if err != nil {
1148 return
1149 }
1150
1151 flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1152 if Bool(d.properties.Metalava_enabled) {
Nan Zhanga40da042018-08-01 12:48:00 -07001153 flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang86d2d552018-08-09 15:33:27 -07001154 outDir := android.PathForModuleOut(ctx, "out").String()
Nan Zhangde860a42018-08-08 16:32:21 -07001155 docStubsDir := android.PathForModuleOut(ctx, "docStubsDir").String()
Nan Zhang86d2d552018-08-09 15:33:27 -07001156 // TODO(nanzhang): Add a Soong property to handle documentation args.
1157 if strings.Contains(flags.args, "--generate-documentation") { // enable docs generation
1158 if Bool(d.properties.Dokka_enabled) {
1159 flags.metalavaDokkaFlags = d.collectMetalavaDokkaFlags(ctx, &implicits,
1160 flags.dokkaClasspathArgs, outDir, docStubsDir)
1161 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1162 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhanged0a39d2018-08-23 17:30:38 -07001163 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001164 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001165 flags.metalavaDokkaFlags+" "+strings.Split(flags.args, "--generate-documentation")[1])
1166 } else {
1167 flags.metalavaJavadocFlags = d.collectMetalavaJavadocFlags(
1168 ctx, flags.bootClasspathArgs, flags.classpathArgs, outDir, docStubsDir)
Nan Zhang443fa522018-08-20 20:58:28 -07001169 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhang86d2d552018-08-09 15:33:27 -07001170 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1171 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhanged0a39d2018-08-23 17:30:38 -07001172 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001173 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001174 flags.metalavaJavadocFlags+flags.doclavaDocsFlags+
1175 " "+strings.Split(flags.args, "--generate-documentation")[1])
1176 }
Nan Zhanga40da042018-08-01 12:48:00 -07001177 } else {
Nan Zhang86d2d552018-08-09 15:33:27 -07001178 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1179 flags.bootClasspathArgs, flags.classpathArgs,
Nan Zhanged0a39d2018-08-23 17:30:38 -07001180 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+flags.args)
Nan Zhang79614d12018-04-19 18:03:39 -07001181 }
Nan Zhanga40da042018-08-01 12:48:00 -07001182 } else {
Nan Zhang443fa522018-08-20 20:58:28 -07001183 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhanga40da042018-08-01 12:48:00 -07001184 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
Nan Zhang86d2d552018-08-09 15:33:27 -07001185 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1186 flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+flags.args,
1187 flags.postDoclavaCmds)
Nan Zhang79614d12018-04-19 18:03:39 -07001188 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001189
Nan Zhang61819ce2018-05-04 18:49:16 -07001190 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001191 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1192 "check_api.current.api_file")
1193 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1194 "check_api.current_removed_api_file")
1195
Nan Zhanged0a39d2018-08-23 17:30:38 -07001196 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang55e0bf42018-08-16 16:23:11 -07001197 if !Bool(d.properties.Metalava_enabled) {
Nan Zhang55e0bf42018-08-16 16:23:11 -07001198 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1199 fmt.Sprintf(`\n******************************\n`+
1200 `You have tried to change the API from what has been previously approved.\n\n`+
1201 `To make these errors go away, you have two choices:\n`+
1202 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1203 ` errors above.\n\n`+
1204 ` 2. You can update current.txt by executing the following command:\n`+
1205 ` make %s-update-current-api\n\n`+
1206 ` To submit the revised current.txt to the main Android repository,\n`+
1207 ` you will need approval.\n`+
1208 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1209 d.checkCurrentApiTimestamp)
Nan Zhanged0a39d2018-08-23 17:30:38 -07001210 } else {
1211 opts := " --check-compatibility:api:current " + apiFile.String() +
1212 " --check-compatibility:removed:current " + removedApiFile.String() + " "
1213
1214 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile,
1215 fmt.Sprintf(`\n******************************\n`+
1216 `You have tried to change the API from what has been previously approved.\n\n`+
1217 `To make these errors go away, you have two choices:\n`+
1218 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1219 ` errors above.\n\n`+
1220 ` 2. You can update current.txt by executing the following command:\n`+
1221 ` make %s-update-current-api\n\n`+
1222 ` To submit the revised current.txt to the main Android repository,\n`+
1223 ` you will need approval.\n`+
1224 `******************************\n`, ctx.ModuleName()), opts,
1225 d.checkCurrentApiTimestamp)
Nan Zhang55e0bf42018-08-16 16:23:11 -07001226 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001227
1228 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang86d2d552018-08-09 15:33:27 -07001229 d.transformUpdateApi(ctx, apiFile, removedApiFile, d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001230 }
Nan Zhanga40da042018-08-01 12:48:00 -07001231
Nan Zhang61819ce2018-05-04 18:49:16 -07001232 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001233 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1234 "check_api.last_released.api_file")
1235 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1236 "check_api.last_released.removed_api_file")
1237
Nan Zhanged0a39d2018-08-23 17:30:38 -07001238 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhanga05ff572018-08-20 20:33:38 -07001239 if !Bool(d.properties.Metalava_enabled) {
Nan Zhanga05ff572018-08-20 20:33:38 -07001240 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1241 `\n******************************\n`+
1242 `You have tried to change the API from what has been previously released in\n`+
1243 `an SDK. Please fix the errors listed above.\n`+
1244 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1245 d.checkLastReleasedApiTimestamp)
Nan Zhanged0a39d2018-08-23 17:30:38 -07001246 } else {
1247 opts := " --check-compatibility:api:released " + apiFile.String() +
1248 " --check-compatibility:removed:released " + removedApiFile.String() + " "
1249
1250 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile,
1251 `\n******************************\n`+
1252 `You have tried to change the API from what has been previously released in\n`+
1253 `an SDK. Please fix the errors listed above.\n`+
1254 `******************************\n`, opts,
1255 d.checkLastReleasedApiTimestamp)
Nan Zhanga05ff572018-08-20 20:33:38 -07001256 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001257 }
Nan Zhang581fd212018-01-10 16:06:12 -08001258}
Dan Willemsencc090972018-02-26 14:33:31 -08001259
Nan Zhanga40da042018-08-01 12:48:00 -07001260//
Nan Zhangf4936b02018-08-01 15:00:28 -07001261// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001262//
Dan Willemsencc090972018-02-26 14:33:31 -08001263var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001264var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001265
Nan Zhangf4936b02018-08-01 15:00:28 -07001266type ExportedDroiddocDirProperties struct {
1267 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001268 Path *string
1269}
1270
Nan Zhangf4936b02018-08-01 15:00:28 -07001271type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001272 android.ModuleBase
1273
Nan Zhangf4936b02018-08-01 15:00:28 -07001274 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001275
1276 deps android.Paths
1277 dir android.Path
1278}
1279
Nan Zhangf4936b02018-08-01 15:00:28 -07001280func ExportedDroiddocDirFactory() android.Module {
1281 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001282 module.AddProperties(&module.properties)
1283 android.InitAndroidModule(module)
1284 return module
1285}
1286
Nan Zhangf4936b02018-08-01 15:00:28 -07001287func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001288
Nan Zhangf4936b02018-08-01 15:00:28 -07001289func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001290 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1291 d.dir = path
1292 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1293}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001294
1295//
1296// Defaults
1297//
1298type DocDefaults struct {
1299 android.ModuleBase
1300 android.DefaultsModuleBase
1301}
1302
1303func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1304}
1305
1306func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1307}
1308
1309func DocDefaultsFactory() android.Module {
1310 module := &DocDefaults{}
1311
1312 module.AddProperties(
1313 &JavadocProperties{},
1314 &DroiddocProperties{},
1315 )
1316
1317 android.InitDefaultsModule(module)
1318
1319 return module
1320}