blob: 96639220a93620003bfa0c59837126da6b41db22 [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 (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Jeongik Cha6bd33c12019-06-25 16:26:18 +090022 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080023
Colin Crossab054432019-07-15 16:13:59 -070024 "android/soong/android"
25 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080026)
27
28func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000029 RegisterDocsBuildComponents(android.InitRegistrationContext)
Nan Zhang581fd212018-01-10 16:06:12 -080030}
31
Paul Duffin884363e2019-12-19 10:21:09 +000032func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
33 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
34
35 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
36 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
37 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
38 ctx.RegisterModuleType("javadoc", JavadocFactory)
39 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
40}
41
Nan Zhang581fd212018-01-10 16:06:12 -080042type JavadocProperties struct {
43 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
44 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080045 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080046
Nan Zhang581fd212018-01-10 16:06:12 -080047 // list of source files that should not be used to build the Java module.
48 // This is most useful in the arch/multilib variants to remove non-common files
49 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080050 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080051
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090052 // list of package names that should actually be used. If this property is left unspecified,
53 // all the sources from the srcs property is used.
54 Filter_packages []string
55
Nan Zhangb2b33de2018-02-23 11:18:47 -080056 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080057 Libs []string `android:"arch_variant"`
58
59 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080060 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080061
Paul Duffine25c6442019-10-11 13:50:28 +010062 // if not blank, set to the version of the sdk to compile against.
63 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080064 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090065
Paul Duffine25c6442019-10-11 13:50:28 +010066 // When targeting 1.9 and above, override the modules to use with --system,
67 // otherwise provides defaults libraries to add to the bootclasspath.
68 // Defaults to "none"
69 System_modules *string
70
Jiyong Park1e440682018-05-23 18:42:04 +090071 Aidl struct {
72 // Top level directories to pass to aidl tool
73 Include_dirs []string
74
75 // Directories rooted at the Android.bp file to pass to aidl tool
76 Local_include_dirs []string
77 }
Nan Zhang357466b2018-04-17 17:38:36 -070078
79 // If not blank, set the java version passed to javadoc as -source
80 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -070081
82 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -080083 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -070084
Liz Kammer585cac22020-07-06 09:12:57 -070085 // user customized droiddoc args. Deprecated, use flags instead.
Nan Zhang1598a9e2018-09-04 17:14:32 -070086 // Available variables for substitution:
87 //
88 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -070089 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -070090 Args *string
91
Liz Kammer585cac22020-07-06 09:12:57 -070092 // user customized droiddoc args. Not compatible with property args.
93 // Available variables for substitution:
94 //
95 // $(location <label>): the path to the arg_files with name <label>
96 // $$: a literal $
97 Flags []string
98
Nan Zhang1598a9e2018-09-04 17:14:32 -070099 // names of the output files used in args that will be generated
100 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800101}
102
Nan Zhang61819ce2018-05-04 18:49:16 -0700103type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900104 // path to the API txt file that the new API extracted from source code is checked
105 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800106 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700107
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900108 // path to the API txt file that the new @removed API extractd from source code is
109 // checked against. The path can be local to the module or from other module (via
110 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800111 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700112
Adrian Roos14f75a92019-08-12 17:54:09 +0200113 // If not blank, path to the baseline txt file for approved API check violations.
114 Baseline_file *string `android:"path"`
115
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900116 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700117 Args *string
118}
119
Nan Zhang581fd212018-01-10 16:06:12 -0800120type DroiddocProperties struct {
121 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800122 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800123
Nan Zhanga40da042018-08-01 12:48:00 -0700124 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800125 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800126
127 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800128 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800129
130 // proofread file contains all of the text content of the javadocs concatenated into one file,
131 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700132 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // a todo file lists the program elements that are missing documentation.
135 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800136 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800137
138 // directory under current module source that provide additional resources (images).
139 Resourcesdir *string
140
141 // resources output directory under out/soong/.intermediates.
142 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800143
Nan Zhange2ba5d42018-07-11 15:16:55 -0700144 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800145 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700146
147 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800148 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700149
Nan Zhang581fd212018-01-10 16:06:12 -0800150 // a list of files under current module source dir which contains known tags in Java sources.
151 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800152 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700153
Nan Zhang1598a9e2018-09-04 17:14:32 -0700154 // if set to true, generate docs through Dokka instead of Doclava.
155 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000156
157 // Compat config XML. Generates compat change documentation if set.
158 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700159}
160
Nan Zhanga40da042018-08-01 12:48:00 -0700161//
162// Common flags passed down to build rule
163//
164type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700165 bootClasspathArgs string
166 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700167 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700168 dokkaClasspathArgs string
169 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700170 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700171
Nan Zhanga40da042018-08-01 12:48:00 -0700172 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700173 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700174 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700175}
176
177func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
178 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
179 android.InitDefaultableModule(module)
180}
181
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200182func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
183 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
184 return false
185 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700186 return true
187 } else if String(apiToCheck.Api_file) != "" {
188 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
189 } else if String(apiToCheck.Removed_api_file) != "" {
190 panic("for " + apiVersionTag + " api_file has to be non-empty!")
191 }
192
193 return false
194}
195
Nan Zhanga40da042018-08-01 12:48:00 -0700196//
197// Javadoc
198//
Nan Zhang581fd212018-01-10 16:06:12 -0800199type Javadoc struct {
200 android.ModuleBase
201 android.DefaultableModuleBase
202
203 properties JavadocProperties
204
205 srcJars android.Paths
206 srcFiles android.Paths
207 sourcepaths android.Paths
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400208 implicits android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700209
Nan Zhangccff0f72018-03-08 17:26:16 -0800210 docZip android.WritablePath
211 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800212}
213
Colin Cross41955e82019-05-29 14:40:35 -0700214func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
215 switch tag {
216 case "":
217 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700218 case ".docs.zip":
219 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700220 default:
221 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
222 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800223}
224
Colin Crossa3002fc2019-07-08 16:48:04 -0700225// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800226func JavadocFactory() android.Module {
227 module := &Javadoc{}
228
229 module.AddProperties(&module.properties)
230
231 InitDroiddocModule(module, android.HostAndDeviceSupported)
232 return module
233}
234
Colin Crossa3002fc2019-07-08 16:48:04 -0700235// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800236func JavadocHostFactory() android.Module {
237 module := &Javadoc{}
238
239 module.AddProperties(&module.properties)
240
241 InitDroiddocModule(module, android.HostSupported)
242 return module
243}
244
Colin Cross41955e82019-05-29 14:40:35 -0700245var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800246
Jiyong Park92315372021-04-02 08:45:46 +0900247func (j *Javadoc) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
248 return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700249}
250
Jiyong Parkf1691d22021-03-29 20:11:58 +0900251func (j *Javadoc) SystemModules() string {
Paul Duffine25c6442019-10-11 13:50:28 +0100252 return proptools.String(j.properties.System_modules)
253}
254
Jiyong Park92315372021-04-02 08:45:46 +0900255func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
256 return j.SdkVersion(ctx)
Colin Cross83bb3162018-06-25 15:48:06 -0700257}
258
William Loh5a082f92022-05-17 20:21:50 +0000259func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec {
260 return j.SdkVersion(ctx)
261}
262
Jiyong Park92315372021-04-02 08:45:46 +0900263func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
264 return j.SdkVersion(ctx)
Dan Willemsen419290a2018-10-31 15:28:47 -0700265}
266
Nan Zhang581fd212018-01-10 16:06:12 -0800267func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
268 if ctx.Device() {
Jiyong Parkf1691d22021-03-29 20:11:58 +0900269 sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
Pete Gilline3d44b22020-06-29 11:28:51 +0100270 if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700271 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100272 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700273 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Pete Gilline3d44b22020-06-29 11:28:51 +0100274 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800275 }
276 }
277
Colin Cross42d48b72018-08-29 14:10:52 -0700278 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800279}
280
Nan Zhanga40da042018-08-01 12:48:00 -0700281func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
282 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900283
Colin Cross3047fa22019-04-18 10:56:44 -0700284 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900285
286 return flags
287}
288
289func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700290 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900291
292 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
293 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
294
295 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700296 var deps android.Paths
297
Jiyong Park1e440682018-05-23 18:42:04 +0900298 if aidlPreprocess.Valid() {
299 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700300 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900301 } else {
302 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
303 }
304
305 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
306 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
307 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
308 flags = append(flags, "-I"+src.String())
309 }
310
Colin Cross3047fa22019-04-18 10:56:44 -0700311 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900312}
313
Jiyong Parkd90d7412019-08-20 22:49:19 +0900314// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900315func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700316 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900317
318 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700319 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900320
Jiyong Park1112c4c2019-08-16 21:12:10 +0900321 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
322
Jiyong Park1e440682018-05-23 18:42:04 +0900323 for _, srcFile := range srcFiles {
324 switch srcFile.Ext() {
325 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700326 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900327 case ".logtags":
328 javaFile := genLogtags(ctx, srcFile)
329 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900330 default:
331 outSrcFiles = append(outSrcFiles, srcFile)
332 }
333 }
334
Colin Crossc0806172019-06-14 18:51:47 -0700335 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
336 if len(aidlSrcs) > 0 {
Thiébaud Weksteende8417c2022-02-10 15:41:46 +1100337 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, nil, flags.aidlDeps)
Colin Crossc0806172019-06-14 18:51:47 -0700338 outSrcFiles = append(outSrcFiles, srcJarFiles...)
339 }
340
Jiyong Park1e440682018-05-23 18:42:04 +0900341 return outSrcFiles
342}
343
Nan Zhang581fd212018-01-10 16:06:12 -0800344func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
345 var deps deps
346
Jiyong Parkf1691d22021-03-29 20:11:58 +0900347 sdkDep := decodeSdkDep(ctx, android.SdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800348 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700349 ctx.AddMissingDependencies(sdkDep.bootclasspath)
350 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800351 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700352 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000353 deps.aidlPreprocess = sdkDep.aidl
354 } else {
355 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800356 }
357
358 ctx.VisitDirectDeps(func(module android.Module) {
359 otherName := ctx.OtherModuleName(module)
360 tag := ctx.OtherModuleDependencyTag(module)
361
Colin Cross2d24c1b2018-05-23 10:59:18 -0700362 switch tag {
363 case bootClasspathTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800364 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
365 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
366 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000367 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100368 // A system modules dependency has been added to the bootclasspath
369 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000370 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700371 } else {
372 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
373 }
374 case libTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800375 if dep, ok := module.(SdkLibraryDependency); ok {
Jiyong Park92315372021-04-02 08:45:46 +0900376 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...)
Colin Crossdcf71b22021-02-01 13:59:03 -0800377 } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
378 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
379 deps.classpath = append(deps.classpath, dep.HeaderJars...)
380 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
381 } else if dep, ok := module.(android.SourceFileProducer); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800382 checkProducesJars(ctx, dep)
383 deps.classpath = append(deps.classpath, dep.Srcs()...)
Colin Crossdcf71b22021-02-01 13:59:03 -0800384 } else {
Nan Zhang581fd212018-01-10 16:06:12 -0800385 ctx.ModuleErrorf("depends on non-java module %q", otherName)
386 }
Colin Cross6cef4812019-10-17 14:23:50 -0700387 case java9LibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800388 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
389 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
390 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
391 } else {
Colin Cross6cef4812019-10-17 14:23:50 -0700392 ctx.ModuleErrorf("depends on non-java module %q", otherName)
393 }
Nan Zhang357466b2018-04-17 17:38:36 -0700394 case systemModulesTag:
395 if deps.systemModules != nil {
396 panic("Found two system module dependencies")
397 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000398 sm := module.(SystemModulesProvider)
399 outputDir, outputDeps := sm.OutputDirAndDeps()
400 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800401 }
402 })
403 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
404 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800405 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400406 j.implicits = append(j.implicits, srcFiles...)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900407
408 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
409 if filterPackages == nil {
410 return srcs
411 }
412 filtered := []android.Path{}
413 for _, src := range srcs {
414 if src.Ext() != ".java" {
415 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
416 // but otherwise metalava emits stub sources having references to the generated AIDL classes
417 // in filtered-out pacages (e.g. com.android.internal.*).
418 // TODO(b/141149570) We need to fix this by introducing default private constructors or
419 // fixing metalava to not emit constructors having references to unknown classes.
420 filtered = append(filtered, src)
421 continue
422 }
423 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800424 if android.HasAnyPrefix(packageName, filterPackages) {
425 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900426 }
427 }
428 return filtered
429 }
430 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
431
Liz Kammer585cac22020-07-06 09:12:57 -0700432 aidlFlags := j.collectAidlFlags(ctx, deps)
433 srcFiles = j.genSources(ctx, srcFiles, aidlFlags)
Nan Zhang581fd212018-01-10 16:06:12 -0800434
435 // srcs may depend on some genrule output.
436 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800437 j.srcJars = append(j.srcJars, deps.srcJars...)
438
Nan Zhang581fd212018-01-10 16:06:12 -0800439 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800440 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800441
Liz Kammere1ab2502020-09-10 15:29:25 +0000442 if len(j.srcFiles) > 0 {
443 j.sourcepaths = android.PathsForModuleSrc(ctx, []string{"."})
Nan Zhang581fd212018-01-10 16:06:12 -0800444 }
Nan Zhang581fd212018-01-10 16:06:12 -0800445
Colin Crossbc139922021-03-25 18:33:16 -0700446 return deps
447}
448
449func (j *Javadoc) expandArgs(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
450 var argFiles android.Paths
Paul Duffin99e4a502019-02-11 15:38:42 +0000451 argFilesMap := map[string]string{}
452 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700453
Paul Duffin99e4a502019-02-11 15:38:42 +0000454 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800455 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000456 if _, exists := argFilesMap[label]; !exists {
Colin Crossbc139922021-03-25 18:33:16 -0700457 argFilesMap[label] = strings.Join(cmd.PathsForInputs(paths), " ")
Paul Duffin99e4a502019-02-11 15:38:42 +0000458 argFileLabels = append(argFileLabels, label)
Colin Crossbc139922021-03-25 18:33:16 -0700459 argFiles = append(argFiles, paths...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700460 } else {
461 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000462 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700463 }
464 }
465
Liz Kammer585cac22020-07-06 09:12:57 -0700466 var argsPropertyName string
467 flags := make([]string, 0)
468 if j.properties.Args != nil && j.properties.Flags != nil {
469 ctx.PropertyErrorf("args", "flags is set. Cannot set args")
470 } else if args := proptools.String(j.properties.Args); args != "" {
471 flags = append(flags, args)
472 argsPropertyName = "args"
473 } else {
474 flags = append(flags, j.properties.Flags...)
475 argsPropertyName = "flags"
476 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700477
Liz Kammer585cac22020-07-06 09:12:57 -0700478 for _, flag := range flags {
Colin Crossbc139922021-03-25 18:33:16 -0700479 expanded, err := android.Expand(flag, func(name string) (string, error) {
Liz Kammer585cac22020-07-06 09:12:57 -0700480 if strings.HasPrefix(name, "location ") {
481 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
482 if paths, ok := argFilesMap[label]; ok {
483 return paths, nil
484 } else {
485 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
486 label, strings.Join(argFileLabels, ", "))
487 }
488 } else if name == "genDir" {
489 return android.PathForModuleGen(ctx).String(), nil
490 }
491 return "", fmt.Errorf("unknown variable '$(%s)'", name)
492 })
493
494 if err != nil {
495 ctx.PropertyErrorf(argsPropertyName, "%s", err.Error())
496 }
Colin Crossbc139922021-03-25 18:33:16 -0700497 cmd.Flag(expanded)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700498 }
499
Colin Crossbc139922021-03-25 18:33:16 -0700500 cmd.Implicits(argFiles)
Nan Zhang581fd212018-01-10 16:06:12 -0800501}
502
503func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
504 j.addDeps(ctx)
505}
506
507func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
508 deps := j.collectDeps(ctx)
509
Colin Crossdaa4c672019-07-15 22:53:46 -0700510 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800511
Colin Crossdaa4c672019-07-15 22:53:46 -0700512 outDir := android.PathForModuleOut(ctx, "out")
513 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
514
515 j.stubsSrcJar = nil
516
Colin Crossf1a035e2020-11-16 17:32:30 -0800517 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossdaa4c672019-07-15 22:53:46 -0700518
519 rule.Command().Text("rm -rf").Text(outDir.String())
520 rule.Command().Text("mkdir -p").Text(outDir.String())
521
522 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700523
Jiyong Parkf1691d22021-03-29 20:11:58 +0900524 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800525
Colin Crossdaa4c672019-07-15 22:53:46 -0700526 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
527 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800528
Colin Cross1e743852019-10-28 11:37:20 -0700529 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700530 Flag("-J-Xmx1024m").
531 Flag("-XDignore.symbol.file").
532 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800533
Colin Crossbc139922021-03-25 18:33:16 -0700534 j.expandArgs(ctx, cmd)
535
Colin Crossdaa4c672019-07-15 22:53:46 -0700536 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800537 BuiltTool("soong_zip").
Colin Crossdaa4c672019-07-15 22:53:46 -0700538 Flag("-write_if_changed").
539 Flag("-d").
540 FlagWithOutput("-o ", j.docZip).
541 FlagWithArg("-C ", outDir.String()).
542 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700543
Colin Crossdaa4c672019-07-15 22:53:46 -0700544 rule.Restat()
545
546 zipSyncCleanupCmd(rule, srcJarDir)
547
Colin Crossf1a035e2020-11-16 17:32:30 -0800548 rule.Build("javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800549}
550
Nan Zhanga40da042018-08-01 12:48:00 -0700551//
552// Droiddoc
553//
554type Droiddoc struct {
555 Javadoc
556
Liz Kammere1ab2502020-09-10 15:29:25 +0000557 properties DroiddocProperties
Nan Zhanga40da042018-08-01 12:48:00 -0700558}
559
Colin Crossa3002fc2019-07-08 16:48:04 -0700560// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700561func DroiddocFactory() android.Module {
562 module := &Droiddoc{}
563
564 module.AddProperties(&module.properties,
565 &module.Javadoc.properties)
566
567 InitDroiddocModule(module, android.HostAndDeviceSupported)
568 return module
569}
570
Colin Crossa3002fc2019-07-08 16:48:04 -0700571// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700572func DroiddocHostFactory() android.Module {
573 module := &Droiddoc{}
574
575 module.AddProperties(&module.properties,
576 &module.Javadoc.properties)
577
578 InitDroiddocModule(module, android.HostSupported)
579 return module
580}
581
Liz Kammere1ab2502020-09-10 15:29:25 +0000582func (d *Droiddoc) OutputFiles(tag string) (android.Paths, error) {
583 switch tag {
584 case "", ".docs.zip":
585 return android.Paths{d.Javadoc.docZip}, nil
586 default:
587 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
588 }
Nan Zhanga40da042018-08-01 12:48:00 -0700589}
590
Nan Zhang581fd212018-01-10 16:06:12 -0800591func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
592 d.Javadoc.addDeps(ctx)
593
Nan Zhang79614d12018-04-19 18:03:39 -0700594 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800595 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
596 }
Nan Zhang581fd212018-01-10 16:06:12 -0800597}
598
Colin Crossab054432019-07-15 16:13:59 -0700599func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800600 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700601 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
602 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
603 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700604 cmd.FlagWithArg("-source ", "1.8").
605 Flag("-J-Xmx1600m").
606 Flag("-J-XX:-OmitStackTraceInFastThrow").
607 Flag("-XDignore.symbol.file").
608 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
609 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800610 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700611 FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `)
Nan Zhang46130972018-06-04 11:28:01 -0700612
Nan Zhanga40da042018-08-01 12:48:00 -0700613 if String(d.properties.Custom_template) == "" {
614 // TODO: This is almost always droiddoc-templates-sdk
615 ctx.PropertyErrorf("custom_template", "must specify a template")
616 }
617
618 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700619 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700620 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700621 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000622 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700623 }
624 })
625
626 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700627 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
628 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
629 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700630 }
631
632 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700633 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
634 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
635 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700636 }
637
638 if len(d.properties.Html_dirs) > 2 {
639 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
640 }
641
Colin Cross8a497952019-03-05 22:25:09 -0800642 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700643 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700644
Colin Crossab054432019-07-15 16:13:59 -0700645 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700646
647 if String(d.properties.Proofread_file) != "" {
648 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700649 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700650 }
651
652 if String(d.properties.Todo_file) != "" {
653 // tricky part:
654 // we should not compute full path for todo_file through PathForModuleOut().
655 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700656 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
657 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700658 }
659
660 if String(d.properties.Resourcesdir) != "" {
661 // TODO: should we add files under resourcesDir to the implicits? It seems that
662 // resourcesDir is one sub dir of htmlDir
663 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700664 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700665 }
666
667 if String(d.properties.Resourcesoutdir) != "" {
668 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700669 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700670 }
Nan Zhanga40da042018-08-01 12:48:00 -0700671}
672
Colin Crossab054432019-07-15 16:13:59 -0700673func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700674 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700675 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
676 rule.Command().Text("cp").
677 Input(staticDocIndexRedirect).
678 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700679 }
680
681 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700682 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
683 rule.Command().Text("cp").
684 Input(staticDocProperties).
685 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700686 }
Nan Zhanga40da042018-08-01 12:48:00 -0700687}
688
Colin Crossab054432019-07-15 16:13:59 -0700689func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700690 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700691
692 cmd := rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800693 BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
Colin Crossab054432019-07-15 16:13:59 -0700694 Flag(config.JavacVmFlags).
695 FlagWithArg("-encoding ", "UTF-8").
Colin Cross70c47412021-03-12 17:48:14 -0800696 FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs).
Colin Crossab054432019-07-15 16:13:59 -0700697 FlagWithInput("@", srcJarList)
698
Colin Crossab054432019-07-15 16:13:59 -0700699 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
700 // based stubs generation.
701 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
702 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
703 // the correct package name base path.
704 if len(sourcepaths) > 0 {
705 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
706 } else {
707 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
708 }
709
710 cmd.FlagWithArg("-d ", outDir.String()).
711 Flag("-quiet")
712
713 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700714}
715
Colin Crossdaa4c672019-07-15 22:53:46 -0700716func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
717 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
718 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
719
720 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
721
722 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
723 cmd.Flag(flag).Implicits(deps)
724
725 cmd.FlagWithArg("--patch-module ", "java.base=.")
726
727 if len(classpath) > 0 {
728 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
729 }
730
731 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700732}
733
Colin Crossdaa4c672019-07-15 22:53:46 -0700734func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
735 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
736 sourcepaths android.Paths) *android.RuleBuilderCommand {
737
738 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
739
740 if len(bootclasspath) == 0 && ctx.Device() {
741 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
742 // ensure java does not fall back to the default bootclasspath.
743 cmd.FlagWithArg("-bootclasspath ", `""`)
744 } else if len(bootclasspath) > 0 {
745 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
746 }
747
748 if len(classpath) > 0 {
749 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
750 }
751
752 return cmd
753}
754
Colin Crossab054432019-07-15 16:13:59 -0700755func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
756 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700757
Colin Crossab054432019-07-15 16:13:59 -0700758 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
759 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
760
761 return rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800762 BuiltTool("dokka").
Colin Crossab054432019-07-15 16:13:59 -0700763 Flag(config.JavacVmFlags).
764 Flag(srcJarDir.String()).
765 FlagWithInputList("-classpath ", dokkaClasspath, ":").
766 FlagWithArg("-format ", "dac").
767 FlagWithArg("-dacRoot ", "/reference/kotlin").
768 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700769}
770
771func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
772 deps := d.Javadoc.collectDeps(ctx)
773
Colin Crossdaa4c672019-07-15 22:53:46 -0700774 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Colin Crossdaa4c672019-07-15 22:53:46 -0700775
Colin Crossae5330a2021-11-03 13:31:22 -0700776 jsilver := ctx.Config().HostJavaToolPath(ctx, "jsilver.jar")
777 doclava := ctx.Config().HostJavaToolPath(ctx, "doclava.jar")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700778
Colin Crossab054432019-07-15 16:13:59 -0700779 outDir := android.PathForModuleOut(ctx, "out")
780 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700781
Colin Crossf1a035e2020-11-16 17:32:30 -0800782 rule := android.NewRuleBuilder(pctx, ctx)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700783
Colin Crossab054432019-07-15 16:13:59 -0700784 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
785
786 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700787 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700788 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700789 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700790 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700791 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700792 }
793
Colin Crossbc139922021-03-25 18:33:16 -0700794 d.expandArgs(ctx, cmd)
Colin Crossab054432019-07-15 16:13:59 -0700795
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000796 if d.properties.Compat_config != nil {
797 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
798 cmd.FlagWithInput("-compatconfig ", compatConfig)
799 }
800
Colin Crossab054432019-07-15 16:13:59 -0700801 var desc string
802 if Bool(d.properties.Dokka_enabled) {
803 desc = "dokka"
804 } else {
805 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
806
807 for _, o := range d.Javadoc.properties.Out {
808 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
809 }
810
811 d.postDoclavaCmds(ctx, rule)
812 desc = "doclava"
813 }
814
815 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800816 BuiltTool("soong_zip").
Colin Crossab054432019-07-15 16:13:59 -0700817 Flag("-write_if_changed").
818 Flag("-d").
819 FlagWithOutput("-o ", d.docZip).
820 FlagWithArg("-C ", outDir.String()).
821 FlagWithArg("-D ", outDir.String())
822
Colin Crossab054432019-07-15 16:13:59 -0700823 rule.Restat()
824
825 zipSyncCleanupCmd(rule, srcJarDir)
826
Colin Crossf1a035e2020-11-16 17:32:30 -0800827 rule.Build("javadoc", desc)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700828}
829
830//
Nan Zhangf4936b02018-08-01 15:00:28 -0700831// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -0700832//
Dan Willemsencc090972018-02-26 14:33:31 -0800833var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
834
Nan Zhangf4936b02018-08-01 15:00:28 -0700835type ExportedDroiddocDirProperties struct {
836 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -0800837 Path *string
838}
839
Nan Zhangf4936b02018-08-01 15:00:28 -0700840type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -0800841 android.ModuleBase
842
Nan Zhangf4936b02018-08-01 15:00:28 -0700843 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -0800844
845 deps android.Paths
846 dir android.Path
847}
848
Colin Crossa3002fc2019-07-08 16:48:04 -0700849// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -0700850func ExportedDroiddocDirFactory() android.Module {
851 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -0800852 module.AddProperties(&module.properties)
853 android.InitAndroidModule(module)
854 return module
855}
856
Nan Zhangf4936b02018-08-01 15:00:28 -0700857func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -0800858
Nan Zhangf4936b02018-08-01 15:00:28 -0700859func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -0800860 path := String(d.properties.Path)
861 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -0800862 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -0800863}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800864
865//
866// Defaults
867//
868type DocDefaults struct {
869 android.ModuleBase
870 android.DefaultsModuleBase
871}
872
Nan Zhangb2b33de2018-02-23 11:18:47 -0800873func DocDefaultsFactory() android.Module {
874 module := &DocDefaults{}
875
876 module.AddProperties(
877 &JavadocProperties{},
878 &DroiddocProperties{},
879 )
880
881 android.InitDefaultsModule(module)
882
883 return module
884}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700885
Colin Cross33961b52019-07-11 11:01:22 -0700886func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
887 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
888
Colin Cross1661aff2021-03-12 17:56:51 -0800889 cmd := rule.Command()
890 cmd.Text("rm -rf").Text(cmd.PathForOutput(srcJarDir))
891 cmd = rule.Command()
892 cmd.Text("mkdir -p").Text(cmd.PathForOutput(srcJarDir))
Colin Cross33961b52019-07-11 11:01:22 -0700893 srcJarList := srcJarDir.Join(ctx, "list")
894
895 rule.Temporary(srcJarList)
896
Colin Cross1661aff2021-03-12 17:56:51 -0800897 cmd = rule.Command()
898 cmd.BuiltTool("zipsync").
899 FlagWithArg("-d ", cmd.PathForOutput(srcJarDir)).
Colin Cross33961b52019-07-11 11:01:22 -0700900 FlagWithOutput("-l ", srcJarList).
901 FlagWithArg("-f ", `"*.java"`).
902 Inputs(srcJars)
903
904 return srcJarList
905}
906
907func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
908 rule.Command().Text("rm -rf").Text(srcJarDir.String())
909}