blob: cbe6be6436149943a359c63a0b9faabb7bf94d41 [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)
698 argFilesMap := map[string]android.Path{}
699
700 for _, f := range j.argFiles {
701 if _, exists := argFilesMap[f.Rel()]; !exists {
702 argFilesMap[f.Rel()] = f
703 } else {
704 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
705 f, argFilesMap[f.Rel()], f.Rel())
706 }
707 }
708
709 var err error
710 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
711 if strings.HasPrefix(name, "location ") {
712 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
713 if f, ok := argFilesMap[label]; ok {
714 return f.String(), nil
715 } else {
716 return "", fmt.Errorf("unknown location label %q", label)
717 }
718 } else if name == "genDir" {
719 return android.PathForModuleGen(ctx).String(), nil
720 }
721 return "", fmt.Errorf("unknown variable '$(%s)'", name)
722 })
723
724 if err != nil {
725 ctx.PropertyErrorf("args", "%s", err.Error())
726 }
727
Nan Zhang581fd212018-01-10 16:06:12 -0800728 return deps
729}
730
731func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
732 j.addDeps(ctx)
733}
734
735func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
736 deps := j.collectDeps(ctx)
737
738 var implicits android.Paths
739 implicits = append(implicits, deps.bootClasspath...)
740 implicits = append(implicits, deps.classpath...)
741
Nan Zhang1598a9e2018-09-04 17:14:32 -0700742 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700743
Colin Cross83bb3162018-06-25 15:48:06 -0700744 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700745 if len(deps.bootClasspath) > 0 {
746 var systemModules classpath
747 if deps.systemModules != nil {
748 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800749 }
Colin Cross997262f2018-06-19 22:49:39 -0700750 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
751 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800752 }
753 if len(deps.classpath.Strings()) > 0 {
754 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
755 }
756
757 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700758 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800759
Nan Zhangaf322cc2018-06-19 15:15:38 -0700760 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800761
Nan Zhang1598a9e2018-09-04 17:14:32 -0700762 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
763
Nan Zhang581fd212018-01-10 16:06:12 -0800764 ctx.Build(pctx, android.BuildParams{
765 Rule: javadoc,
766 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800767 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800768 ImplicitOutput: j.docZip,
769 Inputs: j.srcFiles,
770 Implicits: implicits,
771 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700772 "outDir": android.PathForModuleOut(ctx, "out").String(),
773 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
774 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800775 "srcJars": strings.Join(j.srcJars.Strings(), " "),
776 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700777 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800778 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700779 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800780 "docZip": j.docZip.String(),
781 },
782 })
783}
784
Nan Zhanga40da042018-08-01 12:48:00 -0700785//
786// Droiddoc
787//
788type Droiddoc struct {
789 Javadoc
790
791 properties DroiddocProperties
792 apiFile android.WritablePath
793 dexApiFile android.WritablePath
794 privateApiFile android.WritablePath
795 privateDexApiFile android.WritablePath
796 removedApiFile android.WritablePath
797 removedDexApiFile android.WritablePath
798 exactApiFile android.WritablePath
799 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700800 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700801
802 checkCurrentApiTimestamp android.WritablePath
803 updateCurrentApiTimestamp android.WritablePath
804 checkLastReleasedApiTimestamp android.WritablePath
805
Nan Zhanga40da042018-08-01 12:48:00 -0700806 apiFilePath android.Path
807}
808
Nan Zhanga40da042018-08-01 12:48:00 -0700809func DroiddocFactory() android.Module {
810 module := &Droiddoc{}
811
812 module.AddProperties(&module.properties,
813 &module.Javadoc.properties)
814
815 InitDroiddocModule(module, android.HostAndDeviceSupported)
816 return module
817}
818
819func DroiddocHostFactory() android.Module {
820 module := &Droiddoc{}
821
822 module.AddProperties(&module.properties,
823 &module.Javadoc.properties)
824
825 InitDroiddocModule(module, android.HostSupported)
826 return module
827}
828
829func (d *Droiddoc) ApiFilePath() android.Path {
830 return d.apiFilePath
831}
832
Nan Zhang581fd212018-01-10 16:06:12 -0800833func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
834 d.Javadoc.addDeps(ctx)
835
Nan Zhang79614d12018-04-19 18:03:39 -0700836 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800837 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
838 }
839
Nan Zhang581fd212018-01-10 16:06:12 -0800840 // knowntags may contain filegroup or genrule.
841 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700842
Nan Zhange2ba5d42018-07-11 15:16:55 -0700843 if String(d.properties.Static_doc_index_redirect) != "" {
844 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
845 }
846
847 if String(d.properties.Static_doc_properties) != "" {
848 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
849 }
850
Nan Zhang1598a9e2018-09-04 17:14:32 -0700851 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700852 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
853 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
854 }
855
Nan Zhang1598a9e2018-09-04 17:14:32 -0700856 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700857 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
858 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
859 }
Nan Zhang581fd212018-01-10 16:06:12 -0800860}
861
Nan Zhang66dc2362018-08-14 20:41:04 -0700862func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
863 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700864 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800865
Nan Zhanga40da042018-08-01 12:48:00 -0700866 *implicits = append(*implicits, deps.bootClasspath...)
867 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800868
Nan Zhangc94f9d82018-06-26 10:02:26 -0700869 if len(deps.bootClasspath.Strings()) > 0 {
870 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700871 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700872 }
Nan Zhanga40da042018-08-01 12:48:00 -0700873 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700874 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700875 dokkaClasspath := classpath{}
876 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
877 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
878 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700879
Nan Zhang9c69a122018-08-22 10:22:08 -0700880 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
881 // based stubs generation.
882 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
883 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
884 // the correct package name base path.
885 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
886 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
887 } else {
888 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
889 }
Nan Zhang581fd212018-01-10 16:06:12 -0800890
Nan Zhanga40da042018-08-01 12:48:00 -0700891 return flags, nil
892}
Nan Zhang581fd212018-01-10 16:06:12 -0800893
Nan Zhanga40da042018-08-01 12:48:00 -0700894func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700895 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800896
Nan Zhanga40da042018-08-01 12:48:00 -0700897 *implicits = append(*implicits, jsilver)
898 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700899
Nan Zhang46130972018-06-04 11:28:01 -0700900 var date string
901 if runtime.GOOS == "darwin" {
902 date = `date -r`
903 } else {
904 date = `date -d`
905 }
906
Nan Zhang443fa522018-08-20 20:58:28 -0700907 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
908 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
909 // 1.9 language features.
910 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700911 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800912 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700913 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700914
Nan Zhanga40da042018-08-01 12:48:00 -0700915 if String(d.properties.Custom_template) == "" {
916 // TODO: This is almost always droiddoc-templates-sdk
917 ctx.PropertyErrorf("custom_template", "must specify a template")
918 }
919
920 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700921 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700922 *implicits = append(*implicits, t.deps...)
923 args = args + " -templatedir " + t.dir.String()
924 } else {
925 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
926 }
927 })
928
929 if len(d.properties.Html_dirs) > 0 {
930 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
931 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
932 args = args + " -htmldir " + htmlDir.String()
933 }
934
935 if len(d.properties.Html_dirs) > 1 {
936 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
937 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
938 args = args + " -htmldir2 " + htmlDir2.String()
939 }
940
941 if len(d.properties.Html_dirs) > 2 {
942 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
943 }
944
945 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
946 *implicits = append(*implicits, knownTags...)
947
948 for _, kt := range knownTags {
949 args = args + " -knowntags " + kt.String()
950 }
951
952 for _, hdf := range d.properties.Hdf {
953 args = args + " -hdf " + hdf
954 }
955
956 if String(d.properties.Proofread_file) != "" {
957 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
958 args = args + " -proofread " + proofreadFile.String()
959 }
960
961 if String(d.properties.Todo_file) != "" {
962 // tricky part:
963 // we should not compute full path for todo_file through PathForModuleOut().
964 // the non-standard doclet will get the full path relative to "-o".
965 args = args + " -todo " + String(d.properties.Todo_file)
966 }
967
968 if String(d.properties.Resourcesdir) != "" {
969 // TODO: should we add files under resourcesDir to the implicits? It seems that
970 // resourcesDir is one sub dir of htmlDir
971 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
972 args = args + " -resourcesdir " + resourcesDir.String()
973 }
974
975 if String(d.properties.Resourcesoutdir) != "" {
976 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
977 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
978 }
979 return args
980}
981
Nan Zhang1598a9e2018-09-04 17:14:32 -0700982func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
983 implicitOutputs *android.WritablePaths) string {
984 var doclavaFlags string
985 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
986 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
987 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700988 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
989 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700990 *implicitOutputs = append(*implicitOutputs, d.apiFile)
991 d.apiFilePath = d.apiFile
992 }
993
Nan Zhang1598a9e2018-09-04 17:14:32 -0700994 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
995 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
996 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700997 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
998 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700999 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1000 }
1001
1002 if String(d.properties.Private_api_filename) != "" {
1003 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1004 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001005 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1006 }
1007
1008 if String(d.properties.Dex_api_filename) != "" {
1009 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1010 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1011 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1012 }
1013
1014 if String(d.properties.Private_dex_api_filename) != "" {
1015 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1016 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001017 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1018 }
1019
1020 if String(d.properties.Removed_dex_api_filename) != "" {
1021 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1022 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001023 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1024 }
1025
1026 if String(d.properties.Exact_api_filename) != "" {
1027 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1028 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001029 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1030 }
1031
1032 if String(d.properties.Dex_mapping_filename) != "" {
1033 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1034 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001035 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1036 }
1037
Nan Zhang66dc2362018-08-14 20:41:04 -07001038 if String(d.properties.Proguard_filename) != "" {
1039 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1040 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001041 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1042 }
1043
Nan Zhanga40da042018-08-01 12:48:00 -07001044 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001045 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001046 }
1047
1048 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001049 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001050 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001051
1052 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001053}
1054
1055func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1056 var cmds string
1057 if String(d.properties.Static_doc_index_redirect) != "" {
1058 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1059 "static_doc_index_redirect")
1060 *implicits = append(*implicits, static_doc_index_redirect)
1061 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001062 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001063 }
1064
1065 if String(d.properties.Static_doc_properties) != "" {
1066 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1067 "static_doc_properties")
1068 *implicits = append(*implicits, static_doc_properties)
1069 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001070 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001071 }
1072 return cmds
1073}
1074
Nan Zhang1598a9e2018-09-04 17:14:32 -07001075func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1076 implicitOutputs android.WritablePaths,
1077 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1078 ctx.Build(pctx, android.BuildParams{
1079 Rule: javadoc,
1080 Description: "Doclava",
1081 Output: d.Javadoc.stubsSrcJar,
1082 Inputs: d.Javadoc.srcFiles,
1083 Implicits: implicits,
1084 ImplicitOutputs: implicitOutputs,
1085 Args: map[string]string{
1086 "outDir": android.PathForModuleOut(ctx, "out").String(),
1087 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1088 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1089 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1090 "opts": opts,
1091 "bootclasspathArgs": bootclasspathArgs,
1092 "classpathArgs": classpathArgs,
1093 "sourcepathArgs": sourcepathArgs,
1094 "docZip": d.Javadoc.docZip.String(),
1095 "postDoclavaCmds": postDoclavaCmds,
1096 },
1097 })
1098}
1099
1100func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1101 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1102 ctx.Build(pctx, android.BuildParams{
1103 Rule: apiCheck,
1104 Description: "Doclava Check API",
1105 Output: output,
1106 Inputs: nil,
1107 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1108 checkApiClasspath...),
1109 Args: map[string]string{
1110 "msg": msg,
1111 "classpath": checkApiClasspath.FormJavaClassPath(""),
1112 "opts": opts,
1113 "apiFile": apiFile.String(),
1114 "apiFileToCheck": d.apiFile.String(),
1115 "removedApiFile": removedApiFile.String(),
1116 "removedApiFileToCheck": d.removedApiFile.String(),
1117 },
1118 })
1119}
1120
1121func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1122 classpathArgs, opts string) {
1123 ctx.Build(pctx, android.BuildParams{
1124 Rule: dokka,
1125 Description: "Dokka",
1126 Output: d.Javadoc.stubsSrcJar,
1127 Inputs: d.Javadoc.srcFiles,
1128 Implicits: implicits,
1129 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001130 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1131 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1132 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001133 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1134 "classpathArgs": classpathArgs,
1135 "opts": opts,
1136 "docZip": d.Javadoc.docZip.String(),
1137 },
1138 })
1139}
1140
1141func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1142 deps := d.Javadoc.collectDeps(ctx)
1143
1144 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1145 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1146 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1147 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1148
1149 var implicits android.Paths
1150 implicits = append(implicits, d.Javadoc.srcJars...)
1151 implicits = append(implicits, d.Javadoc.argFiles...)
1152
1153 var implicitOutputs android.WritablePaths
1154 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1155 for _, o := range d.Javadoc.properties.Out {
1156 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1157 }
1158
1159 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1160 if err != nil {
1161 return
1162 }
1163
1164 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1165 if Bool(d.properties.Dokka_enabled) {
1166 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1167 } else {
1168 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1169 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1170 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1171 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1172 flags.postDoclavaCmds)
1173 }
1174
1175 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1176 !ctx.Config().IsPdkBuild() {
1177 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1178 "check_api.current.api_file")
1179 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1180 "check_api.current_removed_api_file")
1181
1182 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1183 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1184 fmt.Sprintf(`\n******************************\n`+
1185 `You have tried to change the API from what has been previously approved.\n\n`+
1186 `To make these errors go away, you have two choices:\n`+
1187 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1188 ` errors above.\n\n`+
1189 ` 2. You can update current.txt by executing the following command:\n`+
1190 ` make %s-update-current-api\n\n`+
1191 ` To submit the revised current.txt to the main Android repository,\n`+
1192 ` you will need approval.\n`+
1193 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1194 d.checkCurrentApiTimestamp)
1195
1196 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1197 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1198 d.updateCurrentApiTimestamp)
1199 }
1200
1201 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1202 !ctx.Config().IsPdkBuild() {
1203 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1204 "check_api.last_released.api_file")
1205 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1206 "check_api.last_released.removed_api_file")
1207
1208 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1209 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1210 `\n******************************\n`+
1211 `You have tried to change the API from what has been previously released in\n`+
1212 `an SDK. Please fix the errors listed above.\n`+
1213 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1214 d.checkLastReleasedApiTimestamp)
1215 }
1216}
1217
1218//
1219// Droidstubs
1220//
1221type Droidstubs struct {
1222 Javadoc
1223
Pete Gillin581d6082018-10-22 15:55:04 +01001224 properties DroidstubsProperties
1225 apiFile android.WritablePath
1226 apiXmlFile android.WritablePath
1227 lastReleasedApiXmlFile android.WritablePath
1228 dexApiFile android.WritablePath
1229 privateApiFile android.WritablePath
1230 privateDexApiFile android.WritablePath
1231 removedApiFile android.WritablePath
1232 removedDexApiFile android.WritablePath
1233 apiMappingFile android.WritablePath
1234 exactApiFile android.WritablePath
1235 proguardFile android.WritablePath
1236 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001237
1238 checkCurrentApiTimestamp android.WritablePath
1239 updateCurrentApiTimestamp android.WritablePath
1240 checkLastReleasedApiTimestamp android.WritablePath
1241
Pete Gillin581d6082018-10-22 15:55:04 +01001242 checkNullabilityWarningsTimestamp android.WritablePath
1243
Nan Zhang1598a9e2018-09-04 17:14:32 -07001244 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001245 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001246
1247 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001248
1249 jdiffDocZip android.WritablePath
1250 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251}
1252
1253func DroidstubsFactory() android.Module {
1254 module := &Droidstubs{}
1255
1256 module.AddProperties(&module.properties,
1257 &module.Javadoc.properties)
1258
1259 InitDroiddocModule(module, android.HostAndDeviceSupported)
1260 return module
1261}
1262
1263func DroidstubsHostFactory() android.Module {
1264 module := &Droidstubs{}
1265
1266 module.AddProperties(&module.properties,
1267 &module.Javadoc.properties)
1268
1269 InitDroiddocModule(module, android.HostSupported)
1270 return module
1271}
1272
1273func (d *Droidstubs) ApiFilePath() android.Path {
1274 return d.apiFilePath
1275}
1276
1277func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1278 d.Javadoc.addDeps(ctx)
1279
1280 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1281 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1282 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1283 }
1284
1285 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1286 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1287 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1288 }
1289
1290 if String(d.properties.Previous_api) != "" {
1291 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1292 }
1293
1294 if len(d.properties.Merge_annotations_dirs) != 0 {
1295 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1296 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1297 }
1298 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001299
Pete Gillin77167902018-09-19 18:16:26 +01001300 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1301 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1302 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1303 }
1304 }
1305
Pete Gillinc382a562018-11-14 18:45:46 +00001306 if String(d.properties.Validate_nullability_from_list) != "" {
1307 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1308 }
Pete Gillin581d6082018-10-22 15:55:04 +01001309 if String(d.properties.Check_nullability_warnings) != "" {
1310 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1311 }
1312
Nan Zhang9c69a122018-08-22 10:22:08 -07001313 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1314 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1315 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1316 }
1317 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001318}
1319
1320func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1321 deps deps) (droiddocBuilderFlags, error) {
1322 var flags droiddocBuilderFlags
1323
1324 *implicits = append(*implicits, deps.bootClasspath...)
1325 *implicits = append(*implicits, deps.classpath...)
1326
1327 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1328 // since it doesn't support system modules yet.
1329 if len(deps.bootClasspath.Strings()) > 0 {
1330 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1331 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1332 }
1333 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1334
Sundong Ahn56dce442018-10-05 18:41:09 +09001335 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001336 return flags, nil
1337}
1338
1339func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1340 implicitOutputs *android.WritablePaths) string {
1341 var metalavaFlags string
1342 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1343 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1344 String(d.properties.Api_filename) != "" {
1345 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1346 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1347 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1348 d.apiFilePath = d.apiFile
1349 }
1350
1351 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1352 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1353 String(d.properties.Removed_api_filename) != "" {
1354 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1355 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1356 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1357 }
1358
1359 if String(d.properties.Private_api_filename) != "" {
1360 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1361 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1362 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1363 }
1364
1365 if String(d.properties.Dex_api_filename) != "" {
1366 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1367 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1368 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1369 }
1370
1371 if String(d.properties.Private_dex_api_filename) != "" {
1372 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1373 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1374 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1375 }
1376
1377 if String(d.properties.Removed_dex_api_filename) != "" {
1378 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1379 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1380 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1381 }
1382
1383 if String(d.properties.Exact_api_filename) != "" {
1384 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1385 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1386 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1387 }
1388
Nan Zhang9c69a122018-08-22 10:22:08 -07001389 if String(d.properties.Dex_mapping_filename) != "" {
1390 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1391 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1392 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1393 }
1394
Nan Zhang199645c2018-09-19 12:40:06 -07001395 if String(d.properties.Proguard_filename) != "" {
1396 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1397 metalavaFlags += " --proguard " + d.proguardFile.String()
1398 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1399 }
1400
Nan Zhang9c69a122018-08-22 10:22:08 -07001401 if Bool(d.properties.Write_sdk_values) {
1402 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1403 }
1404
Nan Zhang1598a9e2018-09-04 17:14:32 -07001405 if Bool(d.properties.Create_doc_stubs) {
1406 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1407 } else {
1408 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1409 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001410 return metalavaFlags
1411}
1412
1413func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001414 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1415 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001416 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001417 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001418 validatingNullability :=
1419 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1420 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001421 migratingNullability := String(d.properties.Previous_api) != ""
1422 if !(migratingNullability || validatingNullability) {
1423 ctx.PropertyErrorf("previous_api",
1424 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001425 }
Pete Gillina262c052018-09-14 14:25:48 +01001426 if migratingNullability {
1427 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1428 *implicits = append(*implicits, previousApi)
1429 flags += " --migrate-nullness " + previousApi.String()
1430 }
Pete Gillinc382a562018-11-14 18:45:46 +00001431 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1432 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1433 }
Pete Gillina262c052018-09-14 14:25:48 +01001434 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001435 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1436 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1437 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001438 }
Nan Zhanga40da042018-08-01 12:48:00 -07001439
1440 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1441 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1442
Nan Zhangf4936b02018-08-01 15:00:28 -07001443 flags += " --extract-annotations " + d.annotationsZip.String()
1444
Nan Zhang1598a9e2018-09-04 17:14:32 -07001445 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001446 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001447 "has to be non-empty if annotations was enabled!")
1448 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001449 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1450 if t, ok := m.(*ExportedDroiddocDir); ok {
1451 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001452 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001453 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001454 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001455 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1456 }
1457 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001458 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001459 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001460 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001461 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001462
Nan Zhangdee152b2018-12-26 16:06:37 -08001463 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001464}
1465
1466func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1467 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1468 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001469 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1470 if t, ok := m.(*ExportedDroiddocDir); ok {
1471 *implicits = append(*implicits, t.deps...)
1472 flags += " --merge-inclusion-annotations " + t.dir.String()
1473 } else {
1474 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1475 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1476 }
1477 })
Nan Zhanga40da042018-08-01 12:48:00 -07001478
1479 return flags
1480}
1481
Nan Zhang9c69a122018-08-22 10:22:08 -07001482func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1483 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1484 var flags string
1485 if Bool(d.properties.Api_levels_annotations_enabled) {
1486 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1487 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1488
1489 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1490 ctx.PropertyErrorf("api_levels_annotations_dirs",
1491 "has to be non-empty if api levels annotations was enabled!")
1492 }
1493
1494 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1495 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1496 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1497
1498 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1499 if t, ok := m.(*ExportedDroiddocDir); ok {
1500 var androidJars android.Paths
1501 for _, dep := range t.deps {
1502 if strings.HasSuffix(dep.String(), "android.jar") {
1503 androidJars = append(androidJars, dep)
1504 }
1505 }
1506 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001507 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001508 } else {
1509 ctx.PropertyErrorf("api_levels_annotations_dirs",
1510 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1511 }
1512 })
1513
1514 }
1515
1516 return flags
1517}
1518
Nan Zhang71bbe632018-09-17 14:32:21 -07001519func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1520 implicitOutputs *android.WritablePaths) string {
1521 var flags string
1522 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1523 if d.apiFile.String() == "" {
1524 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1525 }
1526
1527 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1528 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1529
1530 flags = " --api-xml " + d.apiXmlFile.String()
1531
1532 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1533 ctx.PropertyErrorf("check_api.last_released.api_file",
1534 "has to be non-empty if jdiff was enabled!")
1535 }
1536 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1537 "check_api.last_released.api_file")
1538 *implicits = append(*implicits, lastReleasedApi)
1539
1540 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1541 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1542
1543 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1544 d.lastReleasedApiXmlFile.String()
1545 }
1546
1547 return flags
1548}
1549
Nan Zhang1598a9e2018-09-04 17:14:32 -07001550func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1551 implicitOutputs android.WritablePaths, javaVersion,
1552 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001553
Nan Zhang86d2d552018-08-09 15:33:27 -07001554 ctx.Build(pctx, android.BuildParams{
1555 Rule: metalava,
1556 Description: "Metalava",
1557 Output: d.Javadoc.stubsSrcJar,
1558 Inputs: d.Javadoc.srcFiles,
1559 Implicits: implicits,
1560 ImplicitOutputs: implicitOutputs,
1561 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001562 "outDir": android.PathForModuleOut(ctx, "out").String(),
1563 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1564 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1565 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001566 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001567 "bootclasspathArgs": bootclasspathArgs,
1568 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001569 "sourcepathArgs": sourcepathArgs,
1570 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001571 },
1572 })
1573}
1574
Nan Zhang1598a9e2018-09-04 17:14:32 -07001575func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1576 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001577 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001578 output android.WritablePath) {
1579 ctx.Build(pctx, android.BuildParams{
1580 Rule: metalavaApiCheck,
1581 Description: "Metalava Check API",
1582 Output: output,
1583 Inputs: d.Javadoc.srcFiles,
1584 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1585 implicits...),
1586 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001587 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001588 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1589 "javaVersion": javaVersion,
1590 "bootclasspathArgs": bootclasspathArgs,
1591 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001592 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001593 "opts": opts,
1594 "msg": msg,
1595 },
1596 })
1597}
1598
Nan Zhang71bbe632018-09-17 14:32:21 -07001599func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1600 implicitOutputs android.WritablePaths,
1601 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1602 ctx.Build(pctx, android.BuildParams{
1603 Rule: javadoc,
1604 Description: "Jdiff",
1605 Output: d.jdiffStubsSrcJar,
1606 Inputs: d.Javadoc.srcFiles,
1607 Implicits: implicits,
1608 ImplicitOutputs: implicitOutputs,
1609 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001610 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1611 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1612 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001613 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1614 "opts": opts,
1615 "bootclasspathArgs": bootclasspathArgs,
1616 "classpathArgs": classpathArgs,
1617 "sourcepathArgs": sourcepathArgs,
1618 "docZip": d.jdiffDocZip.String(),
1619 },
1620 })
1621}
1622
Nan Zhang1598a9e2018-09-04 17:14:32 -07001623func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001624 deps := d.Javadoc.collectDeps(ctx)
1625
1626 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001627
Nan Zhanga40da042018-08-01 12:48:00 -07001628 var implicits android.Paths
1629 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001630 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001631
1632 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001633 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001634 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1635 }
1636
1637 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001638 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001639 jdiffImplicits := implicits
1640
Nan Zhanga40da042018-08-01 12:48:00 -07001641 if err != nil {
1642 return
1643 }
1644
Nan Zhang1598a9e2018-09-04 17:14:32 -07001645 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001646 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1647 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001648 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001649 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001650 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1651
Nan Zhang1598a9e2018-09-04 17:14:32 -07001652 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1653 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1654 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1655 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1656 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001657 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001658 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1659 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001660 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001661 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001662
Nan Zhang1598a9e2018-09-04 17:14:32 -07001663 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1664 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001665 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1666 "check_api.current.api_file")
1667 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1668 "check_api.current_removed_api_file")
1669
Nan Zhang2760dfc2018-08-24 17:32:54 +00001670 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001671 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1672 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001673 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001674
Nan Zhang1598a9e2018-09-04 17:14:32 -07001675 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001676 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001677 fmt.Sprintf(`\n******************************\n`+
1678 `You have tried to change the API from what has been previously approved.\n\n`+
1679 `To make these errors go away, you have two choices:\n`+
1680 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1681 ` errors above.\n\n`+
1682 ` 2. You can update current.txt by executing the following command:\n`+
1683 ` make %s-update-current-api\n\n`+
1684 ` To submit the revised current.txt to the main Android repository,\n`+
1685 ` you will need approval.\n`+
1686 `******************************\n`, ctx.ModuleName()),
1687 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001688
1689 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001690 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1691 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001692 }
Nan Zhanga40da042018-08-01 12:48:00 -07001693
Nan Zhang1598a9e2018-09-04 17:14:32 -07001694 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1695 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001696 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1697 "check_api.last_released.api_file")
1698 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1699 "check_api.last_released.removed_api_file")
1700
Nan Zhang2760dfc2018-08-24 17:32:54 +00001701 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001702 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1703 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001704 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001705
Nan Zhang1598a9e2018-09-04 17:14:32 -07001706 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001707 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001708 `\n******************************\n`+
1709 `You have tried to change the API from what has been previously released in\n`+
1710 `an SDK. Please fix the errors listed above.\n`+
1711 `******************************\n`,
1712 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001713 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001714
Pete Gillin581d6082018-10-22 15:55:04 +01001715 if String(d.properties.Check_nullability_warnings) != "" {
1716 if d.nullabilityWarningsFile == nil {
1717 ctx.PropertyErrorf("check_nullability_warnings",
1718 "Cannot specify check_nullability_warnings unless validating nullability")
1719 }
1720 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1721 "check_nullability_warnings")
1722 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1723 msg := fmt.Sprintf(`\n******************************\n`+
1724 `The warnings encountered during nullability annotation validation did\n`+
1725 `not match the checked in file of expected warnings. The diffs are shown\n`+
1726 `above. You have two options:\n`+
1727 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1728 ` 2. Update the file of expected warnings by running:\n`+
1729 ` cp %s %s\n`+
1730 ` and submitting the updated file as part of your change.`,
1731 d.nullabilityWarningsFile, checkNullabilityWarnings)
1732 ctx.Build(pctx, android.BuildParams{
1733 Rule: nullabilityWarningsCheck,
1734 Description: "Nullability Warnings Check",
1735 Output: d.checkNullabilityWarningsTimestamp,
1736 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1737 Args: map[string]string{
1738 "expected": checkNullabilityWarnings.String(),
1739 "actual": d.nullabilityWarningsFile.String(),
1740 "msg": msg,
1741 },
1742 })
1743 }
1744
Nan Zhang71bbe632018-09-17 14:32:21 -07001745 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1746
Nan Zhang86b06202018-09-21 17:09:21 -07001747 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1748 // since there's cron job downstream that fetch this .zip file periodically.
1749 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001750 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1751 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1752
1753 var jdiffImplicitOutputs android.WritablePaths
1754 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1755
1756 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1757 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1758
1759 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1760 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1761 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1762 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1763 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1764 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1765
1766 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1767 flags.sourcepathArgs, opts)
1768 }
Nan Zhang581fd212018-01-10 16:06:12 -08001769}
Dan Willemsencc090972018-02-26 14:33:31 -08001770
Nan Zhanga40da042018-08-01 12:48:00 -07001771//
Nan Zhangf4936b02018-08-01 15:00:28 -07001772// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001773//
Dan Willemsencc090972018-02-26 14:33:31 -08001774var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001775var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001776var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001777var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001778
Nan Zhangf4936b02018-08-01 15:00:28 -07001779type ExportedDroiddocDirProperties struct {
1780 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001781 Path *string
1782}
1783
Nan Zhangf4936b02018-08-01 15:00:28 -07001784type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001785 android.ModuleBase
1786
Nan Zhangf4936b02018-08-01 15:00:28 -07001787 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001788
1789 deps android.Paths
1790 dir android.Path
1791}
1792
Nan Zhangf4936b02018-08-01 15:00:28 -07001793func ExportedDroiddocDirFactory() android.Module {
1794 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001795 module.AddProperties(&module.properties)
1796 android.InitAndroidModule(module)
1797 return module
1798}
1799
Nan Zhangf4936b02018-08-01 15:00:28 -07001800func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001801
Nan Zhangf4936b02018-08-01 15:00:28 -07001802func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001803 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1804 d.dir = path
1805 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1806}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001807
1808//
1809// Defaults
1810//
1811type DocDefaults struct {
1812 android.ModuleBase
1813 android.DefaultsModuleBase
1814}
1815
1816func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1817}
1818
Nan Zhangb2b33de2018-02-23 11:18:47 -08001819func DocDefaultsFactory() android.Module {
1820 module := &DocDefaults{}
1821
1822 module.AddProperties(
1823 &JavadocProperties{},
1824 &DroiddocProperties{},
1825 )
1826
1827 android.InitDefaultsModule(module)
1828
1829 return module
1830}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001831
1832func StubsDefaultsFactory() android.Module {
1833 module := &DocDefaults{}
1834
1835 module.AddProperties(
1836 &JavadocProperties{},
1837 &DroidstubsProperties{},
1838 )
1839
1840 android.InitDefaultsModule(module)
1841
1842 return module
1843}