blob: 787c4d7df4ae1d8ece36570384d8603625af9dc4 [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 Zhang40b41b42018-10-02 16:11:17 -070033 `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070034 `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` +
Nan Zhang581fd212018-01-10 16:06:12 -080035 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Colin Cross44c29a82019-01-24 16:36:57 -080037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds && ` +
38 `rm -rf "$srcJarDir"`,
39
Nan Zhang581fd212018-01-10 16:06:12 -080040 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070041 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 "${config.JavadocCmd}",
43 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080044 },
Nan Zhang40b41b42018-10-02 16:11:17 -070045 CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
46 Rspfile: "$out.rsp",
47 RspfileContent: "$in",
48 Restat: true,
Nan Zhang581fd212018-01-10 16:06:12 -080049 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070050 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang1598a9e2018-09-04 17:14:32 -070051 "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070052
53 apiCheck = pctx.AndroidStaticRule("apiCheck",
54 blueprint.RuleParams{
55 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
56 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090057 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070058 CommandDeps: []string{
59 "${config.ApiCheckCmd}",
60 },
61 },
62 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
63
64 updateApi = pctx.AndroidStaticRule("updateApi",
65 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070066 Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` +
Nan Zhang61819ce2018-05-04 18:49:16 -070067 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
68 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070069 "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile")
Nan Zhang79614d12018-04-19 18:03:39 -070070
71 metalava = pctx.AndroidStaticRule("metalava",
72 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070073 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
74 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070075 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070076 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -080077 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070078 `$opts && ` +
Colin Cross44c29a82019-01-24 16:36:57 -080079 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` +
80 `rm -rf "$srcJarDir"`,
Nan Zhang79614d12018-04-19 18:03:39 -070081 CommandDeps: []string{
82 "${config.ZipSyncCmd}",
83 "${config.JavaCmd}",
84 "${config.MetalavaJar}",
Nan Zhang79614d12018-04-19 18:03:39 -070085 "${config.SoongZipCmd}",
86 },
87 Rspfile: "$out.rsp",
88 RspfileContent: "$in",
89 Restat: true,
90 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070091 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
92 "classpathArgs", "sourcepathArgs", "opts")
Nan Zhang2760dfc2018-08-24 17:32:54 +000093
94 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
95 blueprint.RuleParams{
96 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
97 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
98 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -080099 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Colin Cross44c29a82019-01-24 16:36:57 -0800100 `$opts && touch $out && rm -rf "$srcJarDir") || ` +
Nan Zhang2760dfc2018-08-24 17:32:54 +0000101 `( echo -e "$msg" ; exit 38 )`,
102 CommandDeps: []string{
103 "${config.ZipSyncCmd}",
104 "${config.JavaCmd}",
105 "${config.MetalavaJar}",
106 },
107 Rspfile: "$out.rsp",
108 RspfileContent: "$in",
109 },
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg")
111
Pete Gillin581d6082018-10-22 15:55:04 +0100112 nullabilityWarningsCheck = pctx.AndroidStaticRule("nullabilityWarningsCheck",
113 blueprint.RuleParams{
114 Command: `( diff $expected $actual && touch $out ) || ( echo -e "$msg" ; exit 38 )`,
115 },
116 "expected", "actual", "msg")
117
Nan Zhang1598a9e2018-09-04 17:14:32 -0700118 dokka = pctx.AndroidStaticRule("dokka",
119 blueprint.RuleParams{
120 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
121 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
122 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
123 `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` +
124 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
125 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Colin Cross44c29a82019-01-24 16:36:57 -0800126 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` +
127 `rm -rf "$srcJarDir"`,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700128 CommandDeps: []string{
129 "${config.ZipSyncCmd}",
130 "${config.DokkaJar}",
131 "${config.MetalavaJar}",
132 "${config.SoongZipCmd}",
133 },
134 Restat: true,
135 },
136 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800137)
138
139func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800140 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700141 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800142
Nan Zhang581fd212018-01-10 16:06:12 -0800143 android.RegisterModuleType("droiddoc", DroiddocFactory)
144 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700145 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800146 android.RegisterModuleType("javadoc", JavadocFactory)
147 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700148
149 android.RegisterModuleType("droidstubs", DroidstubsFactory)
150 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800151}
152
Colin Crossa1ce2a02018-06-20 15:19:39 -0700153var (
154 srcsLibTag = dependencyTag{name: "sources from javalib"}
155)
156
Nan Zhang581fd212018-01-10 16:06:12 -0800157type JavadocProperties struct {
158 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
159 // or .aidl files.
160 Srcs []string `android:"arch_variant"`
161
162 // list of directories rooted at the Android.bp file that will
163 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800164 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800165
166 // list of source files that should not be used to build the Java module.
167 // This is most useful in the arch/multilib variants to remove non-common files
168 // filegroup or genrule can be included within this property.
169 Exclude_srcs []string `android:"arch_variant"`
170
Nan Zhangb2b33de2018-02-23 11:18:47 -0800171 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800172 Libs []string `android:"arch_variant"`
173
Nan Zhang5994b622018-09-21 16:39:51 -0700174 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
175 // ext, and framework for device targets)
176 No_standard_libs *bool
177
Nan Zhange66c7272018-03-06 12:59:27 -0800178 // don't build against the framework libraries (legacy-test, core-junit,
179 // ext, and framework for device targets)
180 No_framework_libs *bool
181
Nan Zhangb2b33de2018-02-23 11:18:47 -0800182 // the java library (in classpath) for documentation that provides java srcs and srcjars.
183 Srcs_lib *string
184
185 // the base dirs under srcs_lib will be scanned for java srcs.
186 Srcs_lib_whitelist_dirs []string
187
188 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
189 Srcs_lib_whitelist_pkgs []string
190
Nan Zhang581fd212018-01-10 16:06:12 -0800191 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800192 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800193
194 // if not blank, set to the version of the sdk to compile against
195 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900196
197 Aidl struct {
198 // Top level directories to pass to aidl tool
199 Include_dirs []string
200
201 // Directories rooted at the Android.bp file to pass to aidl tool
202 Local_include_dirs []string
203 }
Nan Zhang357466b2018-04-17 17:38:36 -0700204
205 // If not blank, set the java version passed to javadoc as -source
206 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700207
208 // local files that are used within user customized droiddoc options.
209 Arg_files []string
210
211 // user customized droiddoc args.
212 // Available variables for substitution:
213 //
214 // $(location <label>): the path to the arg_files with name <label>
215 Args *string
216
217 // names of the output files used in args that will be generated
218 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800219}
220
Nan Zhang61819ce2018-05-04 18:49:16 -0700221type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900222 // path to the API txt file that the new API extracted from source code is checked
223 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700224 Api_file *string
225
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900226 // path to the API txt file that the new @removed API extractd from source code is
227 // checked against. The path can be local to the module or from other module (via
228 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700229 Removed_api_file *string
230
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900231 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700232 Args *string
233}
234
Nan Zhang581fd212018-01-10 16:06:12 -0800235type DroiddocProperties struct {
236 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800237 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800238
Nan Zhanga40da042018-08-01 12:48:00 -0700239 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800240 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800241
242 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800243 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800244
245 // proofread file contains all of the text content of the javadocs concatenated into one file,
246 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800247 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800248
249 // a todo file lists the program elements that are missing documentation.
250 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800251 Todo_file *string
252
253 // directory under current module source that provide additional resources (images).
254 Resourcesdir *string
255
256 // resources output directory under out/soong/.intermediates.
257 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800258
Nan Zhange2ba5d42018-07-11 15:16:55 -0700259 // if set to true, collect the values used by the Dev tools and
260 // write them in files packaged with the SDK. Defaults to false.
261 Write_sdk_values *bool
262
263 // index.html under current module will be copied to docs out dir, if not null.
264 Static_doc_index_redirect *string
265
266 // source.properties under current module will be copied to docs out dir, if not null.
267 Static_doc_properties *string
268
Nan Zhang581fd212018-01-10 16:06:12 -0800269 // a list of files under current module source dir which contains known tags in Java sources.
270 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800271 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700272
273 // the tag name used to distinguish if the API files belong to public/system/test.
274 Api_tag_name *string
275
276 // the generated public API filename by Doclava.
277 Api_filename *string
278
David Brazdilfbe4cc32018-05-31 13:56:46 +0100279 // the generated public Dex API filename by Doclava.
280 Dex_api_filename *string
281
Nan Zhang28c68b92018-03-13 16:17:01 -0700282 // the generated private API filename by Doclava.
283 Private_api_filename *string
284
285 // the generated private Dex API filename by Doclava.
286 Private_dex_api_filename *string
287
288 // the generated removed API filename by Doclava.
289 Removed_api_filename *string
290
David Brazdilaac0c3c2018-04-24 16:23:29 +0100291 // the generated removed Dex API filename by Doclava.
292 Removed_dex_api_filename *string
293
Mathew Inwood76c3de12018-06-22 15:28:11 +0100294 // mapping of dex signatures to source file and line number. This is a temporary property and
295 // will be deleted; you probably shouldn't be using it.
296 Dex_mapping_filename *string
297
Nan Zhang28c68b92018-03-13 16:17:01 -0700298 // the generated exact API filename by Doclava.
299 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700300
Nan Zhang66dc2362018-08-14 20:41:04 -0700301 // the generated proguard filename by Doclava.
302 Proguard_filename *string
303
Nan Zhang853f4202018-04-12 16:55:56 -0700304 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
305 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700306
307 Check_api struct {
308 Last_released ApiToCheck
309
310 Current ApiToCheck
311 }
Nan Zhang79614d12018-04-19 18:03:39 -0700312
Nan Zhang1598a9e2018-09-04 17:14:32 -0700313 // if set to true, generate docs through Dokka instead of Doclava.
314 Dokka_enabled *bool
315}
316
317type DroidstubsProperties struct {
318 // the tag name used to distinguish if the API files belong to public/system/test.
319 Api_tag_name *string
320
Nan Zhang199645c2018-09-19 12:40:06 -0700321 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700322 Api_filename *string
323
Nan Zhang199645c2018-09-19 12:40:06 -0700324 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700325 Dex_api_filename *string
326
Nan Zhang199645c2018-09-19 12:40:06 -0700327 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700328 Private_api_filename *string
329
Nan Zhang199645c2018-09-19 12:40:06 -0700330 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700331 Private_dex_api_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Removed_api_filename *string
335
Nan Zhang199645c2018-09-19 12:40:06 -0700336 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700337 Removed_dex_api_filename *string
338
Nan Zhang9c69a122018-08-22 10:22:08 -0700339 // mapping of dex signatures to source file and line number. This is a temporary property and
340 // will be deleted; you probably shouldn't be using it.
341 Dex_mapping_filename *string
342
Nan Zhang199645c2018-09-19 12:40:06 -0700343 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700344 Exact_api_filename *string
345
Nan Zhang199645c2018-09-19 12:40:06 -0700346 // the generated proguard filename by Metalava.
347 Proguard_filename *string
348
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349 Check_api struct {
350 Last_released ApiToCheck
351
352 Current ApiToCheck
353 }
Nan Zhang79614d12018-04-19 18:03:39 -0700354
355 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700356 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700357
358 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700359 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700360
Pete Gillin77167902018-09-19 18:16:26 +0100361 // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700362 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700363
Pete Gillin77167902018-09-19 18:16:26 +0100364 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
365 Merge_inclusion_annotations_dirs []string
366
Pete Gillinc382a562018-11-14 18:45:46 +0000367 // a file containing a list of classes to do nullability validation for.
368 Validate_nullability_from_list *string
369
Pete Gillin581d6082018-10-22 15:55:04 +0100370 // a file containing expected warnings produced by validation of nullability annotations.
371 Check_nullability_warnings *string
372
Nan Zhang1598a9e2018-09-04 17:14:32 -0700373 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
374 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700375
376 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
377 Api_levels_annotations_enabled *bool
378
379 // the dirs which Metalava extracts API levels annotations from.
380 Api_levels_annotations_dirs []string
381
382 // if set to true, collect the values used by the Dev tools and
383 // write them in files packaged with the SDK. Defaults to false.
384 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700385
386 // If set to true, .xml based public API file will be also generated, and
387 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
388 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800389}
390
Nan Zhanga40da042018-08-01 12:48:00 -0700391//
392// Common flags passed down to build rule
393//
394type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700395 bootClasspathArgs string
396 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700397 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700398 dokkaClasspathArgs string
399 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700400
Nan Zhanga40da042018-08-01 12:48:00 -0700401 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700402 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700403 postDoclavaCmds string
404
Nan Zhang9c69a122018-08-22 10:22:08 -0700405 metalavaStubsFlags string
406 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800407 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100408 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700409 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700410
Nan Zhang71bbe632018-09-17 14:32:21 -0700411 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700412}
413
414func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
415 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
416 android.InitDefaultableModule(module)
417}
418
Nan Zhang1598a9e2018-09-04 17:14:32 -0700419func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
420 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
421 return true
422 } else if String(apiToCheck.Api_file) != "" {
423 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
424 } else if String(apiToCheck.Removed_api_file) != "" {
425 panic("for " + apiVersionTag + " api_file has to be non-empty!")
426 }
427
428 return false
429}
430
431type ApiFilePath interface {
432 ApiFilePath() android.Path
433}
434
435func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
436 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
437 ctx.Build(pctx, android.BuildParams{
438 Rule: updateApi,
439 Description: "Update API",
440 Output: output,
441 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
442 destApiFile, destRemovedApiFile),
443 Args: map[string]string{
444 "destApiFile": destApiFile.String(),
445 "srcApiFile": srcApiFile.String(),
446 "destRemovedApiFile": destRemovedApiFile.String(),
447 "srcRemovedApiFile": srcRemovedApiFile.String(),
448 },
449 })
450}
451
Nan Zhanga40da042018-08-01 12:48:00 -0700452//
453// Javadoc
454//
Nan Zhang581fd212018-01-10 16:06:12 -0800455type Javadoc struct {
456 android.ModuleBase
457 android.DefaultableModuleBase
458
459 properties JavadocProperties
460
461 srcJars android.Paths
462 srcFiles android.Paths
463 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700464 argFiles android.Paths
465
466 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800467
Nan Zhangccff0f72018-03-08 17:26:16 -0800468 docZip android.WritablePath
469 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800470}
471
Nan Zhangb2b33de2018-02-23 11:18:47 -0800472func (j *Javadoc) Srcs() android.Paths {
473 return android.Paths{j.stubsSrcJar}
474}
475
Nan Zhang581fd212018-01-10 16:06:12 -0800476func JavadocFactory() android.Module {
477 module := &Javadoc{}
478
479 module.AddProperties(&module.properties)
480
481 InitDroiddocModule(module, android.HostAndDeviceSupported)
482 return module
483}
484
485func JavadocHostFactory() android.Module {
486 module := &Javadoc{}
487
488 module.AddProperties(&module.properties)
489
490 InitDroiddocModule(module, android.HostSupported)
491 return module
492}
493
Nan Zhanga40da042018-08-01 12:48:00 -0700494var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800495
Colin Cross83bb3162018-06-25 15:48:06 -0700496func (j *Javadoc) sdkVersion() string {
497 return String(j.properties.Sdk_version)
498}
499
500func (j *Javadoc) minSdkVersion() string {
501 return j.sdkVersion()
502}
503
Dan Willemsen419290a2018-10-31 15:28:47 -0700504func (j *Javadoc) targetSdkVersion() string {
505 return j.sdkVersion()
506}
507
Nan Zhang581fd212018-01-10 16:06:12 -0800508func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
509 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700510 if !Bool(j.properties.No_standard_libs) {
511 sdkDep := decodeSdkDep(ctx, sdkContext(j))
512 if sdkDep.useDefaultLibs {
513 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
514 if ctx.Config().TargetOpenJDK9() {
515 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
516 }
517 if !Bool(j.properties.No_framework_libs) {
518 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
519 }
520 } else if sdkDep.useModule {
521 if ctx.Config().TargetOpenJDK9() {
522 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
523 }
524 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700525 }
Nan Zhang581fd212018-01-10 16:06:12 -0800526 }
527 }
528
Colin Cross42d48b72018-08-29 14:10:52 -0700529 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700530 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700531 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700532 }
Nan Zhang581fd212018-01-10 16:06:12 -0800533
534 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
535
536 // exclude_srcs may contain filegroup or genrule.
537 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700538
539 // arg_files may contains filegroup or genrule.
540 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800541}
542
Nan Zhangb2b33de2018-02-23 11:18:47 -0800543func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
544 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
545 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900546 // convert foo.bar.baz to foo/bar/baz
547 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
548 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800549 if _, found := whitelistPathPrefixes[prefix]; !found {
550 whitelistPathPrefixes[prefix] = true
551 }
552 }
553 }
554}
555
Nan Zhanga40da042018-08-01 12:48:00 -0700556func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
557 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900558
559 // aidl flags.
560 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
561 if len(aidlFlags) > 0 {
562 // optimization.
563 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
564 flags.aidlFlags = "$aidlFlags"
565 }
566
567 return flags
568}
569
570func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
571 aidlIncludeDirs android.Paths) []string {
572
573 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
574 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
575
576 var flags []string
577 if aidlPreprocess.Valid() {
578 flags = append(flags, "-p"+aidlPreprocess.String())
579 } else {
580 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
581 }
582
583 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
584 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
585 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
586 flags = append(flags, "-I"+src.String())
587 }
588
589 return flags
590}
591
592func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700593 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900594
595 outSrcFiles := make(android.Paths, 0, len(srcFiles))
596
597 for _, srcFile := range srcFiles {
598 switch srcFile.Ext() {
599 case ".aidl":
600 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
601 outSrcFiles = append(outSrcFiles, javaFile)
602 default:
603 outSrcFiles = append(outSrcFiles, srcFile)
604 }
605 }
606
607 return outSrcFiles
608}
609
Nan Zhang581fd212018-01-10 16:06:12 -0800610func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
611 var deps deps
612
Colin Cross83bb3162018-06-25 15:48:06 -0700613 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800614 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700615 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800616 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700617 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800618 }
619
620 ctx.VisitDirectDeps(func(module android.Module) {
621 otherName := ctx.OtherModuleName(module)
622 tag := ctx.OtherModuleDependencyTag(module)
623
Colin Cross2d24c1b2018-05-23 10:59:18 -0700624 switch tag {
625 case bootClasspathTag:
626 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800627 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700628 } else {
629 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
630 }
631 case libTag:
632 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800633 case SdkLibraryDependency:
634 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700635 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900636 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700637 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800638 checkProducesJars(ctx, dep)
639 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800640 default:
641 ctx.ModuleErrorf("depends on non-java module %q", otherName)
642 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700643 case srcsLibTag:
644 switch dep := module.(type) {
645 case Dependency:
646 srcs := dep.(SrcDependency).CompiledSrcs()
647 whitelistPathPrefixes := make(map[string]bool)
648 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
649 for _, src := range srcs {
650 if _, ok := src.(android.WritablePath); ok { // generated sources
651 deps.srcs = append(deps.srcs, src)
652 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700653 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700654 if strings.HasPrefix(src.Rel(), k) {
655 deps.srcs = append(deps.srcs, src)
656 break
657 }
658 }
659 }
660 }
661 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
662 default:
663 ctx.ModuleErrorf("depends on non-java module %q", otherName)
664 }
Nan Zhang357466b2018-04-17 17:38:36 -0700665 case systemModulesTag:
666 if deps.systemModules != nil {
667 panic("Found two system module dependencies")
668 }
669 sm := module.(*SystemModules)
670 if sm.outputFile == nil {
671 panic("Missing directory for system module dependency")
672 }
673 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800674 }
675 })
676 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
677 // may contain filegroup or genrule.
678 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700679 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900680 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800681
682 // srcs may depend on some genrule output.
683 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800684 j.srcJars = append(j.srcJars, deps.srcJars...)
685
Nan Zhang581fd212018-01-10 16:06:12 -0800686 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800687 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800688
689 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800690 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800691
Nan Zhang9c69a122018-08-22 10:22:08 -0700692 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800693 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
694 }
695 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800696
Nan Zhang1598a9e2018-09-04 17:14:32 -0700697 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
Paul Duffin99e4a502019-02-11 15:38:42 +0000698 argFilesMap := map[string]string{}
699 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700700
Paul Duffin99e4a502019-02-11 15:38:42 +0000701 for _, label := range j.properties.Arg_files {
702 var paths = ctx.ExpandSources([]string{label}, nil)
703 if _, exists := argFilesMap[label]; !exists {
704 argFilesMap[label] = strings.Join(paths.Strings(), " ")
705 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700706 } else {
707 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000708 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700709 }
710 }
711
712 var err error
713 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
714 if strings.HasPrefix(name, "location ") {
715 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000716 if paths, ok := argFilesMap[label]; ok {
717 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700718 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000719 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
720 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700721 }
722 } else if name == "genDir" {
723 return android.PathForModuleGen(ctx).String(), nil
724 }
725 return "", fmt.Errorf("unknown variable '$(%s)'", name)
726 })
727
728 if err != nil {
729 ctx.PropertyErrorf("args", "%s", err.Error())
730 }
731
Nan Zhang581fd212018-01-10 16:06:12 -0800732 return deps
733}
734
735func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
736 j.addDeps(ctx)
737}
738
739func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
740 deps := j.collectDeps(ctx)
741
742 var implicits android.Paths
743 implicits = append(implicits, deps.bootClasspath...)
744 implicits = append(implicits, deps.classpath...)
745
Nan Zhang1598a9e2018-09-04 17:14:32 -0700746 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700747
Colin Cross83bb3162018-06-25 15:48:06 -0700748 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700749 if len(deps.bootClasspath) > 0 {
750 var systemModules classpath
751 if deps.systemModules != nil {
752 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800753 }
Colin Cross997262f2018-06-19 22:49:39 -0700754 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
755 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800756 }
757 if len(deps.classpath.Strings()) > 0 {
758 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
759 }
760
761 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700762 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800763
Nan Zhangaf322cc2018-06-19 15:15:38 -0700764 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800765
Nan Zhang1598a9e2018-09-04 17:14:32 -0700766 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
767
Nan Zhang581fd212018-01-10 16:06:12 -0800768 ctx.Build(pctx, android.BuildParams{
769 Rule: javadoc,
770 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800771 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800772 ImplicitOutput: j.docZip,
773 Inputs: j.srcFiles,
774 Implicits: implicits,
775 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700776 "outDir": android.PathForModuleOut(ctx, "out").String(),
777 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
778 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800779 "srcJars": strings.Join(j.srcJars.Strings(), " "),
780 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700781 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800782 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700783 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800784 "docZip": j.docZip.String(),
785 },
786 })
787}
788
Nan Zhanga40da042018-08-01 12:48:00 -0700789//
790// Droiddoc
791//
792type Droiddoc struct {
793 Javadoc
794
795 properties DroiddocProperties
796 apiFile android.WritablePath
797 dexApiFile android.WritablePath
798 privateApiFile android.WritablePath
799 privateDexApiFile android.WritablePath
800 removedApiFile android.WritablePath
801 removedDexApiFile android.WritablePath
802 exactApiFile android.WritablePath
803 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700804 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700805
806 checkCurrentApiTimestamp android.WritablePath
807 updateCurrentApiTimestamp android.WritablePath
808 checkLastReleasedApiTimestamp android.WritablePath
809
Nan Zhanga40da042018-08-01 12:48:00 -0700810 apiFilePath android.Path
811}
812
Nan Zhanga40da042018-08-01 12:48:00 -0700813func DroiddocFactory() android.Module {
814 module := &Droiddoc{}
815
816 module.AddProperties(&module.properties,
817 &module.Javadoc.properties)
818
819 InitDroiddocModule(module, android.HostAndDeviceSupported)
820 return module
821}
822
823func DroiddocHostFactory() android.Module {
824 module := &Droiddoc{}
825
826 module.AddProperties(&module.properties,
827 &module.Javadoc.properties)
828
829 InitDroiddocModule(module, android.HostSupported)
830 return module
831}
832
833func (d *Droiddoc) ApiFilePath() android.Path {
834 return d.apiFilePath
835}
836
Nan Zhang581fd212018-01-10 16:06:12 -0800837func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
838 d.Javadoc.addDeps(ctx)
839
Nan Zhang79614d12018-04-19 18:03:39 -0700840 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800841 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
842 }
843
Nan Zhang581fd212018-01-10 16:06:12 -0800844 // knowntags may contain filegroup or genrule.
845 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700846
Nan Zhange2ba5d42018-07-11 15:16:55 -0700847 if String(d.properties.Static_doc_index_redirect) != "" {
848 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
849 }
850
851 if String(d.properties.Static_doc_properties) != "" {
852 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
853 }
854
Nan Zhang1598a9e2018-09-04 17:14:32 -0700855 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700856 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
857 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
858 }
859
Nan Zhang1598a9e2018-09-04 17:14:32 -0700860 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700861 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
862 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
863 }
Nan Zhang581fd212018-01-10 16:06:12 -0800864}
865
Nan Zhang66dc2362018-08-14 20:41:04 -0700866func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
867 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700868 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800869
Nan Zhanga40da042018-08-01 12:48:00 -0700870 *implicits = append(*implicits, deps.bootClasspath...)
871 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800872
Nan Zhangc94f9d82018-06-26 10:02:26 -0700873 if len(deps.bootClasspath.Strings()) > 0 {
874 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700875 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700876 }
Nan Zhanga40da042018-08-01 12:48:00 -0700877 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700878 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700879 dokkaClasspath := classpath{}
880 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
881 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
882 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700883
Nan Zhang9c69a122018-08-22 10:22:08 -0700884 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
885 // based stubs generation.
886 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
887 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
888 // the correct package name base path.
889 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
890 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
891 } else {
892 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
893 }
Nan Zhang581fd212018-01-10 16:06:12 -0800894
Nan Zhanga40da042018-08-01 12:48:00 -0700895 return flags, nil
896}
Nan Zhang581fd212018-01-10 16:06:12 -0800897
Nan Zhanga40da042018-08-01 12:48:00 -0700898func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700899 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800900
Nan Zhanga40da042018-08-01 12:48:00 -0700901 *implicits = append(*implicits, jsilver)
902 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700903
Nan Zhang46130972018-06-04 11:28:01 -0700904 var date string
905 if runtime.GOOS == "darwin" {
906 date = `date -r`
907 } else {
908 date = `date -d`
909 }
910
Nan Zhang443fa522018-08-20 20:58:28 -0700911 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
912 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
913 // 1.9 language features.
914 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700915 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800916 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700917 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700918
Nan Zhanga40da042018-08-01 12:48:00 -0700919 if String(d.properties.Custom_template) == "" {
920 // TODO: This is almost always droiddoc-templates-sdk
921 ctx.PropertyErrorf("custom_template", "must specify a template")
922 }
923
924 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700925 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700926 *implicits = append(*implicits, t.deps...)
927 args = args + " -templatedir " + t.dir.String()
928 } else {
929 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
930 }
931 })
932
933 if len(d.properties.Html_dirs) > 0 {
934 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
935 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
936 args = args + " -htmldir " + htmlDir.String()
937 }
938
939 if len(d.properties.Html_dirs) > 1 {
940 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
941 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
942 args = args + " -htmldir2 " + htmlDir2.String()
943 }
944
945 if len(d.properties.Html_dirs) > 2 {
946 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
947 }
948
949 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
950 *implicits = append(*implicits, knownTags...)
951
952 for _, kt := range knownTags {
953 args = args + " -knowntags " + kt.String()
954 }
955
956 for _, hdf := range d.properties.Hdf {
957 args = args + " -hdf " + hdf
958 }
959
960 if String(d.properties.Proofread_file) != "" {
961 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
962 args = args + " -proofread " + proofreadFile.String()
963 }
964
965 if String(d.properties.Todo_file) != "" {
966 // tricky part:
967 // we should not compute full path for todo_file through PathForModuleOut().
968 // the non-standard doclet will get the full path relative to "-o".
969 args = args + " -todo " + String(d.properties.Todo_file)
970 }
971
972 if String(d.properties.Resourcesdir) != "" {
973 // TODO: should we add files under resourcesDir to the implicits? It seems that
974 // resourcesDir is one sub dir of htmlDir
975 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
976 args = args + " -resourcesdir " + resourcesDir.String()
977 }
978
979 if String(d.properties.Resourcesoutdir) != "" {
980 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
981 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
982 }
983 return args
984}
985
Nan Zhang1598a9e2018-09-04 17:14:32 -0700986func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
987 implicitOutputs *android.WritablePaths) string {
988 var doclavaFlags string
989 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
990 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
991 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700992 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
993 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700994 *implicitOutputs = append(*implicitOutputs, d.apiFile)
995 d.apiFilePath = d.apiFile
996 }
997
Nan Zhang1598a9e2018-09-04 17:14:32 -0700998 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
999 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1000 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001001 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1002 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001003 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1004 }
1005
1006 if String(d.properties.Private_api_filename) != "" {
1007 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1008 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001009 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1010 }
1011
1012 if String(d.properties.Dex_api_filename) != "" {
1013 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1014 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1015 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1016 }
1017
1018 if String(d.properties.Private_dex_api_filename) != "" {
1019 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1020 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001021 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1022 }
1023
1024 if String(d.properties.Removed_dex_api_filename) != "" {
1025 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1026 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001027 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1028 }
1029
1030 if String(d.properties.Exact_api_filename) != "" {
1031 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1032 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001033 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1034 }
1035
1036 if String(d.properties.Dex_mapping_filename) != "" {
1037 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1038 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001039 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1040 }
1041
Nan Zhang66dc2362018-08-14 20:41:04 -07001042 if String(d.properties.Proguard_filename) != "" {
1043 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1044 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001045 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1046 }
1047
Nan Zhanga40da042018-08-01 12:48:00 -07001048 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001049 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001050 }
1051
1052 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001053 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001054 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001055
1056 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001057}
1058
1059func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1060 var cmds string
1061 if String(d.properties.Static_doc_index_redirect) != "" {
1062 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1063 "static_doc_index_redirect")
1064 *implicits = append(*implicits, static_doc_index_redirect)
1065 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001066 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001067 }
1068
1069 if String(d.properties.Static_doc_properties) != "" {
1070 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1071 "static_doc_properties")
1072 *implicits = append(*implicits, static_doc_properties)
1073 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001074 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001075 }
1076 return cmds
1077}
1078
Nan Zhang1598a9e2018-09-04 17:14:32 -07001079func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1080 implicitOutputs android.WritablePaths,
1081 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1082 ctx.Build(pctx, android.BuildParams{
1083 Rule: javadoc,
1084 Description: "Doclava",
1085 Output: d.Javadoc.stubsSrcJar,
1086 Inputs: d.Javadoc.srcFiles,
1087 Implicits: implicits,
1088 ImplicitOutputs: implicitOutputs,
1089 Args: map[string]string{
1090 "outDir": android.PathForModuleOut(ctx, "out").String(),
1091 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1092 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1093 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1094 "opts": opts,
1095 "bootclasspathArgs": bootclasspathArgs,
1096 "classpathArgs": classpathArgs,
1097 "sourcepathArgs": sourcepathArgs,
1098 "docZip": d.Javadoc.docZip.String(),
1099 "postDoclavaCmds": postDoclavaCmds,
1100 },
1101 })
1102}
1103
1104func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1105 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1106 ctx.Build(pctx, android.BuildParams{
1107 Rule: apiCheck,
1108 Description: "Doclava Check API",
1109 Output: output,
1110 Inputs: nil,
1111 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1112 checkApiClasspath...),
1113 Args: map[string]string{
1114 "msg": msg,
1115 "classpath": checkApiClasspath.FormJavaClassPath(""),
1116 "opts": opts,
1117 "apiFile": apiFile.String(),
1118 "apiFileToCheck": d.apiFile.String(),
1119 "removedApiFile": removedApiFile.String(),
1120 "removedApiFileToCheck": d.removedApiFile.String(),
1121 },
1122 })
1123}
1124
1125func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1126 classpathArgs, opts string) {
1127 ctx.Build(pctx, android.BuildParams{
1128 Rule: dokka,
1129 Description: "Dokka",
1130 Output: d.Javadoc.stubsSrcJar,
1131 Inputs: d.Javadoc.srcFiles,
1132 Implicits: implicits,
1133 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001134 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1135 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1136 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001137 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1138 "classpathArgs": classpathArgs,
1139 "opts": opts,
1140 "docZip": d.Javadoc.docZip.String(),
1141 },
1142 })
1143}
1144
1145func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1146 deps := d.Javadoc.collectDeps(ctx)
1147
1148 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")}
1152
1153 var implicits android.Paths
1154 implicits = append(implicits, d.Javadoc.srcJars...)
1155 implicits = append(implicits, d.Javadoc.argFiles...)
1156
1157 var implicitOutputs android.WritablePaths
1158 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1159 for _, o := range d.Javadoc.properties.Out {
1160 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1161 }
1162
1163 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1164 if err != nil {
1165 return
1166 }
1167
1168 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1169 if Bool(d.properties.Dokka_enabled) {
1170 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1171 } else {
1172 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1173 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1174 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1175 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1176 flags.postDoclavaCmds)
1177 }
1178
1179 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1180 !ctx.Config().IsPdkBuild() {
1181 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1182 "check_api.current.api_file")
1183 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1184 "check_api.current_removed_api_file")
1185
1186 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1187 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1188 fmt.Sprintf(`\n******************************\n`+
1189 `You have tried to change the API from what has been previously approved.\n\n`+
1190 `To make these errors go away, you have two choices:\n`+
1191 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1192 ` errors above.\n\n`+
1193 ` 2. You can update current.txt by executing the following command:\n`+
1194 ` make %s-update-current-api\n\n`+
1195 ` To submit the revised current.txt to the main Android repository,\n`+
1196 ` you will need approval.\n`+
1197 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1198 d.checkCurrentApiTimestamp)
1199
1200 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1201 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1202 d.updateCurrentApiTimestamp)
1203 }
1204
1205 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1206 !ctx.Config().IsPdkBuild() {
1207 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1208 "check_api.last_released.api_file")
1209 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1210 "check_api.last_released.removed_api_file")
1211
1212 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1213 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1214 `\n******************************\n`+
1215 `You have tried to change the API from what has been previously released in\n`+
1216 `an SDK. Please fix the errors listed above.\n`+
1217 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1218 d.checkLastReleasedApiTimestamp)
1219 }
1220}
1221
1222//
1223// Droidstubs
1224//
1225type Droidstubs struct {
1226 Javadoc
1227
Pete Gillin581d6082018-10-22 15:55:04 +01001228 properties DroidstubsProperties
1229 apiFile android.WritablePath
1230 apiXmlFile android.WritablePath
1231 lastReleasedApiXmlFile android.WritablePath
1232 dexApiFile android.WritablePath
1233 privateApiFile android.WritablePath
1234 privateDexApiFile android.WritablePath
1235 removedApiFile android.WritablePath
1236 removedDexApiFile android.WritablePath
1237 apiMappingFile android.WritablePath
1238 exactApiFile android.WritablePath
1239 proguardFile android.WritablePath
1240 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001241
1242 checkCurrentApiTimestamp android.WritablePath
1243 updateCurrentApiTimestamp android.WritablePath
1244 checkLastReleasedApiTimestamp android.WritablePath
1245
Pete Gillin581d6082018-10-22 15:55:04 +01001246 checkNullabilityWarningsTimestamp android.WritablePath
1247
Nan Zhang1598a9e2018-09-04 17:14:32 -07001248 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001249 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001250
1251 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001252
1253 jdiffDocZip android.WritablePath
1254 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001255}
1256
1257func DroidstubsFactory() android.Module {
1258 module := &Droidstubs{}
1259
1260 module.AddProperties(&module.properties,
1261 &module.Javadoc.properties)
1262
1263 InitDroiddocModule(module, android.HostAndDeviceSupported)
1264 return module
1265}
1266
1267func DroidstubsHostFactory() android.Module {
1268 module := &Droidstubs{}
1269
1270 module.AddProperties(&module.properties,
1271 &module.Javadoc.properties)
1272
1273 InitDroiddocModule(module, android.HostSupported)
1274 return module
1275}
1276
1277func (d *Droidstubs) ApiFilePath() android.Path {
1278 return d.apiFilePath
1279}
1280
1281func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1282 d.Javadoc.addDeps(ctx)
1283
1284 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1285 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1286 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1287 }
1288
1289 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1290 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1291 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1292 }
1293
1294 if String(d.properties.Previous_api) != "" {
1295 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1296 }
1297
1298 if len(d.properties.Merge_annotations_dirs) != 0 {
1299 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1300 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1301 }
1302 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001303
Pete Gillin77167902018-09-19 18:16:26 +01001304 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1305 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1306 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1307 }
1308 }
1309
Pete Gillinc382a562018-11-14 18:45:46 +00001310 if String(d.properties.Validate_nullability_from_list) != "" {
1311 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1312 }
Pete Gillin581d6082018-10-22 15:55:04 +01001313 if String(d.properties.Check_nullability_warnings) != "" {
1314 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1315 }
1316
Nan Zhang9c69a122018-08-22 10:22:08 -07001317 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1318 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1319 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1320 }
1321 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001322}
1323
1324func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1325 deps deps) (droiddocBuilderFlags, error) {
1326 var flags droiddocBuilderFlags
1327
1328 *implicits = append(*implicits, deps.bootClasspath...)
1329 *implicits = append(*implicits, deps.classpath...)
1330
1331 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1332 // since it doesn't support system modules yet.
1333 if len(deps.bootClasspath.Strings()) > 0 {
1334 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1335 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1336 }
1337 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1338
Sundong Ahn56dce442018-10-05 18:41:09 +09001339 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001340 return flags, nil
1341}
1342
1343func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1344 implicitOutputs *android.WritablePaths) string {
1345 var metalavaFlags string
1346 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1347 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1348 String(d.properties.Api_filename) != "" {
1349 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1350 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1351 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1352 d.apiFilePath = d.apiFile
1353 }
1354
1355 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1356 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1357 String(d.properties.Removed_api_filename) != "" {
1358 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1359 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1360 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1361 }
1362
1363 if String(d.properties.Private_api_filename) != "" {
1364 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1365 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1366 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1367 }
1368
1369 if String(d.properties.Dex_api_filename) != "" {
1370 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1371 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1372 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1373 }
1374
1375 if String(d.properties.Private_dex_api_filename) != "" {
1376 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1377 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1378 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1379 }
1380
1381 if String(d.properties.Removed_dex_api_filename) != "" {
1382 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1383 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1384 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1385 }
1386
1387 if String(d.properties.Exact_api_filename) != "" {
1388 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1389 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1390 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1391 }
1392
Nan Zhang9c69a122018-08-22 10:22:08 -07001393 if String(d.properties.Dex_mapping_filename) != "" {
1394 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1395 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1396 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1397 }
1398
Nan Zhang199645c2018-09-19 12:40:06 -07001399 if String(d.properties.Proguard_filename) != "" {
1400 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1401 metalavaFlags += " --proguard " + d.proguardFile.String()
1402 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1403 }
1404
Nan Zhang9c69a122018-08-22 10:22:08 -07001405 if Bool(d.properties.Write_sdk_values) {
1406 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1407 }
1408
Nan Zhang1598a9e2018-09-04 17:14:32 -07001409 if Bool(d.properties.Create_doc_stubs) {
1410 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1411 } else {
1412 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1413 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001414 return metalavaFlags
1415}
1416
1417func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001418 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1419 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001420 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001421 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001422 validatingNullability :=
1423 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1424 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001425 migratingNullability := String(d.properties.Previous_api) != ""
1426 if !(migratingNullability || validatingNullability) {
1427 ctx.PropertyErrorf("previous_api",
1428 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001429 }
Pete Gillina262c052018-09-14 14:25:48 +01001430 if migratingNullability {
1431 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1432 *implicits = append(*implicits, previousApi)
1433 flags += " --migrate-nullness " + previousApi.String()
1434 }
Pete Gillinc382a562018-11-14 18:45:46 +00001435 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1436 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1437 }
Pete Gillina262c052018-09-14 14:25:48 +01001438 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001439 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1440 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1441 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001442 }
Nan Zhanga40da042018-08-01 12:48:00 -07001443
1444 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1445 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1446
Nan Zhangf4936b02018-08-01 15:00:28 -07001447 flags += " --extract-annotations " + d.annotationsZip.String()
1448
Nan Zhang1598a9e2018-09-04 17:14:32 -07001449 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001450 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001451 "has to be non-empty if annotations was enabled!")
1452 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001453 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1454 if t, ok := m.(*ExportedDroiddocDir); ok {
1455 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001456 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001457 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001458 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001459 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1460 }
1461 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001462 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001463 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001464 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001465 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001466
Nan Zhangdee152b2018-12-26 16:06:37 -08001467 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001468}
1469
1470func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1471 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1472 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001473 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1474 if t, ok := m.(*ExportedDroiddocDir); ok {
1475 *implicits = append(*implicits, t.deps...)
1476 flags += " --merge-inclusion-annotations " + t.dir.String()
1477 } else {
1478 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1479 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1480 }
1481 })
Nan Zhanga40da042018-08-01 12:48:00 -07001482
1483 return flags
1484}
1485
Nan Zhang9c69a122018-08-22 10:22:08 -07001486func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1487 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1488 var flags string
1489 if Bool(d.properties.Api_levels_annotations_enabled) {
1490 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1491 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1492
1493 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1494 ctx.PropertyErrorf("api_levels_annotations_dirs",
1495 "has to be non-empty if api levels annotations was enabled!")
1496 }
1497
1498 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1499 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1500 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1501
1502 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1503 if t, ok := m.(*ExportedDroiddocDir); ok {
1504 var androidJars android.Paths
1505 for _, dep := range t.deps {
1506 if strings.HasSuffix(dep.String(), "android.jar") {
1507 androidJars = append(androidJars, dep)
1508 }
1509 }
1510 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001511 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001512 } else {
1513 ctx.PropertyErrorf("api_levels_annotations_dirs",
1514 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1515 }
1516 })
1517
1518 }
1519
1520 return flags
1521}
1522
Nan Zhang71bbe632018-09-17 14:32:21 -07001523func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1524 implicitOutputs *android.WritablePaths) string {
1525 var flags string
1526 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1527 if d.apiFile.String() == "" {
1528 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1529 }
1530
1531 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1532 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1533
1534 flags = " --api-xml " + d.apiXmlFile.String()
1535
1536 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1537 ctx.PropertyErrorf("check_api.last_released.api_file",
1538 "has to be non-empty if jdiff was enabled!")
1539 }
1540 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1541 "check_api.last_released.api_file")
1542 *implicits = append(*implicits, lastReleasedApi)
1543
1544 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1545 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1546
1547 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1548 d.lastReleasedApiXmlFile.String()
1549 }
1550
1551 return flags
1552}
1553
Nan Zhang1598a9e2018-09-04 17:14:32 -07001554func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1555 implicitOutputs android.WritablePaths, javaVersion,
1556 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001557
Nan Zhang86d2d552018-08-09 15:33:27 -07001558 ctx.Build(pctx, android.BuildParams{
1559 Rule: metalava,
1560 Description: "Metalava",
1561 Output: d.Javadoc.stubsSrcJar,
1562 Inputs: d.Javadoc.srcFiles,
1563 Implicits: implicits,
1564 ImplicitOutputs: implicitOutputs,
1565 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001566 "outDir": android.PathForModuleOut(ctx, "out").String(),
1567 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1568 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1569 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001570 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001571 "bootclasspathArgs": bootclasspathArgs,
1572 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001573 "sourcepathArgs": sourcepathArgs,
1574 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001575 },
1576 })
1577}
1578
Nan Zhang1598a9e2018-09-04 17:14:32 -07001579func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1580 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001581 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001582 output android.WritablePath) {
1583 ctx.Build(pctx, android.BuildParams{
1584 Rule: metalavaApiCheck,
1585 Description: "Metalava Check API",
1586 Output: output,
1587 Inputs: d.Javadoc.srcFiles,
1588 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1589 implicits...),
1590 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001591 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001592 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1593 "javaVersion": javaVersion,
1594 "bootclasspathArgs": bootclasspathArgs,
1595 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001596 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001597 "opts": opts,
1598 "msg": msg,
1599 },
1600 })
1601}
1602
Nan Zhang71bbe632018-09-17 14:32:21 -07001603func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1604 implicitOutputs android.WritablePaths,
1605 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1606 ctx.Build(pctx, android.BuildParams{
1607 Rule: javadoc,
1608 Description: "Jdiff",
1609 Output: d.jdiffStubsSrcJar,
1610 Inputs: d.Javadoc.srcFiles,
1611 Implicits: implicits,
1612 ImplicitOutputs: implicitOutputs,
1613 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001614 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1615 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1616 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001617 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1618 "opts": opts,
1619 "bootclasspathArgs": bootclasspathArgs,
1620 "classpathArgs": classpathArgs,
1621 "sourcepathArgs": sourcepathArgs,
1622 "docZip": d.jdiffDocZip.String(),
1623 },
1624 })
1625}
1626
Nan Zhang1598a9e2018-09-04 17:14:32 -07001627func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001628 deps := d.Javadoc.collectDeps(ctx)
1629
1630 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001631
Nan Zhanga40da042018-08-01 12:48:00 -07001632 var implicits android.Paths
1633 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001634 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001635
1636 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001637 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001638 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1639 }
1640
1641 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001642 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001643 jdiffImplicits := implicits
1644
Nan Zhanga40da042018-08-01 12:48:00 -07001645 if err != nil {
1646 return
1647 }
1648
Nan Zhang1598a9e2018-09-04 17:14:32 -07001649 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001650 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1651 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001652 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001653 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001654 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1655
Nan Zhang1598a9e2018-09-04 17:14:32 -07001656 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1657 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1658 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1659 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1660 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001661 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001662 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1663 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001664 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001665 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001666
Nan Zhang1598a9e2018-09-04 17:14:32 -07001667 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1668 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001669 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1670 "check_api.current.api_file")
1671 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1672 "check_api.current_removed_api_file")
1673
Nan Zhang2760dfc2018-08-24 17:32:54 +00001674 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001675 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1676 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001677 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001678
Nan Zhang1598a9e2018-09-04 17:14:32 -07001679 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001680 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001681 fmt.Sprintf(`\n******************************\n`+
1682 `You have tried to change the API from what has been previously approved.\n\n`+
1683 `To make these errors go away, you have two choices:\n`+
1684 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1685 ` errors above.\n\n`+
1686 ` 2. You can update current.txt by executing the following command:\n`+
1687 ` make %s-update-current-api\n\n`+
1688 ` To submit the revised current.txt to the main Android repository,\n`+
1689 ` you will need approval.\n`+
1690 `******************************\n`, ctx.ModuleName()),
1691 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001692
1693 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001694 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1695 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001696 }
Nan Zhanga40da042018-08-01 12:48:00 -07001697
Nan Zhang1598a9e2018-09-04 17:14:32 -07001698 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1699 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001700 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1701 "check_api.last_released.api_file")
1702 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1703 "check_api.last_released.removed_api_file")
1704
Nan Zhang2760dfc2018-08-24 17:32:54 +00001705 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001706 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1707 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001708 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001709
Nan Zhang1598a9e2018-09-04 17:14:32 -07001710 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001711 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001712 `\n******************************\n`+
1713 `You have tried to change the API from what has been previously released in\n`+
1714 `an SDK. Please fix the errors listed above.\n`+
1715 `******************************\n`,
1716 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001717 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001718
Pete Gillin581d6082018-10-22 15:55:04 +01001719 if String(d.properties.Check_nullability_warnings) != "" {
1720 if d.nullabilityWarningsFile == nil {
1721 ctx.PropertyErrorf("check_nullability_warnings",
1722 "Cannot specify check_nullability_warnings unless validating nullability")
1723 }
1724 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1725 "check_nullability_warnings")
1726 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1727 msg := fmt.Sprintf(`\n******************************\n`+
1728 `The warnings encountered during nullability annotation validation did\n`+
1729 `not match the checked in file of expected warnings. The diffs are shown\n`+
1730 `above. You have two options:\n`+
1731 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1732 ` 2. Update the file of expected warnings by running:\n`+
1733 ` cp %s %s\n`+
1734 ` and submitting the updated file as part of your change.`,
1735 d.nullabilityWarningsFile, checkNullabilityWarnings)
1736 ctx.Build(pctx, android.BuildParams{
1737 Rule: nullabilityWarningsCheck,
1738 Description: "Nullability Warnings Check",
1739 Output: d.checkNullabilityWarningsTimestamp,
1740 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1741 Args: map[string]string{
1742 "expected": checkNullabilityWarnings.String(),
1743 "actual": d.nullabilityWarningsFile.String(),
1744 "msg": msg,
1745 },
1746 })
1747 }
1748
Nan Zhang71bbe632018-09-17 14:32:21 -07001749 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1750
Nan Zhang86b06202018-09-21 17:09:21 -07001751 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1752 // since there's cron job downstream that fetch this .zip file periodically.
1753 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001754 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1755 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1756
1757 var jdiffImplicitOutputs android.WritablePaths
1758 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1759
1760 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1761 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1762
1763 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1764 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1765 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1766 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1767 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1768 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1769
1770 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1771 flags.sourcepathArgs, opts)
1772 }
Nan Zhang581fd212018-01-10 16:06:12 -08001773}
Dan Willemsencc090972018-02-26 14:33:31 -08001774
Nan Zhanga40da042018-08-01 12:48:00 -07001775//
Nan Zhangf4936b02018-08-01 15:00:28 -07001776// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001777//
Dan Willemsencc090972018-02-26 14:33:31 -08001778var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001779var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001780var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001781var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001782
Nan Zhangf4936b02018-08-01 15:00:28 -07001783type ExportedDroiddocDirProperties struct {
1784 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001785 Path *string
1786}
1787
Nan Zhangf4936b02018-08-01 15:00:28 -07001788type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001789 android.ModuleBase
1790
Nan Zhangf4936b02018-08-01 15:00:28 -07001791 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001792
1793 deps android.Paths
1794 dir android.Path
1795}
1796
Nan Zhangf4936b02018-08-01 15:00:28 -07001797func ExportedDroiddocDirFactory() android.Module {
1798 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001799 module.AddProperties(&module.properties)
1800 android.InitAndroidModule(module)
1801 return module
1802}
1803
Nan Zhangf4936b02018-08-01 15:00:28 -07001804func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001805
Nan Zhangf4936b02018-08-01 15:00:28 -07001806func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001807 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1808 d.dir = path
1809 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1810}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001811
1812//
1813// Defaults
1814//
1815type DocDefaults struct {
1816 android.ModuleBase
1817 android.DefaultsModuleBase
1818}
1819
1820func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1821}
1822
Nan Zhangb2b33de2018-02-23 11:18:47 -08001823func DocDefaultsFactory() android.Module {
1824 module := &DocDefaults{}
1825
1826 module.AddProperties(
1827 &JavadocProperties{},
1828 &DroiddocProperties{},
1829 )
1830
1831 android.InitDefaultsModule(module)
1832
1833 return module
1834}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001835
1836func StubsDefaultsFactory() android.Module {
1837 module := &DocDefaults{}
1838
1839 module.AddProperties(
1840 &JavadocProperties{},
1841 &DroidstubsProperties{},
1842 )
1843
1844 android.InitDefaultsModule(module)
1845
1846 return module
1847}