blob: 1a70d492825c567b72fd1085ea164aced22e3b6e [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)
Inseob Kimc0907f12019-02-08 21:00:45 +0900602 case ".sysprop":
603 javaFile := genSysprop(ctx, srcFile)
604 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900605 default:
606 outSrcFiles = append(outSrcFiles, srcFile)
607 }
608 }
609
610 return outSrcFiles
611}
612
Nan Zhang581fd212018-01-10 16:06:12 -0800613func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
614 var deps deps
615
Colin Cross83bb3162018-06-25 15:48:06 -0700616 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800617 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700618 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800619 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700620 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800621 }
622
623 ctx.VisitDirectDeps(func(module android.Module) {
624 otherName := ctx.OtherModuleName(module)
625 tag := ctx.OtherModuleDependencyTag(module)
626
Colin Cross2d24c1b2018-05-23 10:59:18 -0700627 switch tag {
628 case bootClasspathTag:
629 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800630 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700631 } else {
632 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
633 }
634 case libTag:
635 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800636 case SdkLibraryDependency:
637 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700638 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900639 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700640 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800641 checkProducesJars(ctx, dep)
642 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800643 default:
644 ctx.ModuleErrorf("depends on non-java module %q", otherName)
645 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700646 case srcsLibTag:
647 switch dep := module.(type) {
648 case Dependency:
649 srcs := dep.(SrcDependency).CompiledSrcs()
650 whitelistPathPrefixes := make(map[string]bool)
651 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
652 for _, src := range srcs {
653 if _, ok := src.(android.WritablePath); ok { // generated sources
654 deps.srcs = append(deps.srcs, src)
655 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700656 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700657 if strings.HasPrefix(src.Rel(), k) {
658 deps.srcs = append(deps.srcs, src)
659 break
660 }
661 }
662 }
663 }
664 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
665 default:
666 ctx.ModuleErrorf("depends on non-java module %q", otherName)
667 }
Nan Zhang357466b2018-04-17 17:38:36 -0700668 case systemModulesTag:
669 if deps.systemModules != nil {
670 panic("Found two system module dependencies")
671 }
672 sm := module.(*SystemModules)
673 if sm.outputFile == nil {
674 panic("Missing directory for system module dependency")
675 }
676 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800677 }
678 })
679 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
680 // may contain filegroup or genrule.
681 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700682 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900683 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800684
685 // srcs may depend on some genrule output.
686 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800687 j.srcJars = append(j.srcJars, deps.srcJars...)
688
Nan Zhang581fd212018-01-10 16:06:12 -0800689 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800690 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800691
692 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800693 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800694
Nan Zhang9c69a122018-08-22 10:22:08 -0700695 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800696 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
697 }
698 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800699
Nan Zhang1598a9e2018-09-04 17:14:32 -0700700 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
Paul Duffin99e4a502019-02-11 15:38:42 +0000701 argFilesMap := map[string]string{}
702 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700703
Paul Duffin99e4a502019-02-11 15:38:42 +0000704 for _, label := range j.properties.Arg_files {
705 var paths = ctx.ExpandSources([]string{label}, nil)
706 if _, exists := argFilesMap[label]; !exists {
707 argFilesMap[label] = strings.Join(paths.Strings(), " ")
708 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700709 } else {
710 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000711 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700712 }
713 }
714
715 var err error
716 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
717 if strings.HasPrefix(name, "location ") {
718 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000719 if paths, ok := argFilesMap[label]; ok {
720 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700721 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000722 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
723 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700724 }
725 } else if name == "genDir" {
726 return android.PathForModuleGen(ctx).String(), nil
727 }
728 return "", fmt.Errorf("unknown variable '$(%s)'", name)
729 })
730
731 if err != nil {
732 ctx.PropertyErrorf("args", "%s", err.Error())
733 }
734
Nan Zhang581fd212018-01-10 16:06:12 -0800735 return deps
736}
737
738func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
739 j.addDeps(ctx)
740}
741
742func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
743 deps := j.collectDeps(ctx)
744
745 var implicits android.Paths
746 implicits = append(implicits, deps.bootClasspath...)
747 implicits = append(implicits, deps.classpath...)
748
Nan Zhang1598a9e2018-09-04 17:14:32 -0700749 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700750
Colin Cross83bb3162018-06-25 15:48:06 -0700751 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700752 if len(deps.bootClasspath) > 0 {
753 var systemModules classpath
754 if deps.systemModules != nil {
755 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800756 }
Colin Cross997262f2018-06-19 22:49:39 -0700757 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
758 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800759 }
760 if len(deps.classpath.Strings()) > 0 {
761 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
762 }
763
764 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700765 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800766
Nan Zhangaf322cc2018-06-19 15:15:38 -0700767 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800768
Nan Zhang1598a9e2018-09-04 17:14:32 -0700769 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
770
Nan Zhang581fd212018-01-10 16:06:12 -0800771 ctx.Build(pctx, android.BuildParams{
772 Rule: javadoc,
773 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800774 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800775 ImplicitOutput: j.docZip,
776 Inputs: j.srcFiles,
777 Implicits: implicits,
778 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700779 "outDir": android.PathForModuleOut(ctx, "out").String(),
780 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
781 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800782 "srcJars": strings.Join(j.srcJars.Strings(), " "),
783 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700784 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800785 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700786 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800787 "docZip": j.docZip.String(),
788 },
789 })
790}
791
Nan Zhanga40da042018-08-01 12:48:00 -0700792//
793// Droiddoc
794//
795type Droiddoc struct {
796 Javadoc
797
798 properties DroiddocProperties
799 apiFile android.WritablePath
800 dexApiFile android.WritablePath
801 privateApiFile android.WritablePath
802 privateDexApiFile android.WritablePath
803 removedApiFile android.WritablePath
804 removedDexApiFile android.WritablePath
805 exactApiFile android.WritablePath
806 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700807 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700808
809 checkCurrentApiTimestamp android.WritablePath
810 updateCurrentApiTimestamp android.WritablePath
811 checkLastReleasedApiTimestamp android.WritablePath
812
Nan Zhanga40da042018-08-01 12:48:00 -0700813 apiFilePath android.Path
814}
815
Nan Zhanga40da042018-08-01 12:48:00 -0700816func DroiddocFactory() android.Module {
817 module := &Droiddoc{}
818
819 module.AddProperties(&module.properties,
820 &module.Javadoc.properties)
821
822 InitDroiddocModule(module, android.HostAndDeviceSupported)
823 return module
824}
825
826func DroiddocHostFactory() android.Module {
827 module := &Droiddoc{}
828
829 module.AddProperties(&module.properties,
830 &module.Javadoc.properties)
831
832 InitDroiddocModule(module, android.HostSupported)
833 return module
834}
835
836func (d *Droiddoc) ApiFilePath() android.Path {
837 return d.apiFilePath
838}
839
Nan Zhang581fd212018-01-10 16:06:12 -0800840func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
841 d.Javadoc.addDeps(ctx)
842
Nan Zhang79614d12018-04-19 18:03:39 -0700843 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800844 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
845 }
846
Nan Zhang581fd212018-01-10 16:06:12 -0800847 // knowntags may contain filegroup or genrule.
848 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700849
Nan Zhange2ba5d42018-07-11 15:16:55 -0700850 if String(d.properties.Static_doc_index_redirect) != "" {
851 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
852 }
853
854 if String(d.properties.Static_doc_properties) != "" {
855 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
856 }
857
Nan Zhang1598a9e2018-09-04 17:14:32 -0700858 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700859 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
860 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
861 }
862
Nan Zhang1598a9e2018-09-04 17:14:32 -0700863 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700864 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
865 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
866 }
Nan Zhang581fd212018-01-10 16:06:12 -0800867}
868
Nan Zhang66dc2362018-08-14 20:41:04 -0700869func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
870 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700871 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800872
Nan Zhanga40da042018-08-01 12:48:00 -0700873 *implicits = append(*implicits, deps.bootClasspath...)
874 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800875
Nan Zhangc94f9d82018-06-26 10:02:26 -0700876 if len(deps.bootClasspath.Strings()) > 0 {
877 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700878 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700879 }
Nan Zhanga40da042018-08-01 12:48:00 -0700880 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700881 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700882 dokkaClasspath := classpath{}
883 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
884 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
885 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700886
Nan Zhang9c69a122018-08-22 10:22:08 -0700887 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
888 // based stubs generation.
889 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
890 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
891 // the correct package name base path.
892 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
893 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
894 } else {
895 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
896 }
Nan Zhang581fd212018-01-10 16:06:12 -0800897
Nan Zhanga40da042018-08-01 12:48:00 -0700898 return flags, nil
899}
Nan Zhang581fd212018-01-10 16:06:12 -0800900
Nan Zhanga40da042018-08-01 12:48:00 -0700901func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700902 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800903
Nan Zhanga40da042018-08-01 12:48:00 -0700904 *implicits = append(*implicits, jsilver)
905 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700906
Nan Zhang46130972018-06-04 11:28:01 -0700907 var date string
908 if runtime.GOOS == "darwin" {
909 date = `date -r`
910 } else {
911 date = `date -d`
912 }
913
Nan Zhang443fa522018-08-20 20:58:28 -0700914 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
915 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
916 // 1.9 language features.
917 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700918 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800919 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700920 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700921
Nan Zhanga40da042018-08-01 12:48:00 -0700922 if String(d.properties.Custom_template) == "" {
923 // TODO: This is almost always droiddoc-templates-sdk
924 ctx.PropertyErrorf("custom_template", "must specify a template")
925 }
926
927 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700928 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700929 *implicits = append(*implicits, t.deps...)
930 args = args + " -templatedir " + t.dir.String()
931 } else {
932 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
933 }
934 })
935
936 if len(d.properties.Html_dirs) > 0 {
937 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
938 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
939 args = args + " -htmldir " + htmlDir.String()
940 }
941
942 if len(d.properties.Html_dirs) > 1 {
943 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
944 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
945 args = args + " -htmldir2 " + htmlDir2.String()
946 }
947
948 if len(d.properties.Html_dirs) > 2 {
949 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
950 }
951
952 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
953 *implicits = append(*implicits, knownTags...)
954
955 for _, kt := range knownTags {
956 args = args + " -knowntags " + kt.String()
957 }
958
959 for _, hdf := range d.properties.Hdf {
960 args = args + " -hdf " + hdf
961 }
962
963 if String(d.properties.Proofread_file) != "" {
964 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
965 args = args + " -proofread " + proofreadFile.String()
966 }
967
968 if String(d.properties.Todo_file) != "" {
969 // tricky part:
970 // we should not compute full path for todo_file through PathForModuleOut().
971 // the non-standard doclet will get the full path relative to "-o".
972 args = args + " -todo " + String(d.properties.Todo_file)
973 }
974
975 if String(d.properties.Resourcesdir) != "" {
976 // TODO: should we add files under resourcesDir to the implicits? It seems that
977 // resourcesDir is one sub dir of htmlDir
978 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
979 args = args + " -resourcesdir " + resourcesDir.String()
980 }
981
982 if String(d.properties.Resourcesoutdir) != "" {
983 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
984 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
985 }
986 return args
987}
988
Nan Zhang1598a9e2018-09-04 17:14:32 -0700989func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
990 implicitOutputs *android.WritablePaths) string {
991 var doclavaFlags string
992 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
993 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
994 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700995 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
996 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700997 *implicitOutputs = append(*implicitOutputs, d.apiFile)
998 d.apiFilePath = d.apiFile
999 }
1000
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1002 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1003 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001004 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1005 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001006 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1007 }
1008
1009 if String(d.properties.Private_api_filename) != "" {
1010 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1011 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001012 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1013 }
1014
1015 if String(d.properties.Dex_api_filename) != "" {
1016 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1017 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1018 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1019 }
1020
1021 if String(d.properties.Private_dex_api_filename) != "" {
1022 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1023 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001024 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1025 }
1026
1027 if String(d.properties.Removed_dex_api_filename) != "" {
1028 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1029 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001030 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1031 }
1032
1033 if String(d.properties.Exact_api_filename) != "" {
1034 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1035 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001036 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1037 }
1038
1039 if String(d.properties.Dex_mapping_filename) != "" {
1040 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1041 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001042 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1043 }
1044
Nan Zhang66dc2362018-08-14 20:41:04 -07001045 if String(d.properties.Proguard_filename) != "" {
1046 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1047 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001048 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1049 }
1050
Nan Zhanga40da042018-08-01 12:48:00 -07001051 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001052 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001053 }
1054
1055 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001056 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001057 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001058
1059 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001060}
1061
1062func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1063 var cmds string
1064 if String(d.properties.Static_doc_index_redirect) != "" {
1065 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1066 "static_doc_index_redirect")
1067 *implicits = append(*implicits, static_doc_index_redirect)
1068 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001069 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001070 }
1071
1072 if String(d.properties.Static_doc_properties) != "" {
1073 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1074 "static_doc_properties")
1075 *implicits = append(*implicits, static_doc_properties)
1076 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001077 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001078 }
1079 return cmds
1080}
1081
Nan Zhang1598a9e2018-09-04 17:14:32 -07001082func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1083 implicitOutputs android.WritablePaths,
1084 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1085 ctx.Build(pctx, android.BuildParams{
1086 Rule: javadoc,
1087 Description: "Doclava",
1088 Output: d.Javadoc.stubsSrcJar,
1089 Inputs: d.Javadoc.srcFiles,
1090 Implicits: implicits,
1091 ImplicitOutputs: implicitOutputs,
1092 Args: map[string]string{
1093 "outDir": android.PathForModuleOut(ctx, "out").String(),
1094 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1095 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1096 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1097 "opts": opts,
1098 "bootclasspathArgs": bootclasspathArgs,
1099 "classpathArgs": classpathArgs,
1100 "sourcepathArgs": sourcepathArgs,
1101 "docZip": d.Javadoc.docZip.String(),
1102 "postDoclavaCmds": postDoclavaCmds,
1103 },
1104 })
1105}
1106
1107func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1108 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1109 ctx.Build(pctx, android.BuildParams{
1110 Rule: apiCheck,
1111 Description: "Doclava Check API",
1112 Output: output,
1113 Inputs: nil,
1114 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1115 checkApiClasspath...),
1116 Args: map[string]string{
1117 "msg": msg,
1118 "classpath": checkApiClasspath.FormJavaClassPath(""),
1119 "opts": opts,
1120 "apiFile": apiFile.String(),
1121 "apiFileToCheck": d.apiFile.String(),
1122 "removedApiFile": removedApiFile.String(),
1123 "removedApiFileToCheck": d.removedApiFile.String(),
1124 },
1125 })
1126}
1127
1128func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1129 classpathArgs, opts string) {
1130 ctx.Build(pctx, android.BuildParams{
1131 Rule: dokka,
1132 Description: "Dokka",
1133 Output: d.Javadoc.stubsSrcJar,
1134 Inputs: d.Javadoc.srcFiles,
1135 Implicits: implicits,
1136 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001137 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1138 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1139 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001140 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1141 "classpathArgs": classpathArgs,
1142 "opts": opts,
1143 "docZip": d.Javadoc.docZip.String(),
1144 },
1145 })
1146}
1147
1148func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1149 deps := d.Javadoc.collectDeps(ctx)
1150
1151 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1152 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1153 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1154 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1155
1156 var implicits android.Paths
1157 implicits = append(implicits, d.Javadoc.srcJars...)
1158 implicits = append(implicits, d.Javadoc.argFiles...)
1159
1160 var implicitOutputs android.WritablePaths
1161 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1162 for _, o := range d.Javadoc.properties.Out {
1163 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1164 }
1165
1166 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1167 if err != nil {
1168 return
1169 }
1170
1171 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1172 if Bool(d.properties.Dokka_enabled) {
1173 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1174 } else {
1175 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1176 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1177 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1178 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1179 flags.postDoclavaCmds)
1180 }
1181
1182 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1183 !ctx.Config().IsPdkBuild() {
1184 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1185 "check_api.current.api_file")
1186 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1187 "check_api.current_removed_api_file")
1188
1189 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1190 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1191 fmt.Sprintf(`\n******************************\n`+
1192 `You have tried to change the API from what has been previously approved.\n\n`+
1193 `To make these errors go away, you have two choices:\n`+
1194 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1195 ` errors above.\n\n`+
1196 ` 2. You can update current.txt by executing the following command:\n`+
1197 ` make %s-update-current-api\n\n`+
1198 ` To submit the revised current.txt to the main Android repository,\n`+
1199 ` you will need approval.\n`+
1200 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1201 d.checkCurrentApiTimestamp)
1202
1203 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1204 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1205 d.updateCurrentApiTimestamp)
1206 }
1207
1208 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1209 !ctx.Config().IsPdkBuild() {
1210 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1211 "check_api.last_released.api_file")
1212 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1213 "check_api.last_released.removed_api_file")
1214
1215 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1216 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1217 `\n******************************\n`+
1218 `You have tried to change the API from what has been previously released in\n`+
1219 `an SDK. Please fix the errors listed above.\n`+
1220 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1221 d.checkLastReleasedApiTimestamp)
1222 }
1223}
1224
1225//
1226// Droidstubs
1227//
1228type Droidstubs struct {
1229 Javadoc
1230
Pete Gillin581d6082018-10-22 15:55:04 +01001231 properties DroidstubsProperties
1232 apiFile android.WritablePath
1233 apiXmlFile android.WritablePath
1234 lastReleasedApiXmlFile android.WritablePath
1235 dexApiFile android.WritablePath
1236 privateApiFile android.WritablePath
1237 privateDexApiFile android.WritablePath
1238 removedApiFile android.WritablePath
1239 removedDexApiFile android.WritablePath
1240 apiMappingFile android.WritablePath
1241 exactApiFile android.WritablePath
1242 proguardFile android.WritablePath
1243 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001244
1245 checkCurrentApiTimestamp android.WritablePath
1246 updateCurrentApiTimestamp android.WritablePath
1247 checkLastReleasedApiTimestamp android.WritablePath
1248
Pete Gillin581d6082018-10-22 15:55:04 +01001249 checkNullabilityWarningsTimestamp android.WritablePath
1250
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001252 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253
1254 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001255
1256 jdiffDocZip android.WritablePath
1257 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001258}
1259
1260func DroidstubsFactory() android.Module {
1261 module := &Droidstubs{}
1262
1263 module.AddProperties(&module.properties,
1264 &module.Javadoc.properties)
1265
1266 InitDroiddocModule(module, android.HostAndDeviceSupported)
1267 return module
1268}
1269
1270func DroidstubsHostFactory() android.Module {
1271 module := &Droidstubs{}
1272
1273 module.AddProperties(&module.properties,
1274 &module.Javadoc.properties)
1275
1276 InitDroiddocModule(module, android.HostSupported)
1277 return module
1278}
1279
1280func (d *Droidstubs) ApiFilePath() android.Path {
1281 return d.apiFilePath
1282}
1283
1284func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1285 d.Javadoc.addDeps(ctx)
1286
1287 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1288 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1289 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1290 }
1291
1292 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1293 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1294 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1295 }
1296
1297 if String(d.properties.Previous_api) != "" {
1298 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1299 }
1300
1301 if len(d.properties.Merge_annotations_dirs) != 0 {
1302 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1303 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1304 }
1305 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001306
Pete Gillin77167902018-09-19 18:16:26 +01001307 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1308 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1309 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1310 }
1311 }
1312
Pete Gillinc382a562018-11-14 18:45:46 +00001313 if String(d.properties.Validate_nullability_from_list) != "" {
1314 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1315 }
Pete Gillin581d6082018-10-22 15:55:04 +01001316 if String(d.properties.Check_nullability_warnings) != "" {
1317 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1318 }
1319
Nan Zhang9c69a122018-08-22 10:22:08 -07001320 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1321 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1322 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1323 }
1324 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001325}
1326
1327func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1328 deps deps) (droiddocBuilderFlags, error) {
1329 var flags droiddocBuilderFlags
1330
1331 *implicits = append(*implicits, deps.bootClasspath...)
1332 *implicits = append(*implicits, deps.classpath...)
1333
1334 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1335 // since it doesn't support system modules yet.
1336 if len(deps.bootClasspath.Strings()) > 0 {
1337 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1338 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1339 }
1340 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1341
Sundong Ahn56dce442018-10-05 18:41:09 +09001342 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001343 return flags, nil
1344}
1345
1346func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1347 implicitOutputs *android.WritablePaths) string {
1348 var metalavaFlags string
1349 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1350 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1351 String(d.properties.Api_filename) != "" {
1352 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1353 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1354 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1355 d.apiFilePath = d.apiFile
1356 }
1357
1358 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1359 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1360 String(d.properties.Removed_api_filename) != "" {
1361 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1362 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1363 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1364 }
1365
1366 if String(d.properties.Private_api_filename) != "" {
1367 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1368 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1369 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1370 }
1371
1372 if String(d.properties.Dex_api_filename) != "" {
1373 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1374 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1375 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1376 }
1377
1378 if String(d.properties.Private_dex_api_filename) != "" {
1379 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1380 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1381 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1382 }
1383
1384 if String(d.properties.Removed_dex_api_filename) != "" {
1385 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1386 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1387 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1388 }
1389
1390 if String(d.properties.Exact_api_filename) != "" {
1391 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1392 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1393 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1394 }
1395
Nan Zhang9c69a122018-08-22 10:22:08 -07001396 if String(d.properties.Dex_mapping_filename) != "" {
1397 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1398 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1399 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1400 }
1401
Nan Zhang199645c2018-09-19 12:40:06 -07001402 if String(d.properties.Proguard_filename) != "" {
1403 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1404 metalavaFlags += " --proguard " + d.proguardFile.String()
1405 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1406 }
1407
Nan Zhang9c69a122018-08-22 10:22:08 -07001408 if Bool(d.properties.Write_sdk_values) {
1409 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1410 }
1411
Nan Zhang1598a9e2018-09-04 17:14:32 -07001412 if Bool(d.properties.Create_doc_stubs) {
1413 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1414 } else {
1415 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1416 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001417 return metalavaFlags
1418}
1419
1420func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001421 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1422 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001423 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001424 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001425 validatingNullability :=
1426 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1427 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001428 migratingNullability := String(d.properties.Previous_api) != ""
1429 if !(migratingNullability || validatingNullability) {
1430 ctx.PropertyErrorf("previous_api",
1431 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001432 }
Pete Gillina262c052018-09-14 14:25:48 +01001433 if migratingNullability {
1434 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1435 *implicits = append(*implicits, previousApi)
1436 flags += " --migrate-nullness " + previousApi.String()
1437 }
Pete Gillinc382a562018-11-14 18:45:46 +00001438 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1439 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1440 }
Pete Gillina262c052018-09-14 14:25:48 +01001441 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001442 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1443 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1444 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001445 }
Nan Zhanga40da042018-08-01 12:48:00 -07001446
1447 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1448 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1449
Nan Zhangf4936b02018-08-01 15:00:28 -07001450 flags += " --extract-annotations " + d.annotationsZip.String()
1451
Nan Zhang1598a9e2018-09-04 17:14:32 -07001452 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001453 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001454 "has to be non-empty if annotations was enabled!")
1455 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001456 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1457 if t, ok := m.(*ExportedDroiddocDir); ok {
1458 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001459 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001460 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001461 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001462 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1463 }
1464 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001465 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001466 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001467 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001468 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001469
Nan Zhangdee152b2018-12-26 16:06:37 -08001470 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001471}
1472
1473func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1474 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1475 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001476 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1477 if t, ok := m.(*ExportedDroiddocDir); ok {
1478 *implicits = append(*implicits, t.deps...)
1479 flags += " --merge-inclusion-annotations " + t.dir.String()
1480 } else {
1481 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1482 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1483 }
1484 })
Nan Zhanga40da042018-08-01 12:48:00 -07001485
1486 return flags
1487}
1488
Nan Zhang9c69a122018-08-22 10:22:08 -07001489func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1490 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1491 var flags string
1492 if Bool(d.properties.Api_levels_annotations_enabled) {
1493 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1494 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1495
1496 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1497 ctx.PropertyErrorf("api_levels_annotations_dirs",
1498 "has to be non-empty if api levels annotations was enabled!")
1499 }
1500
1501 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1502 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1503 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1504
1505 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1506 if t, ok := m.(*ExportedDroiddocDir); ok {
1507 var androidJars android.Paths
1508 for _, dep := range t.deps {
1509 if strings.HasSuffix(dep.String(), "android.jar") {
1510 androidJars = append(androidJars, dep)
1511 }
1512 }
1513 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001514 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001515 } else {
1516 ctx.PropertyErrorf("api_levels_annotations_dirs",
1517 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1518 }
1519 })
1520
1521 }
1522
1523 return flags
1524}
1525
Nan Zhang71bbe632018-09-17 14:32:21 -07001526func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1527 implicitOutputs *android.WritablePaths) string {
1528 var flags string
1529 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1530 if d.apiFile.String() == "" {
1531 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1532 }
1533
1534 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1535 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1536
1537 flags = " --api-xml " + d.apiXmlFile.String()
1538
1539 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1540 ctx.PropertyErrorf("check_api.last_released.api_file",
1541 "has to be non-empty if jdiff was enabled!")
1542 }
1543 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1544 "check_api.last_released.api_file")
1545 *implicits = append(*implicits, lastReleasedApi)
1546
1547 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1548 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1549
1550 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1551 d.lastReleasedApiXmlFile.String()
1552 }
1553
1554 return flags
1555}
1556
Nan Zhang1598a9e2018-09-04 17:14:32 -07001557func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1558 implicitOutputs android.WritablePaths, javaVersion,
1559 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001560
Nan Zhang86d2d552018-08-09 15:33:27 -07001561 ctx.Build(pctx, android.BuildParams{
1562 Rule: metalava,
1563 Description: "Metalava",
1564 Output: d.Javadoc.stubsSrcJar,
1565 Inputs: d.Javadoc.srcFiles,
1566 Implicits: implicits,
1567 ImplicitOutputs: implicitOutputs,
1568 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001569 "outDir": android.PathForModuleOut(ctx, "out").String(),
1570 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1571 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1572 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001573 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001574 "bootclasspathArgs": bootclasspathArgs,
1575 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001576 "sourcepathArgs": sourcepathArgs,
1577 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001578 },
1579 })
1580}
1581
Nan Zhang1598a9e2018-09-04 17:14:32 -07001582func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1583 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001584 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001585 output android.WritablePath) {
1586 ctx.Build(pctx, android.BuildParams{
1587 Rule: metalavaApiCheck,
1588 Description: "Metalava Check API",
1589 Output: output,
1590 Inputs: d.Javadoc.srcFiles,
1591 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1592 implicits...),
1593 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001594 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001595 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1596 "javaVersion": javaVersion,
1597 "bootclasspathArgs": bootclasspathArgs,
1598 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001599 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001600 "opts": opts,
1601 "msg": msg,
1602 },
1603 })
1604}
1605
Nan Zhang71bbe632018-09-17 14:32:21 -07001606func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1607 implicitOutputs android.WritablePaths,
1608 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1609 ctx.Build(pctx, android.BuildParams{
1610 Rule: javadoc,
1611 Description: "Jdiff",
1612 Output: d.jdiffStubsSrcJar,
1613 Inputs: d.Javadoc.srcFiles,
1614 Implicits: implicits,
1615 ImplicitOutputs: implicitOutputs,
1616 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001617 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1618 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1619 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001620 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1621 "opts": opts,
1622 "bootclasspathArgs": bootclasspathArgs,
1623 "classpathArgs": classpathArgs,
1624 "sourcepathArgs": sourcepathArgs,
1625 "docZip": d.jdiffDocZip.String(),
1626 },
1627 })
1628}
1629
Nan Zhang1598a9e2018-09-04 17:14:32 -07001630func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001631 deps := d.Javadoc.collectDeps(ctx)
1632
1633 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001634
Nan Zhanga40da042018-08-01 12:48:00 -07001635 var implicits android.Paths
1636 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001637 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001638
1639 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001640 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001641 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1642 }
1643
1644 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001645 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001646 jdiffImplicits := implicits
1647
Nan Zhanga40da042018-08-01 12:48:00 -07001648 if err != nil {
1649 return
1650 }
1651
Nan Zhang1598a9e2018-09-04 17:14:32 -07001652 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001653 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1654 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001655 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001656 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001657 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1658
Nan Zhang1598a9e2018-09-04 17:14:32 -07001659 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1660 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1661 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1662 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1663 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001664 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001665 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1666 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001667 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001668 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001669
Nan Zhang1598a9e2018-09-04 17:14:32 -07001670 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1671 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001672 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1673 "check_api.current.api_file")
1674 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1675 "check_api.current_removed_api_file")
1676
Nan Zhang2760dfc2018-08-24 17:32:54 +00001677 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001678 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1679 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001680 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001681
Nan Zhang1598a9e2018-09-04 17:14:32 -07001682 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001683 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001684 fmt.Sprintf(`\n******************************\n`+
1685 `You have tried to change the API from what has been previously approved.\n\n`+
1686 `To make these errors go away, you have two choices:\n`+
1687 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1688 ` errors above.\n\n`+
1689 ` 2. You can update current.txt by executing the following command:\n`+
1690 ` make %s-update-current-api\n\n`+
1691 ` To submit the revised current.txt to the main Android repository,\n`+
1692 ` you will need approval.\n`+
1693 `******************************\n`, ctx.ModuleName()),
1694 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001695
1696 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001697 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1698 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001699 }
Nan Zhanga40da042018-08-01 12:48:00 -07001700
Nan Zhang1598a9e2018-09-04 17:14:32 -07001701 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1702 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001703 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1704 "check_api.last_released.api_file")
1705 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1706 "check_api.last_released.removed_api_file")
1707
Nan Zhang2760dfc2018-08-24 17:32:54 +00001708 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001709 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1710 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001711 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001712
Nan Zhang1598a9e2018-09-04 17:14:32 -07001713 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001714 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001715 `\n******************************\n`+
1716 `You have tried to change the API from what has been previously released in\n`+
1717 `an SDK. Please fix the errors listed above.\n`+
1718 `******************************\n`,
1719 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001720 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001721
Pete Gillin581d6082018-10-22 15:55:04 +01001722 if String(d.properties.Check_nullability_warnings) != "" {
1723 if d.nullabilityWarningsFile == nil {
1724 ctx.PropertyErrorf("check_nullability_warnings",
1725 "Cannot specify check_nullability_warnings unless validating nullability")
1726 }
1727 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1728 "check_nullability_warnings")
1729 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1730 msg := fmt.Sprintf(`\n******************************\n`+
1731 `The warnings encountered during nullability annotation validation did\n`+
1732 `not match the checked in file of expected warnings. The diffs are shown\n`+
1733 `above. You have two options:\n`+
1734 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1735 ` 2. Update the file of expected warnings by running:\n`+
1736 ` cp %s %s\n`+
1737 ` and submitting the updated file as part of your change.`,
1738 d.nullabilityWarningsFile, checkNullabilityWarnings)
1739 ctx.Build(pctx, android.BuildParams{
1740 Rule: nullabilityWarningsCheck,
1741 Description: "Nullability Warnings Check",
1742 Output: d.checkNullabilityWarningsTimestamp,
1743 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1744 Args: map[string]string{
1745 "expected": checkNullabilityWarnings.String(),
1746 "actual": d.nullabilityWarningsFile.String(),
1747 "msg": msg,
1748 },
1749 })
1750 }
1751
Nan Zhang71bbe632018-09-17 14:32:21 -07001752 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1753
Nan Zhang86b06202018-09-21 17:09:21 -07001754 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1755 // since there's cron job downstream that fetch this .zip file periodically.
1756 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001757 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1758 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1759
1760 var jdiffImplicitOutputs android.WritablePaths
1761 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1762
1763 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1764 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1765
1766 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1767 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1768 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1769 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1770 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1771 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1772
1773 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1774 flags.sourcepathArgs, opts)
1775 }
Nan Zhang581fd212018-01-10 16:06:12 -08001776}
Dan Willemsencc090972018-02-26 14:33:31 -08001777
Nan Zhanga40da042018-08-01 12:48:00 -07001778//
Nan Zhangf4936b02018-08-01 15:00:28 -07001779// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001780//
Dan Willemsencc090972018-02-26 14:33:31 -08001781var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001782var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001783var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001784var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001785
Nan Zhangf4936b02018-08-01 15:00:28 -07001786type ExportedDroiddocDirProperties struct {
1787 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001788 Path *string
1789}
1790
Nan Zhangf4936b02018-08-01 15:00:28 -07001791type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001792 android.ModuleBase
1793
Nan Zhangf4936b02018-08-01 15:00:28 -07001794 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001795
1796 deps android.Paths
1797 dir android.Path
1798}
1799
Nan Zhangf4936b02018-08-01 15:00:28 -07001800func ExportedDroiddocDirFactory() android.Module {
1801 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001802 module.AddProperties(&module.properties)
1803 android.InitAndroidModule(module)
1804 return module
1805}
1806
Nan Zhangf4936b02018-08-01 15:00:28 -07001807func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001808
Nan Zhangf4936b02018-08-01 15:00:28 -07001809func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001810 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1811 d.dir = path
1812 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1813}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001814
1815//
1816// Defaults
1817//
1818type DocDefaults struct {
1819 android.ModuleBase
1820 android.DefaultsModuleBase
1821}
1822
1823func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1824}
1825
Nan Zhangb2b33de2018-02-23 11:18:47 -08001826func DocDefaultsFactory() android.Module {
1827 module := &DocDefaults{}
1828
1829 module.AddProperties(
1830 &JavadocProperties{},
1831 &DroiddocProperties{},
1832 )
1833
1834 android.InitDefaultsModule(module)
1835
1836 return module
1837}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001838
1839func StubsDefaultsFactory() android.Module {
1840 module := &DocDefaults{}
1841
1842 module.AddProperties(
1843 &JavadocProperties{},
1844 &DroidstubsProperties{},
1845 )
1846
1847 android.InitDefaultsModule(module)
1848
1849 return module
1850}