blob: 52db7057e9ed664a619373e908797f740dcc2c1f [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
19 "android/soong/java/config"
20 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080021 "path/filepath"
Nan Zhang46130972018-06-04 11:28:01 -070022 "runtime"
Nan Zhang581fd212018-01-10 16:06:12 -080023 "strings"
24
25 "github.com/google/blueprint"
26)
27
28var (
29 javadoc = pctx.AndroidStaticRule("javadoc",
30 blueprint.RuleParams{
31 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070032 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhangaf322cc2018-06-19 15:15:38 -070033 `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang581fd212018-01-10 16:06:12 -080034 `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
35 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Nan Zhange2ba5d42018-07-11 15:16:55 -070037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`,
Nan Zhang581fd212018-01-10 16:06:12 -080038 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070039 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080040 "${config.JavadocCmd}",
41 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 },
43 Rspfile: "$out.rsp",
44 RspfileContent: "$in",
45 Restat: true,
46 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070047 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhange2ba5d42018-07-11 15:16:55 -070048 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070049
50 apiCheck = pctx.AndroidStaticRule("apiCheck",
51 blueprint.RuleParams{
52 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
53 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090054 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070055 CommandDeps: []string{
56 "${config.ApiCheckCmd}",
57 },
58 },
59 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
60
61 updateApi = pctx.AndroidStaticRule("updateApi",
62 blueprint.RuleParams{
63 Command: `( ( cp -f $apiFileToCheck $apiFile && cp -f $removedApiFileToCheck $removedApiFile ) ` +
64 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
65 },
66 "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck")
Nan Zhang79614d12018-04-19 18:03:39 -070067
68 metalava = pctx.AndroidStaticRule("metalava",
69 blueprint.RuleParams{
Nan Zhangde860a42018-08-08 16:32:21 -070070 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
71 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070072 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070073 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang16c0a312018-06-13 17:42:48 -070074 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
75 `--stubs $stubsDir $opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070076 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
77 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
78 CommandDeps: []string{
79 "${config.ZipSyncCmd}",
80 "${config.JavaCmd}",
81 "${config.MetalavaJar}",
82 "${config.JavadocCmd}",
83 "${config.SoongZipCmd}",
84 },
85 Rspfile: "$out.rsp",
86 RspfileContent: "$in",
87 Restat: true,
88 },
Nan Zhangde860a42018-08-08 16:32:21 -070089 "outDir", "srcJarDir", "stubsDir", "docStubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
Nan Zhang357466b2018-04-17 17:38:36 -070090 "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang2760dfc2018-08-24 17:32:54 +000091
92 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
93 blueprint.RuleParams{
94 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
95 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
96 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
97 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
98 `$opts && touch $out ) || ` +
99 `( echo -e "$msg" ; exit 38 )`,
100 CommandDeps: []string{
101 "${config.ZipSyncCmd}",
102 "${config.JavaCmd}",
103 "${config.MetalavaJar}",
104 },
105 Rspfile: "$out.rsp",
106 RspfileContent: "$in",
107 },
108 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "msg")
Nan Zhang581fd212018-01-10 16:06:12 -0800109)
110
111func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800112 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
113
Nan Zhang581fd212018-01-10 16:06:12 -0800114 android.RegisterModuleType("droiddoc", DroiddocFactory)
115 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700116 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800117 android.RegisterModuleType("javadoc", JavadocFactory)
118 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
119}
120
Colin Crossa1ce2a02018-06-20 15:19:39 -0700121var (
122 srcsLibTag = dependencyTag{name: "sources from javalib"}
123)
124
Nan Zhang581fd212018-01-10 16:06:12 -0800125type JavadocProperties struct {
126 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
127 // or .aidl files.
128 Srcs []string `android:"arch_variant"`
129
130 // list of directories rooted at the Android.bp file that will
131 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // list of source files that should not be used to build the Java module.
135 // This is most useful in the arch/multilib variants to remove non-common files
136 // filegroup or genrule can be included within this property.
137 Exclude_srcs []string `android:"arch_variant"`
138
Nan Zhangb2b33de2018-02-23 11:18:47 -0800139 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800140 Libs []string `android:"arch_variant"`
141
Nan Zhange66c7272018-03-06 12:59:27 -0800142 // don't build against the framework libraries (legacy-test, core-junit,
143 // ext, and framework for device targets)
144 No_framework_libs *bool
145
Nan Zhangb2b33de2018-02-23 11:18:47 -0800146 // the java library (in classpath) for documentation that provides java srcs and srcjars.
147 Srcs_lib *string
148
149 // the base dirs under srcs_lib will be scanned for java srcs.
150 Srcs_lib_whitelist_dirs []string
151
152 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
153 Srcs_lib_whitelist_pkgs []string
154
Nan Zhang581fd212018-01-10 16:06:12 -0800155 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800156 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800157
158 // if not blank, set to the version of the sdk to compile against
159 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900160
161 Aidl struct {
162 // Top level directories to pass to aidl tool
163 Include_dirs []string
164
165 // Directories rooted at the Android.bp file to pass to aidl tool
166 Local_include_dirs []string
167 }
Nan Zhang357466b2018-04-17 17:38:36 -0700168
169 // If not blank, set the java version passed to javadoc as -source
170 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800171}
172
Nan Zhang61819ce2018-05-04 18:49:16 -0700173type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900174 // path to the API txt file that the new API extracted from source code is checked
175 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700176 Api_file *string
177
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900178 // path to the API txt file that the new @removed API extractd from source code is
179 // checked against. The path can be local to the module or from other module (via
180 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700181 Removed_api_file *string
182
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900183 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700184 Args *string
185}
186
Nan Zhang581fd212018-01-10 16:06:12 -0800187type DroiddocProperties struct {
188 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800189 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800190
Nan Zhanga40da042018-08-01 12:48:00 -0700191 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800192 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800193
194 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800195 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800196
197 // proofread file contains all of the text content of the javadocs concatenated into one file,
198 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800199 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800200
201 // a todo file lists the program elements that are missing documentation.
202 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800203 Todo_file *string
204
205 // directory under current module source that provide additional resources (images).
206 Resourcesdir *string
207
208 // resources output directory under out/soong/.intermediates.
209 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800210
211 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800212 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800213
214 // user customized droiddoc args.
215 // Available variables for substitution:
216 //
217 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800218 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800219
220 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800221 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800222
Nan Zhange2ba5d42018-07-11 15:16:55 -0700223 // if set to true, collect the values used by the Dev tools and
224 // write them in files packaged with the SDK. Defaults to false.
225 Write_sdk_values *bool
226
227 // index.html under current module will be copied to docs out dir, if not null.
228 Static_doc_index_redirect *string
229
230 // source.properties under current module will be copied to docs out dir, if not null.
231 Static_doc_properties *string
232
Nan Zhang581fd212018-01-10 16:06:12 -0800233 // a list of files under current module source dir which contains known tags in Java sources.
234 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800235 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700236
237 // the tag name used to distinguish if the API files belong to public/system/test.
238 Api_tag_name *string
239
240 // the generated public API filename by Doclava.
241 Api_filename *string
242
David Brazdilfbe4cc32018-05-31 13:56:46 +0100243 // the generated public Dex API filename by Doclava.
244 Dex_api_filename *string
245
Nan Zhang28c68b92018-03-13 16:17:01 -0700246 // the generated private API filename by Doclava.
247 Private_api_filename *string
248
249 // the generated private Dex API filename by Doclava.
250 Private_dex_api_filename *string
251
252 // the generated removed API filename by Doclava.
253 Removed_api_filename *string
254
David Brazdilaac0c3c2018-04-24 16:23:29 +0100255 // the generated removed Dex API filename by Doclava.
256 Removed_dex_api_filename *string
257
Mathew Inwood76c3de12018-06-22 15:28:11 +0100258 // mapping of dex signatures to source file and line number. This is a temporary property and
259 // will be deleted; you probably shouldn't be using it.
260 Dex_mapping_filename *string
261
Nan Zhang28c68b92018-03-13 16:17:01 -0700262 // the generated exact API filename by Doclava.
263 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700264
Nan Zhang66dc2362018-08-14 20:41:04 -0700265 // the generated proguard filename by Doclava.
266 Proguard_filename *string
267
Nan Zhang853f4202018-04-12 16:55:56 -0700268 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
269 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700270
271 Check_api struct {
272 Last_released ApiToCheck
273
274 Current ApiToCheck
275 }
Nan Zhang79614d12018-04-19 18:03:39 -0700276
277 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
278 // currently still used for documentation generation, and will be replaced by Dokka soon.
279 Metalava_enabled *bool
280
281 // user can specify the version of previous released API file in order to do compatibility check.
282 Metalava_previous_api *string
283
284 // is set to true, Metalava will allow framework SDK to contain annotations.
285 Metalava_annotations_enabled *bool
286
Pete Gillinb13a0152018-07-19 17:56:49 +0100287 // a list of top-level directories containing files to merge annotations from.
288 Metalava_merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700289
290 // if set to true, generate docs through Dokka instead of Doclava. Valid only when
291 // metalava_enabled is set to true.
292 Dokka_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800293}
294
Nan Zhanga40da042018-08-01 12:48:00 -0700295//
296// Common flags passed down to build rule
297//
298type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700299 args string
300 bootClasspathArgs string
301 classpathArgs string
302 dokkaClasspathArgs string
303 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700304
Nan Zhanga40da042018-08-01 12:48:00 -0700305 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700306 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700307 postDoclavaCmds string
308
Nan Zhang2760dfc2018-08-24 17:32:54 +0000309 metalavaStubsFlags string
310 metalavaAnnotationsFlags string
311 metalavaJavadocFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700312
Nan Zhang86d2d552018-08-09 15:33:27 -0700313 metalavaDokkaFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700314}
315
316func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
317 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
318 android.InitDefaultableModule(module)
319}
320
321//
322// Javadoc
323//
Nan Zhang581fd212018-01-10 16:06:12 -0800324type Javadoc struct {
325 android.ModuleBase
326 android.DefaultableModuleBase
327
328 properties JavadocProperties
329
330 srcJars android.Paths
331 srcFiles android.Paths
332 sourcepaths android.Paths
333
Nan Zhangccff0f72018-03-08 17:26:16 -0800334 docZip android.WritablePath
335 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800336}
337
Nan Zhangb2b33de2018-02-23 11:18:47 -0800338func (j *Javadoc) Srcs() android.Paths {
339 return android.Paths{j.stubsSrcJar}
340}
341
Nan Zhang581fd212018-01-10 16:06:12 -0800342func JavadocFactory() android.Module {
343 module := &Javadoc{}
344
345 module.AddProperties(&module.properties)
346
347 InitDroiddocModule(module, android.HostAndDeviceSupported)
348 return module
349}
350
351func JavadocHostFactory() android.Module {
352 module := &Javadoc{}
353
354 module.AddProperties(&module.properties)
355
356 InitDroiddocModule(module, android.HostSupported)
357 return module
358}
359
Nan Zhanga40da042018-08-01 12:48:00 -0700360var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800361
Colin Cross83bb3162018-06-25 15:48:06 -0700362func (j *Javadoc) sdkVersion() string {
363 return String(j.properties.Sdk_version)
364}
365
366func (j *Javadoc) minSdkVersion() string {
367 return j.sdkVersion()
368}
369
Nan Zhang581fd212018-01-10 16:06:12 -0800370func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
371 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700372 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800373 if sdkDep.useDefaultLibs {
374 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700375 if ctx.Config().TargetOpenJDK9() {
376 ctx.AddDependency(ctx.Module(), systemModulesTag, config.DefaultSystemModules)
377 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700378 if !Bool(j.properties.No_framework_libs) {
Nan Zhang77a69ec2018-08-02 16:28:26 -0700379 ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800380 }
Nan Zhang581fd212018-01-10 16:06:12 -0800381 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700382 if ctx.Config().TargetOpenJDK9() {
383 ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
384 }
Colin Cross86a60ae2018-05-29 14:44:55 -0700385 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800386 }
387 }
388
389 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700390 if j.properties.Srcs_lib != nil {
391 ctx.AddDependency(ctx.Module(), srcsLibTag, *j.properties.Srcs_lib)
392 }
Nan Zhang581fd212018-01-10 16:06:12 -0800393
394 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
395
396 // exclude_srcs may contain filegroup or genrule.
397 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
398}
399
Nan Zhangb2b33de2018-02-23 11:18:47 -0800400func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
401 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
402 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900403 // convert foo.bar.baz to foo/bar/baz
404 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
405 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800406 if _, found := whitelistPathPrefixes[prefix]; !found {
407 whitelistPathPrefixes[prefix] = true
408 }
409 }
410 }
411}
412
Nan Zhanga40da042018-08-01 12:48:00 -0700413func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
414 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900415
416 // aidl flags.
417 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
418 if len(aidlFlags) > 0 {
419 // optimization.
420 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
421 flags.aidlFlags = "$aidlFlags"
422 }
423
424 return flags
425}
426
427func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
428 aidlIncludeDirs android.Paths) []string {
429
430 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
431 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
432
433 var flags []string
434 if aidlPreprocess.Valid() {
435 flags = append(flags, "-p"+aidlPreprocess.String())
436 } else {
437 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
438 }
439
440 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
441 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
442 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
443 flags = append(flags, "-I"+src.String())
444 }
445
446 return flags
447}
448
449func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700450 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900451
452 outSrcFiles := make(android.Paths, 0, len(srcFiles))
453
454 for _, srcFile := range srcFiles {
455 switch srcFile.Ext() {
456 case ".aidl":
457 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
458 outSrcFiles = append(outSrcFiles, javaFile)
459 default:
460 outSrcFiles = append(outSrcFiles, srcFile)
461 }
462 }
463
464 return outSrcFiles
465}
466
Nan Zhang581fd212018-01-10 16:06:12 -0800467func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
468 var deps deps
469
Colin Cross83bb3162018-06-25 15:48:06 -0700470 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800471 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700472 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800473 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700474 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800475 }
476
477 ctx.VisitDirectDeps(func(module android.Module) {
478 otherName := ctx.OtherModuleName(module)
479 tag := ctx.OtherModuleDependencyTag(module)
480
Colin Cross2d24c1b2018-05-23 10:59:18 -0700481 switch tag {
482 case bootClasspathTag:
483 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800484 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700485 } else {
486 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
487 }
488 case libTag:
489 switch dep := module.(type) {
490 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800491 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700492 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700493 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900494 linkType := javaSdk
495 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
496 linkType = javaSystem
497 } else if sdkVersion == "" {
498 linkType = javaPlatform
499 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900500 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700501 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800502 checkProducesJars(ctx, dep)
503 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800504 default:
505 ctx.ModuleErrorf("depends on non-java module %q", otherName)
506 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700507 case srcsLibTag:
508 switch dep := module.(type) {
509 case Dependency:
510 srcs := dep.(SrcDependency).CompiledSrcs()
511 whitelistPathPrefixes := make(map[string]bool)
512 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
513 for _, src := range srcs {
514 if _, ok := src.(android.WritablePath); ok { // generated sources
515 deps.srcs = append(deps.srcs, src)
516 } else { // select source path for documentation based on whitelist path prefixs.
517 for k, _ := range whitelistPathPrefixes {
518 if strings.HasPrefix(src.Rel(), k) {
519 deps.srcs = append(deps.srcs, src)
520 break
521 }
522 }
523 }
524 }
525 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
526 default:
527 ctx.ModuleErrorf("depends on non-java module %q", otherName)
528 }
Nan Zhang357466b2018-04-17 17:38:36 -0700529 case systemModulesTag:
530 if deps.systemModules != nil {
531 panic("Found two system module dependencies")
532 }
533 sm := module.(*SystemModules)
534 if sm.outputFile == nil {
535 panic("Missing directory for system module dependency")
536 }
537 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800538 }
539 })
540 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
541 // may contain filegroup or genrule.
542 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700543 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900544 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800545
546 // srcs may depend on some genrule output.
547 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800548 j.srcJars = append(j.srcJars, deps.srcJars...)
549
Nan Zhang581fd212018-01-10 16:06:12 -0800550 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800551 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800552
553 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800554 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800555
556 if j.properties.Local_sourcepaths == nil {
557 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
558 }
559 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800560
561 return deps
562}
563
564func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
565 j.addDeps(ctx)
566}
567
568func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
569 deps := j.collectDeps(ctx)
570
571 var implicits android.Paths
572 implicits = append(implicits, deps.bootClasspath...)
573 implicits = append(implicits, deps.classpath...)
574
575 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700576
Colin Cross83bb3162018-06-25 15:48:06 -0700577 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700578 if len(deps.bootClasspath) > 0 {
579 var systemModules classpath
580 if deps.systemModules != nil {
581 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800582 }
Colin Cross997262f2018-06-19 22:49:39 -0700583 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
584 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800585 }
586 if len(deps.classpath.Strings()) > 0 {
587 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
588 }
589
590 implicits = append(implicits, j.srcJars...)
591
Nan Zhangaf322cc2018-06-19 15:15:38 -0700592 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800593
594 ctx.Build(pctx, android.BuildParams{
595 Rule: javadoc,
596 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800597 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800598 ImplicitOutput: j.docZip,
599 Inputs: j.srcFiles,
600 Implicits: implicits,
601 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700602 "outDir": android.PathForModuleOut(ctx, "out").String(),
603 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
604 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800605 "srcJars": strings.Join(j.srcJars.Strings(), " "),
606 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700607 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800608 "classpathArgs": classpathArgs,
609 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
610 "docZip": j.docZip.String(),
611 },
612 })
613}
614
Nan Zhanga40da042018-08-01 12:48:00 -0700615//
616// Droiddoc
617//
618type Droiddoc struct {
619 Javadoc
620
621 properties DroiddocProperties
622 apiFile android.WritablePath
623 dexApiFile android.WritablePath
624 privateApiFile android.WritablePath
625 privateDexApiFile android.WritablePath
626 removedApiFile android.WritablePath
627 removedDexApiFile android.WritablePath
628 exactApiFile android.WritablePath
629 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700630 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700631
632 checkCurrentApiTimestamp android.WritablePath
633 updateCurrentApiTimestamp android.WritablePath
634 checkLastReleasedApiTimestamp android.WritablePath
635
636 annotationsZip android.WritablePath
637
638 apiFilePath android.Path
639}
640
641type ApiFilePath interface {
642 ApiFilePath() android.Path
643}
644
645func DroiddocFactory() android.Module {
646 module := &Droiddoc{}
647
648 module.AddProperties(&module.properties,
649 &module.Javadoc.properties)
650
651 InitDroiddocModule(module, android.HostAndDeviceSupported)
652 return module
653}
654
655func DroiddocHostFactory() android.Module {
656 module := &Droiddoc{}
657
658 module.AddProperties(&module.properties,
659 &module.Javadoc.properties)
660
661 InitDroiddocModule(module, android.HostSupported)
662 return module
663}
664
665func (d *Droiddoc) ApiFilePath() android.Path {
666 return d.apiFilePath
667}
668
Nan Zhang61819ce2018-05-04 18:49:16 -0700669func (d *Droiddoc) checkCurrentApi() bool {
670 if String(d.properties.Check_api.Current.Api_file) != "" &&
671 String(d.properties.Check_api.Current.Removed_api_file) != "" {
672 return true
673 } else if String(d.properties.Check_api.Current.Api_file) != "" {
674 panic("check_api.current.removed_api_file: has to be non empty!")
675 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
676 panic("check_api.current.api_file: has to be non empty!")
677 }
678
679 return false
680}
681
682func (d *Droiddoc) checkLastReleasedApi() bool {
683 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
684 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
685 return true
686 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
687 panic("check_api.last_released.removed_api_file: has to be non empty!")
688 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
689 panic("check_api.last_released.api_file: has to be non empty!")
690 }
691
692 return false
693}
694
Nan Zhang581fd212018-01-10 16:06:12 -0800695func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
696 d.Javadoc.addDeps(ctx)
697
Nan Zhang79614d12018-04-19 18:03:39 -0700698 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800699 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
700 }
701
Nan Zhanga40da042018-08-01 12:48:00 -0700702 // arg_files may contains filegroup or genrule.
Nan Zhang581fd212018-01-10 16:06:12 -0800703 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
704
705 // knowntags may contain filegroup or genrule.
706 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700707
Nan Zhange2ba5d42018-07-11 15:16:55 -0700708 if String(d.properties.Static_doc_index_redirect) != "" {
709 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
710 }
711
712 if String(d.properties.Static_doc_properties) != "" {
713 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
714 }
715
Nan Zhang61819ce2018-05-04 18:49:16 -0700716 if d.checkCurrentApi() {
717 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
718 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
719 }
720
721 if d.checkLastReleasedApi() {
722 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
723 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
724 }
Nan Zhang79614d12018-04-19 18:03:39 -0700725
726 if String(d.properties.Metalava_previous_api) != "" {
727 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
728 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700729
730 if len(d.properties.Metalava_merge_annotations_dirs) != 0 {
731 for _, mergeAnnotationsDir := range d.properties.Metalava_merge_annotations_dirs {
732 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
733 }
734 }
Nan Zhang581fd212018-01-10 16:06:12 -0800735}
736
Nan Zhang66dc2362018-08-14 20:41:04 -0700737func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
738 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700739 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800740
Nan Zhanga40da042018-08-01 12:48:00 -0700741 *implicits = append(*implicits, deps.bootClasspath...)
742 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800743
Nan Zhangc94f9d82018-06-26 10:02:26 -0700744 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
745 // since it doesn't support system modules yet.
746 if len(deps.bootClasspath.Strings()) > 0 {
747 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700748 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700749 }
Nan Zhanga40da042018-08-01 12:48:00 -0700750 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang86d2d552018-08-09 15:33:27 -0700751 // Dokka doesn't support boocClasspath, so combine these two classpath vars for Dokka.
752 dokkaClasspath := classpath{}
753 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
754 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
755 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700756
Nan Zhang581fd212018-01-10 16:06:12 -0800757 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
758 argFilesMap := map[string]android.Path{}
759
760 for _, f := range argFiles {
Nan Zhanga40da042018-08-01 12:48:00 -0700761 *implicits = append(*implicits, f)
Nan Zhang581fd212018-01-10 16:06:12 -0800762 if _, exists := argFilesMap[f.Rel()]; !exists {
763 argFilesMap[f.Rel()] = f
764 } else {
765 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
766 f, argFilesMap[f.Rel()], f.Rel())
767 }
768 }
769
Nan Zhanga40da042018-08-01 12:48:00 -0700770 var err error
771 flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) {
Nan Zhang581fd212018-01-10 16:06:12 -0800772 if strings.HasPrefix(name, "location ") {
773 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
774 if f, ok := argFilesMap[label]; ok {
775 return f.String(), nil
776 } else {
777 return "", fmt.Errorf("unknown location label %q", label)
778 }
779 } else if name == "genDir" {
780 return android.PathForModuleGen(ctx).String(), nil
781 }
782 return "", fmt.Errorf("unknown variable '$(%s)'", name)
783 })
784
785 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700786 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhanga40da042018-08-01 12:48:00 -0700787 return droiddocBuilderFlags{}, err
Nan Zhang581fd212018-01-10 16:06:12 -0800788 }
Nan Zhanga40da042018-08-01 12:48:00 -0700789 return flags, nil
790}
Nan Zhang581fd212018-01-10 16:06:12 -0800791
Nan Zhanga40da042018-08-01 12:48:00 -0700792func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700793 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800794
Nan Zhanga40da042018-08-01 12:48:00 -0700795 *implicits = append(*implicits, jsilver)
796 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700797
Nan Zhang46130972018-06-04 11:28:01 -0700798 var date string
799 if runtime.GOOS == "darwin" {
800 date = `date -r`
801 } else {
802 date = `date -d`
803 }
804
Nan Zhang443fa522018-08-20 20:58:28 -0700805 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
806 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
807 // 1.9 language features.
808 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700809 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800810 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700811 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700812
Nan Zhanga40da042018-08-01 12:48:00 -0700813 if String(d.properties.Custom_template) == "" {
814 // TODO: This is almost always droiddoc-templates-sdk
815 ctx.PropertyErrorf("custom_template", "must specify a template")
816 }
817
818 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700819 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700820 *implicits = append(*implicits, t.deps...)
821 args = args + " -templatedir " + t.dir.String()
822 } else {
823 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
824 }
825 })
826
827 if len(d.properties.Html_dirs) > 0 {
828 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
829 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
830 args = args + " -htmldir " + htmlDir.String()
831 }
832
833 if len(d.properties.Html_dirs) > 1 {
834 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
835 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
836 args = args + " -htmldir2 " + htmlDir2.String()
837 }
838
839 if len(d.properties.Html_dirs) > 2 {
840 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
841 }
842
843 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
844 *implicits = append(*implicits, knownTags...)
845
846 for _, kt := range knownTags {
847 args = args + " -knowntags " + kt.String()
848 }
849
850 for _, hdf := range d.properties.Hdf {
851 args = args + " -hdf " + hdf
852 }
853
854 if String(d.properties.Proofread_file) != "" {
855 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
856 args = args + " -proofread " + proofreadFile.String()
857 }
858
859 if String(d.properties.Todo_file) != "" {
860 // tricky part:
861 // we should not compute full path for todo_file through PathForModuleOut().
862 // the non-standard doclet will get the full path relative to "-o".
863 args = args + " -todo " + String(d.properties.Todo_file)
864 }
865
866 if String(d.properties.Resourcesdir) != "" {
867 // TODO: should we add files under resourcesDir to the implicits? It seems that
868 // resourcesDir is one sub dir of htmlDir
869 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
870 args = args + " -resourcesdir " + resourcesDir.String()
871 }
872
873 if String(d.properties.Resourcesoutdir) != "" {
874 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
875 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
876 }
877 return args
878}
879
880func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) {
881 var doclavaFlags, MetalavaFlags string
882 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
883 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
884 doclavaFlags += " -api " + d.apiFile.String()
885 MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String()
886 *implicitOutputs = append(*implicitOutputs, d.apiFile)
887 d.apiFilePath = d.apiFile
888 }
889
890 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
891 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
892 doclavaFlags += " -removedApi " + d.removedApiFile.String()
893 MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String()
894 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
895 }
896
897 if String(d.properties.Private_api_filename) != "" {
898 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
899 doclavaFlags += " -privateApi " + d.privateApiFile.String()
900 MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String()
901 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
902 }
903
904 if String(d.properties.Dex_api_filename) != "" {
905 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
906 doclavaFlags += " -dexApi " + d.dexApiFile.String()
907 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
908 }
909
910 if String(d.properties.Private_dex_api_filename) != "" {
911 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
912 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
913 MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
914 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
915 }
916
917 if String(d.properties.Removed_dex_api_filename) != "" {
918 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
919 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
920 MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
921 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
922 }
923
924 if String(d.properties.Exact_api_filename) != "" {
925 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
926 doclavaFlags += " -exactApi " + d.exactApiFile.String()
927 MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String()
928 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
929 }
930
931 if String(d.properties.Dex_mapping_filename) != "" {
932 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
933 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
934 // Omitted: metalava support
935 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
936 }
937
Nan Zhang66dc2362018-08-14 20:41:04 -0700938 if String(d.properties.Proguard_filename) != "" {
939 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
940 doclavaFlags += " -proguard " + d.proguardFile.String()
941 // Omitted: metalava support
942 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
943 }
944
Nan Zhanga40da042018-08-01 12:48:00 -0700945 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -0700946 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700947 }
948
949 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -0700950 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700951 }
952 return doclavaFlags, MetalavaFlags
953}
954
955func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
956 var cmds string
957 if String(d.properties.Static_doc_index_redirect) != "" {
958 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
959 "static_doc_index_redirect")
960 *implicits = append(*implicits, static_doc_index_redirect)
961 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700962 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700963 }
964
965 if String(d.properties.Static_doc_properties) != "" {
966 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
967 "static_doc_properties")
968 *implicits = append(*implicits, static_doc_properties)
969 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700970 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700971 }
972 return cmds
973}
974
975func (d *Droiddoc) collectMetalavaAnnotationsFlags(
976 ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
977 var flags string
Nan Zhanga40da042018-08-01 12:48:00 -0700978 if Bool(d.properties.Metalava_annotations_enabled) {
979 if String(d.properties.Metalava_previous_api) == "" {
980 ctx.PropertyErrorf("metalava_previous_api",
981 "has to be non-empty if annotations was enabled!")
982 }
Nan Zhangde860a42018-08-08 16:32:21 -0700983 previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api),
984 "metalava_previous_api")
985 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -0700986
Nan Zhangd05a4362018-08-15 13:28:54 -0700987 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700988
989 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
990 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
991
Nan Zhangf4936b02018-08-01 15:00:28 -0700992 flags += " --extract-annotations " + d.annotationsZip.String()
993
Nan Zhanga40da042018-08-01 12:48:00 -0700994 if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
995 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
996 "has to be non-empty if annotations was enabled!")
997 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700998 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
999 if t, ok := m.(*ExportedDroiddocDir); ok {
1000 *implicits = append(*implicits, t.deps...)
1001 flags += " --merge-annotations " + t.dir.String()
1002 } else {
1003 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
1004 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1005 }
1006 })
Nan Zhanga40da042018-08-01 12:48:00 -07001007 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1008 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1009 }
1010
1011 return flags
1012}
1013
Nan Zhang86d2d552018-08-09 15:33:27 -07001014func (d *Droiddoc) collectMetalavaJavadocFlags(ctx android.ModuleContext,
Nan Zhangde860a42018-08-08 16:32:21 -07001015 bootClasspathArgs, classpathArgs, outDir, docStubsDir string) string {
1016 return " --doc-stubs " + docStubsDir +
1017 " --write-doc-stubs-source-list " + android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
Nan Zhanga40da042018-08-01 12:48:00 -07001018 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
1019 bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhangde860a42018-08-08 16:32:21 -07001020 docStubsDir + " -quiet -d " + outDir
Nan Zhanga40da042018-08-01 12:48:00 -07001021}
1022
Nan Zhang86d2d552018-08-09 15:33:27 -07001023func (d *Droiddoc) collectMetalavaDokkaFlags(ctx android.ModuleContext, implicits *android.Paths,
1024 classpathArgs, outDir, docStubsDir string) string {
1025 dokka := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "dokka.jar")
1026 *implicits = append(*implicits, dokka)
1027
1028 return " --doc-stubs " + docStubsDir + " --write-doc-stubs-source-list " +
1029 android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
1030 " --generate-documentation ${config.JavaCmd} -jar " + dokka.String() + " " +
1031 docStubsDir + " " + classpathArgs + " -format dac -dacRoot /reference/kotlin -output " + outDir
1032}
1033
1034func (d *Droiddoc) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1035 implicitOutputs android.WritablePaths, outDir, docStubsDir, javaVersion,
1036 bootclasspathArgs, classpathArgs, opts string) {
1037 ctx.Build(pctx, android.BuildParams{
1038 Rule: metalava,
1039 Description: "Metalava",
1040 Output: d.Javadoc.stubsSrcJar,
1041 Inputs: d.Javadoc.srcFiles,
1042 Implicits: implicits,
1043 ImplicitOutputs: implicitOutputs,
1044 Args: map[string]string{
1045 "outDir": outDir,
1046 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1047 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1048 "docStubsDir": docStubsDir,
1049 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1050 "javaVersion": javaVersion,
1051 "bootclasspathArgs": bootclasspathArgs,
1052 "classpathArgs": classpathArgs,
1053 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1054 "docZip": d.Javadoc.docZip.String(),
1055 "opts": opts,
1056 },
1057 })
1058}
1059
1060func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1061 implicitOutputs android.WritablePaths, bootclasspathArgs, classpathArgs, opts, postDoclavaCmds string) {
1062 ctx.Build(pctx, android.BuildParams{
1063 Rule: javadoc,
1064 Description: "Doclava",
1065 Output: d.Javadoc.stubsSrcJar,
1066 Inputs: d.Javadoc.srcFiles,
1067 Implicits: implicits,
1068 ImplicitOutputs: implicitOutputs,
1069 Args: map[string]string{
1070 "outDir": android.PathForModuleOut(ctx, "out").String(),
1071 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1072 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1073 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1074 "opts": opts,
1075 "bootclasspathArgs": bootclasspathArgs,
1076 "classpathArgs": classpathArgs,
1077 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1078 "docZip": d.Javadoc.docZip.String(),
1079 "postDoclavaCmds": postDoclavaCmds,
1080 },
1081 })
1082}
1083
1084func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1085 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1086 ctx.Build(pctx, android.BuildParams{
1087 Rule: apiCheck,
Nan Zhanga05ff572018-08-20 20:33:38 -07001088 Description: "Doclava Check API",
Nan Zhang86d2d552018-08-09 15:33:27 -07001089 Output: output,
1090 Inputs: nil,
1091 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1092 checkApiClasspath...),
1093 Args: map[string]string{
1094 "classpath": checkApiClasspath.FormJavaClassPath(""),
1095 "opts": opts,
1096 "apiFile": apiFile.String(),
1097 "apiFileToCheck": d.apiFile.String(),
1098 "removedApiFile": removedApiFile.String(),
1099 "removedApiFileToCheck": d.removedApiFile.String(),
1100 "msg": msg,
1101 },
1102 })
1103}
1104
Nan Zhang2760dfc2018-08-24 17:32:54 +00001105func (d *Droiddoc) transformMetalavaCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1106 implicits android.Paths, javaVersion, bootclasspathArgs, classpathArgs, opts, msg string,
1107 output android.WritablePath) {
1108 ctx.Build(pctx, android.BuildParams{
1109 Rule: metalavaApiCheck,
1110 Description: "Metalava Check API",
1111 Output: output,
1112 Inputs: d.Javadoc.srcFiles,
1113 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1114 implicits...),
1115 Args: map[string]string{
1116 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1117 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1118 "javaVersion": javaVersion,
1119 "bootclasspathArgs": bootclasspathArgs,
1120 "classpathArgs": classpathArgs,
1121 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1122 "opts": opts,
1123 "msg": msg,
1124 },
1125 })
1126}
1127
Nan Zhang86d2d552018-08-09 15:33:27 -07001128func (d *Droiddoc) transformUpdateApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1129 output android.WritablePath) {
1130 ctx.Build(pctx, android.BuildParams{
1131 Rule: updateApi,
1132 Description: "Update API",
1133 Output: output,
1134 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1135 Args: map[string]string{
1136 "apiFile": apiFile.String(),
1137 "apiFileToCheck": d.apiFile.String(),
1138 "removedApiFile": removedApiFile.String(),
1139 "removedApiFileToCheck": d.removedApiFile.String(),
1140 },
1141 })
1142}
1143
Nan Zhanga40da042018-08-01 12:48:00 -07001144func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1145 deps := d.Javadoc.collectDeps(ctx)
1146
1147 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhanga40da042018-08-01 12:48:00 -07001148 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1149 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1150 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1151 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
Nan Zhang581fd212018-01-10 16:06:12 -08001152
Nan Zhanga40da042018-08-01 12:48:00 -07001153 var implicits android.Paths
1154 implicits = append(implicits, d.Javadoc.srcJars...)
1155
1156 var implicitOutputs android.WritablePaths
1157 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1158 for _, o := range d.properties.Out {
1159 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1160 }
1161
1162 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001163 metalavaCheckApiImplicits := implicits
Nan Zhanga40da042018-08-01 12:48:00 -07001164 if err != nil {
1165 return
1166 }
1167
1168 flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1169 if Bool(d.properties.Metalava_enabled) {
Nan Zhanga40da042018-08-01 12:48:00 -07001170 flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang86d2d552018-08-09 15:33:27 -07001171 outDir := android.PathForModuleOut(ctx, "out").String()
Nan Zhangde860a42018-08-08 16:32:21 -07001172 docStubsDir := android.PathForModuleOut(ctx, "docStubsDir").String()
Nan Zhang86d2d552018-08-09 15:33:27 -07001173 // TODO(nanzhang): Add a Soong property to handle documentation args.
1174 if strings.Contains(flags.args, "--generate-documentation") { // enable docs generation
1175 if Bool(d.properties.Dokka_enabled) {
1176 flags.metalavaDokkaFlags = d.collectMetalavaDokkaFlags(ctx, &implicits,
1177 flags.dokkaClasspathArgs, outDir, docStubsDir)
1178 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1179 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhang2760dfc2018-08-24 17:32:54 +00001180 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001181 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001182 flags.metalavaDokkaFlags+" "+strings.Split(flags.args, "--generate-documentation")[1])
1183 } else {
1184 flags.metalavaJavadocFlags = d.collectMetalavaJavadocFlags(
1185 ctx, flags.bootClasspathArgs, flags.classpathArgs, outDir, docStubsDir)
Nan Zhang443fa522018-08-20 20:58:28 -07001186 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhang86d2d552018-08-09 15:33:27 -07001187 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1188 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhang2760dfc2018-08-24 17:32:54 +00001189 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001190 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001191 flags.metalavaJavadocFlags+flags.doclavaDocsFlags+
1192 " "+strings.Split(flags.args, "--generate-documentation")[1])
1193 }
Nan Zhanga40da042018-08-01 12:48:00 -07001194 } else {
Nan Zhang86d2d552018-08-09 15:33:27 -07001195 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1196 flags.bootClasspathArgs, flags.classpathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001197 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+flags.args)
Nan Zhang79614d12018-04-19 18:03:39 -07001198 }
Nan Zhanga40da042018-08-01 12:48:00 -07001199 } else {
Nan Zhang443fa522018-08-20 20:58:28 -07001200 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhanga40da042018-08-01 12:48:00 -07001201 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
Nan Zhang86d2d552018-08-09 15:33:27 -07001202 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1203 flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+flags.args,
1204 flags.postDoclavaCmds)
Nan Zhang79614d12018-04-19 18:03:39 -07001205 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001206
Nan Zhang61819ce2018-05-04 18:49:16 -07001207 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001208 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1209 "check_api.current.api_file")
1210 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1211 "check_api.current_removed_api_file")
1212
Nan Zhang2760dfc2018-08-24 17:32:54 +00001213 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang55e0bf42018-08-16 16:23:11 -07001214 if !Bool(d.properties.Metalava_enabled) {
Nan Zhang55e0bf42018-08-16 16:23:11 -07001215 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1216 fmt.Sprintf(`\n******************************\n`+
1217 `You have tried to change the API from what has been previously approved.\n\n`+
1218 `To make these errors go away, you have two choices:\n`+
1219 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1220 ` errors above.\n\n`+
1221 ` 2. You can update current.txt by executing the following command:\n`+
1222 ` make %s-update-current-api\n\n`+
1223 ` To submit the revised current.txt to the main Android repository,\n`+
1224 ` you will need approval.\n`+
1225 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1226 d.checkCurrentApiTimestamp)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001227 } else {
1228 opts := flags.args + " --check-compatibility:api:current " + apiFile.String() +
1229 " --check-compatibility:removed:current " + removedApiFile.String() + " "
1230
1231 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1232 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts,
1233 fmt.Sprintf(`\n******************************\n`+
1234 `You have tried to change the API from what has been previously approved.\n\n`+
1235 `To make these errors go away, you have two choices:\n`+
1236 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1237 ` errors above.\n\n`+
1238 ` 2. You can update current.txt by executing the following command:\n`+
1239 ` make %s-update-current-api\n\n`+
1240 ` To submit the revised current.txt to the main Android repository,\n`+
1241 ` you will need approval.\n`+
1242 `******************************\n`, ctx.ModuleName()),
1243 d.checkCurrentApiTimestamp)
Nan Zhang55e0bf42018-08-16 16:23:11 -07001244 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001245
1246 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang86d2d552018-08-09 15:33:27 -07001247 d.transformUpdateApi(ctx, apiFile, removedApiFile, d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001248 }
Nan Zhanga40da042018-08-01 12:48:00 -07001249
Nan Zhang61819ce2018-05-04 18:49:16 -07001250 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001251 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1252 "check_api.last_released.api_file")
1253 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1254 "check_api.last_released.removed_api_file")
1255
Nan Zhang2760dfc2018-08-24 17:32:54 +00001256 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhanga05ff572018-08-20 20:33:38 -07001257 if !Bool(d.properties.Metalava_enabled) {
Nan Zhanga05ff572018-08-20 20:33:38 -07001258 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1259 `\n******************************\n`+
1260 `You have tried to change the API from what has been previously released in\n`+
1261 `an SDK. Please fix the errors listed above.\n`+
1262 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1263 d.checkLastReleasedApiTimestamp)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001264 } else {
1265 opts := flags.args + " --check-compatibility:api:released " + apiFile.String() +
1266 " --check-compatibility:removed:released " + removedApiFile.String() + " "
1267
1268 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1269 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts,
1270 `\n******************************\n`+
1271 `You have tried to change the API from what has been previously released in\n`+
1272 `an SDK. Please fix the errors listed above.\n`+
1273 `******************************\n`,
1274 d.checkLastReleasedApiTimestamp)
Nan Zhanga05ff572018-08-20 20:33:38 -07001275 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001276 }
Nan Zhang581fd212018-01-10 16:06:12 -08001277}
Dan Willemsencc090972018-02-26 14:33:31 -08001278
Nan Zhanga40da042018-08-01 12:48:00 -07001279//
Nan Zhangf4936b02018-08-01 15:00:28 -07001280// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001281//
Dan Willemsencc090972018-02-26 14:33:31 -08001282var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001283var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001284
Nan Zhangf4936b02018-08-01 15:00:28 -07001285type ExportedDroiddocDirProperties struct {
1286 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001287 Path *string
1288}
1289
Nan Zhangf4936b02018-08-01 15:00:28 -07001290type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001291 android.ModuleBase
1292
Nan Zhangf4936b02018-08-01 15:00:28 -07001293 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001294
1295 deps android.Paths
1296 dir android.Path
1297}
1298
Nan Zhangf4936b02018-08-01 15:00:28 -07001299func ExportedDroiddocDirFactory() android.Module {
1300 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001301 module.AddProperties(&module.properties)
1302 android.InitAndroidModule(module)
1303 return module
1304}
1305
Nan Zhangf4936b02018-08-01 15:00:28 -07001306func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001307
Nan Zhangf4936b02018-08-01 15:00:28 -07001308func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001309 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1310 d.dir = path
1311 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1312}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001313
1314//
1315// Defaults
1316//
1317type DocDefaults struct {
1318 android.ModuleBase
1319 android.DefaultsModuleBase
1320}
1321
1322func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1323}
1324
1325func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1326}
1327
1328func DocDefaultsFactory() android.Module {
1329 module := &DocDefaults{}
1330
1331 module.AddProperties(
1332 &JavadocProperties{},
1333 &DroiddocProperties{},
1334 )
1335
1336 android.InitDefaultsModule(module)
1337
1338 return module
1339}