blob: a8e2b0e4801f8a808a95862d6c240f3300e6b98b [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
Ramy Medhat2f99eec2020-06-13 17:38:27 -0400101
102 // If set, metalava is sandboxed to only read files explicitly specified on the command
103 // line. Defaults to false.
104 Sandbox *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800105}
106
Nan Zhang61819ce2018-05-04 18:49:16 -0700107type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900108 // path to the API txt file that the new API extracted from source code is checked
109 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800110 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700111
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900112 // path to the API txt file that the new @removed API extractd from source code is
113 // checked against. The path can be local to the module or from other module (via
114 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800115 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700116
Adrian Roos14f75a92019-08-12 17:54:09 +0200117 // If not blank, path to the baseline txt file for approved API check violations.
118 Baseline_file *string `android:"path"`
119
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900120 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700121 Args *string
122}
123
Nan Zhang581fd212018-01-10 16:06:12 -0800124type DroiddocProperties struct {
125 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800126 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800127
Nan Zhanga40da042018-08-01 12:48:00 -0700128 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800129 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800130
131 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // proofread file contains all of the text content of the javadocs concatenated into one file,
135 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700136 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800137
138 // a todo file lists the program elements that are missing documentation.
139 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800140 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800141
142 // directory under current module source that provide additional resources (images).
143 Resourcesdir *string
144
145 // resources output directory under out/soong/.intermediates.
146 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800147
Nan Zhange2ba5d42018-07-11 15:16:55 -0700148 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800149 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700150
151 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800152 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700153
Nan Zhang581fd212018-01-10 16:06:12 -0800154 // a list of files under current module source dir which contains known tags in Java sources.
155 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800156 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700157
Nan Zhang1598a9e2018-09-04 17:14:32 -0700158 // if set to true, generate docs through Dokka instead of Doclava.
159 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000160
161 // Compat config XML. Generates compat change documentation if set.
162 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700163}
164
Nan Zhanga40da042018-08-01 12:48:00 -0700165//
166// Common flags passed down to build rule
167//
168type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700169 bootClasspathArgs string
170 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700171 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700172 dokkaClasspathArgs string
173 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700174 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700175
Nan Zhanga40da042018-08-01 12:48:00 -0700176 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700177 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700178 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700179}
180
181func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
182 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
183 android.InitDefaultableModule(module)
184}
185
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200186func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
187 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
188 return false
189 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700190 return true
191 } else if String(apiToCheck.Api_file) != "" {
192 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
193 } else if String(apiToCheck.Removed_api_file) != "" {
194 panic("for " + apiVersionTag + " api_file has to be non-empty!")
195 }
196
197 return false
198}
199
Paul Duffin3d1248c2020-04-09 00:10:17 +0100200// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700201type ApiFilePath interface {
202 ApiFilePath() android.Path
203}
204
Paul Duffin0f8faff2020-05-20 16:18:00 +0100205type ApiStubsSrcProvider interface {
206 StubsSrcJar() android.Path
207}
208
Paul Duffin3d1248c2020-04-09 00:10:17 +0100209// Provider of information about API stubs, used by java_sdk_library.
210type ApiStubsProvider interface {
211 ApiFilePath
Paul Duffin1fd005d2020-04-09 01:08:11 +0100212 RemovedApiFilePath() android.Path
Paul Duffin0f8faff2020-05-20 16:18:00 +0100213
214 ApiStubsSrcProvider
Paul Duffin3d1248c2020-04-09 00:10:17 +0100215}
216
Nan Zhanga40da042018-08-01 12:48:00 -0700217//
218// Javadoc
219//
Nan Zhang581fd212018-01-10 16:06:12 -0800220type Javadoc struct {
221 android.ModuleBase
222 android.DefaultableModuleBase
223
224 properties JavadocProperties
225
226 srcJars android.Paths
227 srcFiles android.Paths
228 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700229 argFiles android.Paths
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400230 implicits android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700231
Liz Kammer585cac22020-07-06 09:12:57 -0700232 args []string
Nan Zhang581fd212018-01-10 16:06:12 -0800233
Nan Zhangccff0f72018-03-08 17:26:16 -0800234 docZip android.WritablePath
235 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800236}
237
Colin Cross41955e82019-05-29 14:40:35 -0700238func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
239 switch tag {
240 case "":
241 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700242 case ".docs.zip":
243 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700244 default:
245 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
246 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800247}
248
Colin Crossa3002fc2019-07-08 16:48:04 -0700249// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800250func JavadocFactory() android.Module {
251 module := &Javadoc{}
252
253 module.AddProperties(&module.properties)
254
255 InitDroiddocModule(module, android.HostAndDeviceSupported)
256 return module
257}
258
Colin Crossa3002fc2019-07-08 16:48:04 -0700259// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800260func JavadocHostFactory() android.Module {
261 module := &Javadoc{}
262
263 module.AddProperties(&module.properties)
264
265 InitDroiddocModule(module, android.HostSupported)
266 return module
267}
268
Colin Cross41955e82019-05-29 14:40:35 -0700269var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800270
Jiyong Park6a927c42020-01-21 02:03:43 +0900271func (j *Javadoc) sdkVersion() sdkSpec {
272 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700273}
274
Paul Duffine25c6442019-10-11 13:50:28 +0100275func (j *Javadoc) systemModules() string {
276 return proptools.String(j.properties.System_modules)
277}
278
Jiyong Park6a927c42020-01-21 02:03:43 +0900279func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700280 return j.sdkVersion()
281}
282
Jiyong Park6a927c42020-01-21 02:03:43 +0900283func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700284 return j.sdkVersion()
285}
286
Nan Zhang581fd212018-01-10 16:06:12 -0800287func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
288 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100289 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Pete Gilline3d44b22020-06-29 11:28:51 +0100290 if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700291 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100292 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700293 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Pete Gilline3d44b22020-06-29 11:28:51 +0100294 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800295 }
296 }
297
Colin Cross42d48b72018-08-29 14:10:52 -0700298 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800299}
300
Nan Zhanga40da042018-08-01 12:48:00 -0700301func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
302 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900303
Colin Cross3047fa22019-04-18 10:56:44 -0700304 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900305
306 return flags
307}
308
309func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700310 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900311
312 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
313 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
314
315 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700316 var deps android.Paths
317
Jiyong Park1e440682018-05-23 18:42:04 +0900318 if aidlPreprocess.Valid() {
319 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700320 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900321 } else {
322 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
323 }
324
325 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
326 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
327 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
328 flags = append(flags, "-I"+src.String())
329 }
330
Colin Cross3047fa22019-04-18 10:56:44 -0700331 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900332}
333
Jiyong Parkd90d7412019-08-20 22:49:19 +0900334// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900335func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700336 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900337
338 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700339 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900340
Jiyong Park1112c4c2019-08-16 21:12:10 +0900341 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
342
Jiyong Park1e440682018-05-23 18:42:04 +0900343 for _, srcFile := range srcFiles {
344 switch srcFile.Ext() {
345 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700346 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900347 case ".logtags":
348 javaFile := genLogtags(ctx, srcFile)
349 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900350 default:
351 outSrcFiles = append(outSrcFiles, srcFile)
352 }
353 }
354
Colin Crossc0806172019-06-14 18:51:47 -0700355 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
356 if len(aidlSrcs) > 0 {
357 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
358 outSrcFiles = append(outSrcFiles, srcJarFiles...)
359 }
360
Jiyong Park1e440682018-05-23 18:42:04 +0900361 return outSrcFiles
362}
363
Nan Zhang581fd212018-01-10 16:06:12 -0800364func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
365 var deps deps
366
Colin Cross83bb3162018-06-25 15:48:06 -0700367 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800368 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700369 ctx.AddMissingDependencies(sdkDep.bootclasspath)
370 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800371 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700372 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000373 deps.aidlPreprocess = sdkDep.aidl
374 } else {
375 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800376 }
377
378 ctx.VisitDirectDeps(func(module android.Module) {
379 otherName := ctx.OtherModuleName(module)
380 tag := ctx.OtherModuleDependencyTag(module)
381
Colin Cross2d24c1b2018-05-23 10:59:18 -0700382 switch tag {
383 case bootClasspathTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800384 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
385 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
386 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000387 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100388 // A system modules dependency has been added to the bootclasspath
389 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000390 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700391 } else {
392 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
393 }
394 case libTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800395 if dep, ok := module.(SdkLibraryDependency); ok {
Paul Duffin649dadf2020-05-26 11:42:13 +0100396 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
Colin Crossdcf71b22021-02-01 13:59:03 -0800397 } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
398 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
399 deps.classpath = append(deps.classpath, dep.HeaderJars...)
400 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...)
401 } else if dep, ok := module.(android.SourceFileProducer); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800402 checkProducesJars(ctx, dep)
403 deps.classpath = append(deps.classpath, dep.Srcs()...)
Colin Crossdcf71b22021-02-01 13:59:03 -0800404 } else {
Nan Zhang581fd212018-01-10 16:06:12 -0800405 ctx.ModuleErrorf("depends on non-java module %q", otherName)
406 }
Colin Cross6cef4812019-10-17 14:23:50 -0700407 case java9LibTag:
Colin Crossdcf71b22021-02-01 13:59:03 -0800408 if ctx.OtherModuleHasProvider(module, JavaInfoProvider) {
409 dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo)
410 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...)
411 } else {
Colin Cross6cef4812019-10-17 14:23:50 -0700412 ctx.ModuleErrorf("depends on non-java module %q", otherName)
413 }
Nan Zhang357466b2018-04-17 17:38:36 -0700414 case systemModulesTag:
415 if deps.systemModules != nil {
416 panic("Found two system module dependencies")
417 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000418 sm := module.(SystemModulesProvider)
419 outputDir, outputDeps := sm.OutputDirAndDeps()
420 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800421 }
422 })
423 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
424 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800425 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400426 j.implicits = append(j.implicits, srcFiles...)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900427
428 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
429 if filterPackages == nil {
430 return srcs
431 }
432 filtered := []android.Path{}
433 for _, src := range srcs {
434 if src.Ext() != ".java" {
435 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
436 // but otherwise metalava emits stub sources having references to the generated AIDL classes
437 // in filtered-out pacages (e.g. com.android.internal.*).
438 // TODO(b/141149570) We need to fix this by introducing default private constructors or
439 // fixing metalava to not emit constructors having references to unknown classes.
440 filtered = append(filtered, src)
441 continue
442 }
443 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800444 if android.HasAnyPrefix(packageName, filterPackages) {
445 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900446 }
447 }
448 return filtered
449 }
450 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
451
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400452 // While metalava needs package html files, it does not need them to be explicit on the command
Anton Hansson746be9c2020-10-08 19:05:40 +0100453 // line. javadoc complains if it receives html files on the command line. The filter
454 // below excludes html files from the rsp file metalava. Note that the html
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400455 // files are still included as implicit inputs for successful remote execution and correct
456 // incremental builds.
457 filterHtml := func(srcs []android.Path) []android.Path {
458 filtered := []android.Path{}
459 for _, src := range srcs {
460 if src.Ext() == ".html" {
461 continue
462 }
463 filtered = append(filtered, src)
464 }
465 return filtered
466 }
467 srcFiles = filterHtml(srcFiles)
468
Liz Kammer585cac22020-07-06 09:12:57 -0700469 aidlFlags := j.collectAidlFlags(ctx, deps)
470 srcFiles = j.genSources(ctx, srcFiles, aidlFlags)
Nan Zhang581fd212018-01-10 16:06:12 -0800471
472 // srcs may depend on some genrule output.
473 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800474 j.srcJars = append(j.srcJars, deps.srcJars...)
475
Nan Zhang581fd212018-01-10 16:06:12 -0800476 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800477 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800478
Liz Kammere1ab2502020-09-10 15:29:25 +0000479 if len(j.srcFiles) > 0 {
480 j.sourcepaths = android.PathsForModuleSrc(ctx, []string{"."})
Nan Zhang581fd212018-01-10 16:06:12 -0800481 }
Nan Zhang581fd212018-01-10 16:06:12 -0800482
Colin Cross8a497952019-03-05 22:25:09 -0800483 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000484 argFilesMap := map[string]string{}
485 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700486
Paul Duffin99e4a502019-02-11 15:38:42 +0000487 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800488 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000489 if _, exists := argFilesMap[label]; !exists {
490 argFilesMap[label] = strings.Join(paths.Strings(), " ")
491 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700492 } else {
493 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000494 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700495 }
496 }
497
Liz Kammer585cac22020-07-06 09:12:57 -0700498 var argsPropertyName string
499 flags := make([]string, 0)
500 if j.properties.Args != nil && j.properties.Flags != nil {
501 ctx.PropertyErrorf("args", "flags is set. Cannot set args")
502 } else if args := proptools.String(j.properties.Args); args != "" {
503 flags = append(flags, args)
504 argsPropertyName = "args"
505 } else {
506 flags = append(flags, j.properties.Flags...)
507 argsPropertyName = "flags"
508 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700509
Liz Kammer585cac22020-07-06 09:12:57 -0700510 for _, flag := range flags {
511 args, err := android.Expand(flag, func(name string) (string, error) {
512 if strings.HasPrefix(name, "location ") {
513 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
514 if paths, ok := argFilesMap[label]; ok {
515 return paths, nil
516 } else {
517 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
518 label, strings.Join(argFileLabels, ", "))
519 }
520 } else if name == "genDir" {
521 return android.PathForModuleGen(ctx).String(), nil
522 }
523 return "", fmt.Errorf("unknown variable '$(%s)'", name)
524 })
525
526 if err != nil {
527 ctx.PropertyErrorf(argsPropertyName, "%s", err.Error())
528 }
529 j.args = append(j.args, args)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700530 }
531
Nan Zhang581fd212018-01-10 16:06:12 -0800532 return deps
533}
534
535func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
536 j.addDeps(ctx)
537}
538
539func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
540 deps := j.collectDeps(ctx)
541
Colin Crossdaa4c672019-07-15 22:53:46 -0700542 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800543
Colin Crossdaa4c672019-07-15 22:53:46 -0700544 outDir := android.PathForModuleOut(ctx, "out")
545 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
546
547 j.stubsSrcJar = nil
548
Colin Crossf1a035e2020-11-16 17:32:30 -0800549 rule := android.NewRuleBuilder(pctx, ctx)
Colin Crossdaa4c672019-07-15 22:53:46 -0700550
551 rule.Command().Text("rm -rf").Text(outDir.String())
552 rule.Command().Text("mkdir -p").Text(outDir.String())
553
554 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700555
Colin Cross83bb3162018-06-25 15:48:06 -0700556 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800557
Colin Crossdaa4c672019-07-15 22:53:46 -0700558 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
559 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800560
Colin Cross1e743852019-10-28 11:37:20 -0700561 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700562 Flag("-J-Xmx1024m").
563 Flag("-XDignore.symbol.file").
564 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800565
Colin Crossdaa4c672019-07-15 22:53:46 -0700566 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800567 BuiltTool("soong_zip").
Colin Crossdaa4c672019-07-15 22:53:46 -0700568 Flag("-write_if_changed").
569 Flag("-d").
570 FlagWithOutput("-o ", j.docZip).
571 FlagWithArg("-C ", outDir.String()).
572 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700573
Colin Crossdaa4c672019-07-15 22:53:46 -0700574 rule.Restat()
575
576 zipSyncCleanupCmd(rule, srcJarDir)
577
Colin Crossf1a035e2020-11-16 17:32:30 -0800578 rule.Build("javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800579}
580
Nan Zhanga40da042018-08-01 12:48:00 -0700581//
582// Droiddoc
583//
584type Droiddoc struct {
585 Javadoc
586
Liz Kammere1ab2502020-09-10 15:29:25 +0000587 properties DroiddocProperties
Nan Zhanga40da042018-08-01 12:48:00 -0700588}
589
Colin Crossa3002fc2019-07-08 16:48:04 -0700590// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700591func DroiddocFactory() android.Module {
592 module := &Droiddoc{}
593
594 module.AddProperties(&module.properties,
595 &module.Javadoc.properties)
596
597 InitDroiddocModule(module, android.HostAndDeviceSupported)
598 return module
599}
600
Colin Crossa3002fc2019-07-08 16:48:04 -0700601// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700602func DroiddocHostFactory() android.Module {
603 module := &Droiddoc{}
604
605 module.AddProperties(&module.properties,
606 &module.Javadoc.properties)
607
608 InitDroiddocModule(module, android.HostSupported)
609 return module
610}
611
Liz Kammere1ab2502020-09-10 15:29:25 +0000612func (d *Droiddoc) OutputFiles(tag string) (android.Paths, error) {
613 switch tag {
614 case "", ".docs.zip":
615 return android.Paths{d.Javadoc.docZip}, nil
616 default:
617 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
618 }
Nan Zhanga40da042018-08-01 12:48:00 -0700619}
620
Nan Zhang581fd212018-01-10 16:06:12 -0800621func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
622 d.Javadoc.addDeps(ctx)
623
Nan Zhang79614d12018-04-19 18:03:39 -0700624 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800625 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
626 }
Nan Zhang581fd212018-01-10 16:06:12 -0800627}
628
Colin Crossab054432019-07-15 16:13:59 -0700629func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800630 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700631 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
632 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
633 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700634 cmd.FlagWithArg("-source ", "1.8").
635 Flag("-J-Xmx1600m").
636 Flag("-J-XX:-OmitStackTraceInFastThrow").
637 Flag("-XDignore.symbol.file").
638 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
639 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800640 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700641 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 -0700642
Nan Zhanga40da042018-08-01 12:48:00 -0700643 if String(d.properties.Custom_template) == "" {
644 // TODO: This is almost always droiddoc-templates-sdk
645 ctx.PropertyErrorf("custom_template", "must specify a template")
646 }
647
648 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700649 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700650 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700651 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000652 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700653 }
654 })
655
656 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700657 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
658 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
659 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700660 }
661
662 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700663 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
664 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
665 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700666 }
667
668 if len(d.properties.Html_dirs) > 2 {
669 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
670 }
671
Colin Cross8a497952019-03-05 22:25:09 -0800672 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700673 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700674
Colin Crossab054432019-07-15 16:13:59 -0700675 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700676
677 if String(d.properties.Proofread_file) != "" {
678 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700679 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700680 }
681
682 if String(d.properties.Todo_file) != "" {
683 // tricky part:
684 // we should not compute full path for todo_file through PathForModuleOut().
685 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700686 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
687 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700688 }
689
690 if String(d.properties.Resourcesdir) != "" {
691 // TODO: should we add files under resourcesDir to the implicits? It seems that
692 // resourcesDir is one sub dir of htmlDir
693 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700694 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700695 }
696
697 if String(d.properties.Resourcesoutdir) != "" {
698 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700699 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700700 }
Nan Zhanga40da042018-08-01 12:48:00 -0700701}
702
Colin Crossab054432019-07-15 16:13:59 -0700703func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700704 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700705 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
706 rule.Command().Text("cp").
707 Input(staticDocIndexRedirect).
708 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700709 }
710
711 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700712 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
713 rule.Command().Text("cp").
714 Input(staticDocProperties).
715 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700716 }
Nan Zhanga40da042018-08-01 12:48:00 -0700717}
718
Colin Crossab054432019-07-15 16:13:59 -0700719func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700720 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700721
722 cmd := rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800723 BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
Colin Crossab054432019-07-15 16:13:59 -0700724 Flag(config.JavacVmFlags).
725 FlagWithArg("-encoding ", "UTF-8").
Colin Cross70c47412021-03-12 17:48:14 -0800726 FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs).
Colin Crossab054432019-07-15 16:13:59 -0700727 FlagWithInput("@", srcJarList)
728
Colin Crossab054432019-07-15 16:13:59 -0700729 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
730 // based stubs generation.
731 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
732 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
733 // the correct package name base path.
734 if len(sourcepaths) > 0 {
735 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
736 } else {
737 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
738 }
739
740 cmd.FlagWithArg("-d ", outDir.String()).
741 Flag("-quiet")
742
743 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700744}
745
Colin Crossdaa4c672019-07-15 22:53:46 -0700746func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
747 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
748 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
749
750 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
751
752 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
753 cmd.Flag(flag).Implicits(deps)
754
755 cmd.FlagWithArg("--patch-module ", "java.base=.")
756
757 if len(classpath) > 0 {
758 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
759 }
760
761 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700762}
763
Colin Crossdaa4c672019-07-15 22:53:46 -0700764func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
765 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
766 sourcepaths android.Paths) *android.RuleBuilderCommand {
767
768 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
769
770 if len(bootclasspath) == 0 && ctx.Device() {
771 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
772 // ensure java does not fall back to the default bootclasspath.
773 cmd.FlagWithArg("-bootclasspath ", `""`)
774 } else if len(bootclasspath) > 0 {
775 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
776 }
777
778 if len(classpath) > 0 {
779 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
780 }
781
782 return cmd
783}
784
Colin Crossab054432019-07-15 16:13:59 -0700785func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
786 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700787
Colin Crossab054432019-07-15 16:13:59 -0700788 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
789 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
790
791 return rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800792 BuiltTool("dokka").
Colin Crossab054432019-07-15 16:13:59 -0700793 Flag(config.JavacVmFlags).
794 Flag(srcJarDir.String()).
795 FlagWithInputList("-classpath ", dokkaClasspath, ":").
796 FlagWithArg("-format ", "dac").
797 FlagWithArg("-dacRoot ", "/reference/kotlin").
798 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700799}
800
801func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
802 deps := d.Javadoc.collectDeps(ctx)
803
Colin Crossdaa4c672019-07-15 22:53:46 -0700804 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Colin Crossdaa4c672019-07-15 22:53:46 -0700805
Nan Zhang1598a9e2018-09-04 17:14:32 -0700806 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
807 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700808
Colin Crossab054432019-07-15 16:13:59 -0700809 outDir := android.PathForModuleOut(ctx, "out")
810 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700811
Colin Crossf1a035e2020-11-16 17:32:30 -0800812 rule := android.NewRuleBuilder(pctx, ctx)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700813
Colin Crossab054432019-07-15 16:13:59 -0700814 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
815
816 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700817 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700818 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700819 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700820 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700821 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700822 }
823
Liz Kammer585cac22020-07-06 09:12:57 -0700824 cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
Colin Crossab054432019-07-15 16:13:59 -0700825
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000826 if d.properties.Compat_config != nil {
827 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
828 cmd.FlagWithInput("-compatconfig ", compatConfig)
829 }
830
Colin Crossab054432019-07-15 16:13:59 -0700831 var desc string
832 if Bool(d.properties.Dokka_enabled) {
833 desc = "dokka"
834 } else {
835 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
836
837 for _, o := range d.Javadoc.properties.Out {
838 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
839 }
840
841 d.postDoclavaCmds(ctx, rule)
842 desc = "doclava"
843 }
844
845 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800846 BuiltTool("soong_zip").
Colin Crossab054432019-07-15 16:13:59 -0700847 Flag("-write_if_changed").
848 Flag("-d").
849 FlagWithOutput("-o ", d.docZip).
850 FlagWithArg("-C ", outDir.String()).
851 FlagWithArg("-D ", outDir.String())
852
Colin Crossab054432019-07-15 16:13:59 -0700853 rule.Restat()
854
855 zipSyncCleanupCmd(rule, srcJarDir)
856
Colin Crossf1a035e2020-11-16 17:32:30 -0800857 rule.Build("javadoc", desc)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700858}
859
860//
Nan Zhangf4936b02018-08-01 15:00:28 -0700861// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -0700862//
Dan Willemsencc090972018-02-26 14:33:31 -0800863var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
864
Nan Zhangf4936b02018-08-01 15:00:28 -0700865type ExportedDroiddocDirProperties struct {
866 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -0800867 Path *string
868}
869
Nan Zhangf4936b02018-08-01 15:00:28 -0700870type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -0800871 android.ModuleBase
872
Nan Zhangf4936b02018-08-01 15:00:28 -0700873 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -0800874
875 deps android.Paths
876 dir android.Path
877}
878
Colin Crossa3002fc2019-07-08 16:48:04 -0700879// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -0700880func ExportedDroiddocDirFactory() android.Module {
881 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -0800882 module.AddProperties(&module.properties)
883 android.InitAndroidModule(module)
884 return module
885}
886
Nan Zhangf4936b02018-08-01 15:00:28 -0700887func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -0800888
Nan Zhangf4936b02018-08-01 15:00:28 -0700889func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -0800890 path := String(d.properties.Path)
891 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -0800892 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -0800893}
Nan Zhangb2b33de2018-02-23 11:18:47 -0800894
895//
896// Defaults
897//
898type DocDefaults struct {
899 android.ModuleBase
900 android.DefaultsModuleBase
901}
902
Nan Zhangb2b33de2018-02-23 11:18:47 -0800903func DocDefaultsFactory() android.Module {
904 module := &DocDefaults{}
905
906 module.AddProperties(
907 &JavadocProperties{},
908 &DroiddocProperties{},
909 )
910
911 android.InitDefaultsModule(module)
912
913 return module
914}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700915
Colin Cross33961b52019-07-11 11:01:22 -0700916func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
917 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
918
Colin Cross1661aff2021-03-12 17:56:51 -0800919 cmd := rule.Command()
920 cmd.Text("rm -rf").Text(cmd.PathForOutput(srcJarDir))
921 cmd = rule.Command()
922 cmd.Text("mkdir -p").Text(cmd.PathForOutput(srcJarDir))
Colin Cross33961b52019-07-11 11:01:22 -0700923 srcJarList := srcJarDir.Join(ctx, "list")
924
925 rule.Temporary(srcJarList)
926
Colin Cross1661aff2021-03-12 17:56:51 -0800927 cmd = rule.Command()
928 cmd.BuiltTool("zipsync").
929 FlagWithArg("-d ", cmd.PathForOutput(srcJarDir)).
Colin Cross33961b52019-07-11 11:01:22 -0700930 FlagWithOutput("-l ", srcJarList).
931 FlagWithArg("-f ", `"*.java"`).
932 Inputs(srcJars)
933
934 return srcJarList
935}
936
937func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
938 rule.Command().Text("rm -rf").Text(srcJarDir.String())
939}