blob: 85e479790c1ecaf65c80beb2d1b54d0d92ffc9c0 [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
Paul Duffin2fbbfb82019-02-13 12:49:33 +0000174 // don't build against the default libraries (bootclasspath, ext, and framework for device
175 // targets)
Nan Zhang5994b622018-09-21 16:39:51 -0700176 No_standard_libs *bool
177
Paul Duffin2fbbfb82019-02-13 12:49:33 +0000178 // don't build against the framework libraries (ext, and framework for device targets)
Nan Zhange66c7272018-03-06 12:59:27 -0800179 No_framework_libs *bool
180
Nan Zhangb2b33de2018-02-23 11:18:47 -0800181 // the java library (in classpath) for documentation that provides java srcs and srcjars.
182 Srcs_lib *string
183
184 // the base dirs under srcs_lib will be scanned for java srcs.
185 Srcs_lib_whitelist_dirs []string
186
187 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
188 Srcs_lib_whitelist_pkgs []string
189
Nan Zhang581fd212018-01-10 16:06:12 -0800190 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800191 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800192
193 // if not blank, set to the version of the sdk to compile against
194 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900195
196 Aidl struct {
197 // Top level directories to pass to aidl tool
198 Include_dirs []string
199
200 // Directories rooted at the Android.bp file to pass to aidl tool
201 Local_include_dirs []string
202 }
Nan Zhang357466b2018-04-17 17:38:36 -0700203
204 // If not blank, set the java version passed to javadoc as -source
205 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700206
207 // local files that are used within user customized droiddoc options.
208 Arg_files []string
209
210 // user customized droiddoc args.
211 // Available variables for substitution:
212 //
213 // $(location <label>): the path to the arg_files with name <label>
214 Args *string
215
216 // names of the output files used in args that will be generated
217 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800218}
219
Nan Zhang61819ce2018-05-04 18:49:16 -0700220type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900221 // path to the API txt file that the new API extracted from source code is checked
222 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700223 Api_file *string
224
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900225 // path to the API txt file that the new @removed API extractd from source code is
226 // checked against. The path can be local to the module or from other module (via
227 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700228 Removed_api_file *string
229
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900230 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700231 Args *string
232}
233
Nan Zhang581fd212018-01-10 16:06:12 -0800234type DroiddocProperties struct {
235 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800237
Nan Zhanga40da042018-08-01 12:48:00 -0700238 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800239 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800240
241 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800242 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800243
244 // proofread file contains all of the text content of the javadocs concatenated into one file,
245 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800246 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800247
248 // a todo file lists the program elements that are missing documentation.
249 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800250 Todo_file *string
251
252 // directory under current module source that provide additional resources (images).
253 Resourcesdir *string
254
255 // resources output directory under out/soong/.intermediates.
256 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800257
Nan Zhange2ba5d42018-07-11 15:16:55 -0700258 // if set to true, collect the values used by the Dev tools and
259 // write them in files packaged with the SDK. Defaults to false.
260 Write_sdk_values *bool
261
262 // index.html under current module will be copied to docs out dir, if not null.
263 Static_doc_index_redirect *string
264
265 // source.properties under current module will be copied to docs out dir, if not null.
266 Static_doc_properties *string
267
Nan Zhang581fd212018-01-10 16:06:12 -0800268 // a list of files under current module source dir which contains known tags in Java sources.
269 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800270 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700271
272 // the tag name used to distinguish if the API files belong to public/system/test.
273 Api_tag_name *string
274
275 // the generated public API filename by Doclava.
276 Api_filename *string
277
David Brazdilfbe4cc32018-05-31 13:56:46 +0100278 // the generated public Dex API filename by Doclava.
279 Dex_api_filename *string
280
Nan Zhang28c68b92018-03-13 16:17:01 -0700281 // the generated private API filename by Doclava.
282 Private_api_filename *string
283
284 // the generated private Dex API filename by Doclava.
285 Private_dex_api_filename *string
286
287 // the generated removed API filename by Doclava.
288 Removed_api_filename *string
289
David Brazdilaac0c3c2018-04-24 16:23:29 +0100290 // the generated removed Dex API filename by Doclava.
291 Removed_dex_api_filename *string
292
Mathew Inwood76c3de12018-06-22 15:28:11 +0100293 // mapping of dex signatures to source file and line number. This is a temporary property and
294 // will be deleted; you probably shouldn't be using it.
295 Dex_mapping_filename *string
296
Nan Zhang28c68b92018-03-13 16:17:01 -0700297 // the generated exact API filename by Doclava.
298 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700299
Nan Zhang66dc2362018-08-14 20:41:04 -0700300 // the generated proguard filename by Doclava.
301 Proguard_filename *string
302
Nan Zhang853f4202018-04-12 16:55:56 -0700303 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
304 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700305
306 Check_api struct {
307 Last_released ApiToCheck
308
309 Current ApiToCheck
310 }
Nan Zhang79614d12018-04-19 18:03:39 -0700311
Nan Zhang1598a9e2018-09-04 17:14:32 -0700312 // if set to true, generate docs through Dokka instead of Doclava.
313 Dokka_enabled *bool
314}
315
316type DroidstubsProperties struct {
317 // the tag name used to distinguish if the API files belong to public/system/test.
318 Api_tag_name *string
319
Nan Zhang199645c2018-09-19 12:40:06 -0700320 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700321 Api_filename *string
322
Nan Zhang199645c2018-09-19 12:40:06 -0700323 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700324 Dex_api_filename *string
325
Nan Zhang199645c2018-09-19 12:40:06 -0700326 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700327 Private_api_filename *string
328
Nan Zhang199645c2018-09-19 12:40:06 -0700329 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700330 Private_dex_api_filename *string
331
Nan Zhang199645c2018-09-19 12:40:06 -0700332 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700333 Removed_api_filename *string
334
Nan Zhang199645c2018-09-19 12:40:06 -0700335 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700336 Removed_dex_api_filename *string
337
Nan Zhang9c69a122018-08-22 10:22:08 -0700338 // mapping of dex signatures to source file and line number. This is a temporary property and
339 // will be deleted; you probably shouldn't be using it.
340 Dex_mapping_filename *string
341
Nan Zhang199645c2018-09-19 12:40:06 -0700342 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700343 Exact_api_filename *string
344
Nan Zhang199645c2018-09-19 12:40:06 -0700345 // the generated proguard filename by Metalava.
346 Proguard_filename *string
347
Nan Zhang1598a9e2018-09-04 17:14:32 -0700348 Check_api struct {
349 Last_released ApiToCheck
350
351 Current ApiToCheck
352 }
Nan Zhang79614d12018-04-19 18:03:39 -0700353
354 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700355 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700356
357 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700358 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700359
Pete Gillin77167902018-09-19 18:16:26 +0100360 // 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 -0700361 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700362
Pete Gillin77167902018-09-19 18:16:26 +0100363 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
364 Merge_inclusion_annotations_dirs []string
365
Pete Gillinc382a562018-11-14 18:45:46 +0000366 // a file containing a list of classes to do nullability validation for.
367 Validate_nullability_from_list *string
368
Pete Gillin581d6082018-10-22 15:55:04 +0100369 // a file containing expected warnings produced by validation of nullability annotations.
370 Check_nullability_warnings *string
371
Nan Zhang1598a9e2018-09-04 17:14:32 -0700372 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
373 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700374
375 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
376 Api_levels_annotations_enabled *bool
377
378 // the dirs which Metalava extracts API levels annotations from.
379 Api_levels_annotations_dirs []string
380
381 // if set to true, collect the values used by the Dev tools and
382 // write them in files packaged with the SDK. Defaults to false.
383 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700384
385 // If set to true, .xml based public API file will be also generated, and
386 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
387 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800388}
389
Nan Zhanga40da042018-08-01 12:48:00 -0700390//
391// Common flags passed down to build rule
392//
393type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700394 bootClasspathArgs string
395 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700396 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700397 dokkaClasspathArgs string
398 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700399
Nan Zhanga40da042018-08-01 12:48:00 -0700400 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700401 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700402 postDoclavaCmds string
403
Nan Zhang9c69a122018-08-22 10:22:08 -0700404 metalavaStubsFlags string
405 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800406 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100407 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700408 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700409
Nan Zhang71bbe632018-09-17 14:32:21 -0700410 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700411}
412
413func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
414 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
415 android.InitDefaultableModule(module)
416}
417
Nan Zhang1598a9e2018-09-04 17:14:32 -0700418func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
419 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
420 return true
421 } else if String(apiToCheck.Api_file) != "" {
422 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
423 } else if String(apiToCheck.Removed_api_file) != "" {
424 panic("for " + apiVersionTag + " api_file has to be non-empty!")
425 }
426
427 return false
428}
429
430type ApiFilePath interface {
431 ApiFilePath() android.Path
432}
433
434func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
435 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
436 ctx.Build(pctx, android.BuildParams{
437 Rule: updateApi,
438 Description: "Update API",
439 Output: output,
440 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
441 destApiFile, destRemovedApiFile),
442 Args: map[string]string{
443 "destApiFile": destApiFile.String(),
444 "srcApiFile": srcApiFile.String(),
445 "destRemovedApiFile": destRemovedApiFile.String(),
446 "srcRemovedApiFile": srcRemovedApiFile.String(),
447 },
448 })
449}
450
Nan Zhanga40da042018-08-01 12:48:00 -0700451//
452// Javadoc
453//
Nan Zhang581fd212018-01-10 16:06:12 -0800454type Javadoc struct {
455 android.ModuleBase
456 android.DefaultableModuleBase
457
458 properties JavadocProperties
459
460 srcJars android.Paths
461 srcFiles android.Paths
462 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700463 argFiles android.Paths
464
465 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800466
Nan Zhangccff0f72018-03-08 17:26:16 -0800467 docZip android.WritablePath
468 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800469}
470
Nan Zhangb2b33de2018-02-23 11:18:47 -0800471func (j *Javadoc) Srcs() android.Paths {
472 return android.Paths{j.stubsSrcJar}
473}
474
Nan Zhang581fd212018-01-10 16:06:12 -0800475func JavadocFactory() android.Module {
476 module := &Javadoc{}
477
478 module.AddProperties(&module.properties)
479
480 InitDroiddocModule(module, android.HostAndDeviceSupported)
481 return module
482}
483
484func JavadocHostFactory() android.Module {
485 module := &Javadoc{}
486
487 module.AddProperties(&module.properties)
488
489 InitDroiddocModule(module, android.HostSupported)
490 return module
491}
492
Nan Zhanga40da042018-08-01 12:48:00 -0700493var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800494
Colin Cross83bb3162018-06-25 15:48:06 -0700495func (j *Javadoc) sdkVersion() string {
496 return String(j.properties.Sdk_version)
497}
498
499func (j *Javadoc) minSdkVersion() string {
500 return j.sdkVersion()
501}
502
Dan Willemsen419290a2018-10-31 15:28:47 -0700503func (j *Javadoc) targetSdkVersion() string {
504 return j.sdkVersion()
505}
506
Nan Zhang581fd212018-01-10 16:06:12 -0800507func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
508 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700509 if !Bool(j.properties.No_standard_libs) {
510 sdkDep := decodeSdkDep(ctx, sdkContext(j))
511 if sdkDep.useDefaultLibs {
512 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
513 if ctx.Config().TargetOpenJDK9() {
514 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
515 }
516 if !Bool(j.properties.No_framework_libs) {
517 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
518 }
519 } else if sdkDep.useModule {
520 if ctx.Config().TargetOpenJDK9() {
521 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
522 }
523 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700524 }
Nan Zhang581fd212018-01-10 16:06:12 -0800525 }
526 }
527
Colin Cross42d48b72018-08-29 14:10:52 -0700528 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700529 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700530 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700531 }
Nan Zhang581fd212018-01-10 16:06:12 -0800532
533 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
534
535 // exclude_srcs may contain filegroup or genrule.
536 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700537
538 // arg_files may contains filegroup or genrule.
539 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800540}
541
Nan Zhangb2b33de2018-02-23 11:18:47 -0800542func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
543 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
544 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900545 // convert foo.bar.baz to foo/bar/baz
546 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
547 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800548 if _, found := whitelistPathPrefixes[prefix]; !found {
549 whitelistPathPrefixes[prefix] = true
550 }
551 }
552 }
553}
554
Nan Zhanga40da042018-08-01 12:48:00 -0700555func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
556 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900557
558 // aidl flags.
559 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
560 if len(aidlFlags) > 0 {
561 // optimization.
562 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
563 flags.aidlFlags = "$aidlFlags"
564 }
565
566 return flags
567}
568
569func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
570 aidlIncludeDirs android.Paths) []string {
571
572 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
573 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
574
575 var flags []string
576 if aidlPreprocess.Valid() {
577 flags = append(flags, "-p"+aidlPreprocess.String())
578 } else {
579 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
580 }
581
582 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
583 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
584 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
585 flags = append(flags, "-I"+src.String())
586 }
587
588 return flags
589}
590
591func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700592 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900593
594 outSrcFiles := make(android.Paths, 0, len(srcFiles))
595
596 for _, srcFile := range srcFiles {
597 switch srcFile.Ext() {
598 case ".aidl":
599 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
600 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900601 case ".sysprop":
602 javaFile := genSysprop(ctx, srcFile)
603 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900604 default:
605 outSrcFiles = append(outSrcFiles, srcFile)
606 }
607 }
608
609 return outSrcFiles
610}
611
Nan Zhang581fd212018-01-10 16:06:12 -0800612func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
613 var deps deps
614
Colin Cross83bb3162018-06-25 15:48:06 -0700615 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800616 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700617 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800618 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700619 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800620 }
621
622 ctx.VisitDirectDeps(func(module android.Module) {
623 otherName := ctx.OtherModuleName(module)
624 tag := ctx.OtherModuleDependencyTag(module)
625
Colin Cross2d24c1b2018-05-23 10:59:18 -0700626 switch tag {
627 case bootClasspathTag:
628 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800629 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700630 } else {
631 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
632 }
633 case libTag:
634 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800635 case SdkLibraryDependency:
636 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700637 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900638 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700639 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800640 checkProducesJars(ctx, dep)
641 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800642 default:
643 ctx.ModuleErrorf("depends on non-java module %q", otherName)
644 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700645 case srcsLibTag:
646 switch dep := module.(type) {
647 case Dependency:
648 srcs := dep.(SrcDependency).CompiledSrcs()
649 whitelistPathPrefixes := make(map[string]bool)
650 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
651 for _, src := range srcs {
652 if _, ok := src.(android.WritablePath); ok { // generated sources
653 deps.srcs = append(deps.srcs, src)
654 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700655 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700656 if strings.HasPrefix(src.Rel(), k) {
657 deps.srcs = append(deps.srcs, src)
658 break
659 }
660 }
661 }
662 }
663 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
664 default:
665 ctx.ModuleErrorf("depends on non-java module %q", otherName)
666 }
Nan Zhang357466b2018-04-17 17:38:36 -0700667 case systemModulesTag:
668 if deps.systemModules != nil {
669 panic("Found two system module dependencies")
670 }
671 sm := module.(*SystemModules)
672 if sm.outputFile == nil {
673 panic("Missing directory for system module dependency")
674 }
675 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800676 }
677 })
678 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
679 // may contain filegroup or genrule.
680 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700681 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900682 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800683
684 // srcs may depend on some genrule output.
685 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800686 j.srcJars = append(j.srcJars, deps.srcJars...)
687
Nan Zhang581fd212018-01-10 16:06:12 -0800688 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800689 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800690
691 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800692 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800693
Nan Zhang9c69a122018-08-22 10:22:08 -0700694 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800695 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
696 }
697 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800698
Nan Zhang1598a9e2018-09-04 17:14:32 -0700699 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
Paul Duffin99e4a502019-02-11 15:38:42 +0000700 argFilesMap := map[string]string{}
701 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700702
Paul Duffin99e4a502019-02-11 15:38:42 +0000703 for _, label := range j.properties.Arg_files {
704 var paths = ctx.ExpandSources([]string{label}, nil)
705 if _, exists := argFilesMap[label]; !exists {
706 argFilesMap[label] = strings.Join(paths.Strings(), " ")
707 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700708 } else {
709 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000710 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700711 }
712 }
713
714 var err error
715 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
716 if strings.HasPrefix(name, "location ") {
717 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000718 if paths, ok := argFilesMap[label]; ok {
719 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700720 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000721 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
722 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700723 }
724 } else if name == "genDir" {
725 return android.PathForModuleGen(ctx).String(), nil
726 }
727 return "", fmt.Errorf("unknown variable '$(%s)'", name)
728 })
729
730 if err != nil {
731 ctx.PropertyErrorf("args", "%s", err.Error())
732 }
733
Nan Zhang581fd212018-01-10 16:06:12 -0800734 return deps
735}
736
737func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
738 j.addDeps(ctx)
739}
740
741func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
742 deps := j.collectDeps(ctx)
743
744 var implicits android.Paths
745 implicits = append(implicits, deps.bootClasspath...)
746 implicits = append(implicits, deps.classpath...)
747
Nan Zhang1598a9e2018-09-04 17:14:32 -0700748 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700749
Colin Cross83bb3162018-06-25 15:48:06 -0700750 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700751 if len(deps.bootClasspath) > 0 {
752 var systemModules classpath
753 if deps.systemModules != nil {
754 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800755 }
Colin Cross997262f2018-06-19 22:49:39 -0700756 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
757 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800758 }
759 if len(deps.classpath.Strings()) > 0 {
760 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
761 }
762
763 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700764 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800765
Nan Zhangaf322cc2018-06-19 15:15:38 -0700766 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800767
Nan Zhang1598a9e2018-09-04 17:14:32 -0700768 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
769
Nan Zhang581fd212018-01-10 16:06:12 -0800770 ctx.Build(pctx, android.BuildParams{
771 Rule: javadoc,
772 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800773 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800774 ImplicitOutput: j.docZip,
775 Inputs: j.srcFiles,
776 Implicits: implicits,
777 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700778 "outDir": android.PathForModuleOut(ctx, "out").String(),
779 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
780 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800781 "srcJars": strings.Join(j.srcJars.Strings(), " "),
782 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700783 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800784 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700785 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800786 "docZip": j.docZip.String(),
787 },
788 })
789}
790
Nan Zhanga40da042018-08-01 12:48:00 -0700791//
792// Droiddoc
793//
794type Droiddoc struct {
795 Javadoc
796
797 properties DroiddocProperties
798 apiFile android.WritablePath
799 dexApiFile android.WritablePath
800 privateApiFile android.WritablePath
801 privateDexApiFile android.WritablePath
802 removedApiFile android.WritablePath
803 removedDexApiFile android.WritablePath
804 exactApiFile android.WritablePath
805 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700806 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700807
808 checkCurrentApiTimestamp android.WritablePath
809 updateCurrentApiTimestamp android.WritablePath
810 checkLastReleasedApiTimestamp android.WritablePath
811
Nan Zhanga40da042018-08-01 12:48:00 -0700812 apiFilePath android.Path
813}
814
Nan Zhanga40da042018-08-01 12:48:00 -0700815func DroiddocFactory() android.Module {
816 module := &Droiddoc{}
817
818 module.AddProperties(&module.properties,
819 &module.Javadoc.properties)
820
821 InitDroiddocModule(module, android.HostAndDeviceSupported)
822 return module
823}
824
825func DroiddocHostFactory() android.Module {
826 module := &Droiddoc{}
827
828 module.AddProperties(&module.properties,
829 &module.Javadoc.properties)
830
831 InitDroiddocModule(module, android.HostSupported)
832 return module
833}
834
835func (d *Droiddoc) ApiFilePath() android.Path {
836 return d.apiFilePath
837}
838
Nan Zhang581fd212018-01-10 16:06:12 -0800839func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
840 d.Javadoc.addDeps(ctx)
841
Nan Zhang79614d12018-04-19 18:03:39 -0700842 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800843 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
844 }
845
Nan Zhang581fd212018-01-10 16:06:12 -0800846 // knowntags may contain filegroup or genrule.
847 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700848
Nan Zhange2ba5d42018-07-11 15:16:55 -0700849 if String(d.properties.Static_doc_index_redirect) != "" {
850 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
851 }
852
853 if String(d.properties.Static_doc_properties) != "" {
854 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
855 }
856
Nan Zhang1598a9e2018-09-04 17:14:32 -0700857 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700858 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
859 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
860 }
861
Nan Zhang1598a9e2018-09-04 17:14:32 -0700862 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700863 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
864 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
865 }
Nan Zhang581fd212018-01-10 16:06:12 -0800866}
867
Nan Zhang66dc2362018-08-14 20:41:04 -0700868func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
869 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700870 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800871
Nan Zhanga40da042018-08-01 12:48:00 -0700872 *implicits = append(*implicits, deps.bootClasspath...)
873 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800874
Nan Zhangc94f9d82018-06-26 10:02:26 -0700875 if len(deps.bootClasspath.Strings()) > 0 {
876 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700877 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700878 }
Nan Zhanga40da042018-08-01 12:48:00 -0700879 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700880 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700881 dokkaClasspath := classpath{}
882 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
883 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
884 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700885
Nan Zhang9c69a122018-08-22 10:22:08 -0700886 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
887 // based stubs generation.
888 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
889 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
890 // the correct package name base path.
891 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
892 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
893 } else {
894 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
895 }
Nan Zhang581fd212018-01-10 16:06:12 -0800896
Nan Zhanga40da042018-08-01 12:48:00 -0700897 return flags, nil
898}
Nan Zhang581fd212018-01-10 16:06:12 -0800899
Nan Zhanga40da042018-08-01 12:48:00 -0700900func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700901 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800902
Nan Zhanga40da042018-08-01 12:48:00 -0700903 *implicits = append(*implicits, jsilver)
904 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700905
Nan Zhang46130972018-06-04 11:28:01 -0700906 var date string
907 if runtime.GOOS == "darwin" {
908 date = `date -r`
909 } else {
910 date = `date -d`
911 }
912
Nan Zhang443fa522018-08-20 20:58:28 -0700913 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
914 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
915 // 1.9 language features.
916 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700917 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800918 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700919 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700920
Nan Zhanga40da042018-08-01 12:48:00 -0700921 if String(d.properties.Custom_template) == "" {
922 // TODO: This is almost always droiddoc-templates-sdk
923 ctx.PropertyErrorf("custom_template", "must specify a template")
924 }
925
926 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700927 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700928 *implicits = append(*implicits, t.deps...)
929 args = args + " -templatedir " + t.dir.String()
930 } else {
931 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
932 }
933 })
934
935 if len(d.properties.Html_dirs) > 0 {
936 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
937 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
938 args = args + " -htmldir " + htmlDir.String()
939 }
940
941 if len(d.properties.Html_dirs) > 1 {
942 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
943 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
944 args = args + " -htmldir2 " + htmlDir2.String()
945 }
946
947 if len(d.properties.Html_dirs) > 2 {
948 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
949 }
950
951 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
952 *implicits = append(*implicits, knownTags...)
953
954 for _, kt := range knownTags {
955 args = args + " -knowntags " + kt.String()
956 }
957
958 for _, hdf := range d.properties.Hdf {
959 args = args + " -hdf " + hdf
960 }
961
962 if String(d.properties.Proofread_file) != "" {
963 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
964 args = args + " -proofread " + proofreadFile.String()
965 }
966
967 if String(d.properties.Todo_file) != "" {
968 // tricky part:
969 // we should not compute full path for todo_file through PathForModuleOut().
970 // the non-standard doclet will get the full path relative to "-o".
971 args = args + " -todo " + String(d.properties.Todo_file)
972 }
973
974 if String(d.properties.Resourcesdir) != "" {
975 // TODO: should we add files under resourcesDir to the implicits? It seems that
976 // resourcesDir is one sub dir of htmlDir
977 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
978 args = args + " -resourcesdir " + resourcesDir.String()
979 }
980
981 if String(d.properties.Resourcesoutdir) != "" {
982 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
983 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
984 }
985 return args
986}
987
Nan Zhang1598a9e2018-09-04 17:14:32 -0700988func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
989 implicitOutputs *android.WritablePaths) string {
990 var doclavaFlags string
991 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
992 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
993 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700994 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
995 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700996 *implicitOutputs = append(*implicitOutputs, d.apiFile)
997 d.apiFilePath = d.apiFile
998 }
999
Nan Zhang1598a9e2018-09-04 17:14:32 -07001000 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1001 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1002 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001003 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1004 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001005 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1006 }
1007
1008 if String(d.properties.Private_api_filename) != "" {
1009 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1010 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001011 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1012 }
1013
1014 if String(d.properties.Dex_api_filename) != "" {
1015 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1016 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1017 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1018 }
1019
1020 if String(d.properties.Private_dex_api_filename) != "" {
1021 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1022 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001023 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1024 }
1025
1026 if String(d.properties.Removed_dex_api_filename) != "" {
1027 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1028 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001029 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1030 }
1031
1032 if String(d.properties.Exact_api_filename) != "" {
1033 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1034 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001035 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1036 }
1037
1038 if String(d.properties.Dex_mapping_filename) != "" {
1039 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1040 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001041 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1042 }
1043
Nan Zhang66dc2362018-08-14 20:41:04 -07001044 if String(d.properties.Proguard_filename) != "" {
1045 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1046 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001047 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1048 }
1049
Nan Zhanga40da042018-08-01 12:48:00 -07001050 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001051 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001052 }
1053
1054 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001055 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001056 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001057
1058 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001059}
1060
1061func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1062 var cmds string
1063 if String(d.properties.Static_doc_index_redirect) != "" {
1064 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1065 "static_doc_index_redirect")
1066 *implicits = append(*implicits, static_doc_index_redirect)
1067 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001068 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001069 }
1070
1071 if String(d.properties.Static_doc_properties) != "" {
1072 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1073 "static_doc_properties")
1074 *implicits = append(*implicits, static_doc_properties)
1075 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001076 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001077 }
1078 return cmds
1079}
1080
Nan Zhang1598a9e2018-09-04 17:14:32 -07001081func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1082 implicitOutputs android.WritablePaths,
1083 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1084 ctx.Build(pctx, android.BuildParams{
1085 Rule: javadoc,
1086 Description: "Doclava",
1087 Output: d.Javadoc.stubsSrcJar,
1088 Inputs: d.Javadoc.srcFiles,
1089 Implicits: implicits,
1090 ImplicitOutputs: implicitOutputs,
1091 Args: map[string]string{
1092 "outDir": android.PathForModuleOut(ctx, "out").String(),
1093 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1094 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1095 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1096 "opts": opts,
1097 "bootclasspathArgs": bootclasspathArgs,
1098 "classpathArgs": classpathArgs,
1099 "sourcepathArgs": sourcepathArgs,
1100 "docZip": d.Javadoc.docZip.String(),
1101 "postDoclavaCmds": postDoclavaCmds,
1102 },
1103 })
1104}
1105
1106func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1107 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1108 ctx.Build(pctx, android.BuildParams{
1109 Rule: apiCheck,
1110 Description: "Doclava Check API",
1111 Output: output,
1112 Inputs: nil,
1113 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1114 checkApiClasspath...),
1115 Args: map[string]string{
1116 "msg": msg,
1117 "classpath": checkApiClasspath.FormJavaClassPath(""),
1118 "opts": opts,
1119 "apiFile": apiFile.String(),
1120 "apiFileToCheck": d.apiFile.String(),
1121 "removedApiFile": removedApiFile.String(),
1122 "removedApiFileToCheck": d.removedApiFile.String(),
1123 },
1124 })
1125}
1126
1127func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1128 classpathArgs, opts string) {
1129 ctx.Build(pctx, android.BuildParams{
1130 Rule: dokka,
1131 Description: "Dokka",
1132 Output: d.Javadoc.stubsSrcJar,
1133 Inputs: d.Javadoc.srcFiles,
1134 Implicits: implicits,
1135 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001136 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1137 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1138 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001139 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1140 "classpathArgs": classpathArgs,
1141 "opts": opts,
1142 "docZip": d.Javadoc.docZip.String(),
1143 },
1144 })
1145}
1146
1147func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1148 deps := d.Javadoc.collectDeps(ctx)
1149
1150 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1151 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1152 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1153 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1154
1155 var implicits android.Paths
1156 implicits = append(implicits, d.Javadoc.srcJars...)
1157 implicits = append(implicits, d.Javadoc.argFiles...)
1158
1159 var implicitOutputs android.WritablePaths
1160 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1161 for _, o := range d.Javadoc.properties.Out {
1162 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1163 }
1164
1165 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1166 if err != nil {
1167 return
1168 }
1169
1170 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1171 if Bool(d.properties.Dokka_enabled) {
1172 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1173 } else {
1174 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1175 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1176 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1177 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1178 flags.postDoclavaCmds)
1179 }
1180
1181 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1182 !ctx.Config().IsPdkBuild() {
1183 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1184 "check_api.current.api_file")
1185 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1186 "check_api.current_removed_api_file")
1187
1188 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1189 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1190 fmt.Sprintf(`\n******************************\n`+
1191 `You have tried to change the API from what has been previously approved.\n\n`+
1192 `To make these errors go away, you have two choices:\n`+
1193 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1194 ` errors above.\n\n`+
1195 ` 2. You can update current.txt by executing the following command:\n`+
1196 ` make %s-update-current-api\n\n`+
1197 ` To submit the revised current.txt to the main Android repository,\n`+
1198 ` you will need approval.\n`+
1199 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1200 d.checkCurrentApiTimestamp)
1201
1202 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1203 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1204 d.updateCurrentApiTimestamp)
1205 }
1206
1207 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1208 !ctx.Config().IsPdkBuild() {
1209 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1210 "check_api.last_released.api_file")
1211 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1212 "check_api.last_released.removed_api_file")
1213
1214 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1215 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1216 `\n******************************\n`+
1217 `You have tried to change the API from what has been previously released in\n`+
1218 `an SDK. Please fix the errors listed above.\n`+
1219 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1220 d.checkLastReleasedApiTimestamp)
1221 }
1222}
1223
1224//
1225// Droidstubs
1226//
1227type Droidstubs struct {
1228 Javadoc
1229
Pete Gillin581d6082018-10-22 15:55:04 +01001230 properties DroidstubsProperties
1231 apiFile android.WritablePath
1232 apiXmlFile android.WritablePath
1233 lastReleasedApiXmlFile android.WritablePath
1234 dexApiFile android.WritablePath
1235 privateApiFile android.WritablePath
1236 privateDexApiFile android.WritablePath
1237 removedApiFile android.WritablePath
1238 removedDexApiFile android.WritablePath
1239 apiMappingFile android.WritablePath
1240 exactApiFile android.WritablePath
1241 proguardFile android.WritablePath
1242 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001243
1244 checkCurrentApiTimestamp android.WritablePath
1245 updateCurrentApiTimestamp android.WritablePath
1246 checkLastReleasedApiTimestamp android.WritablePath
1247
Pete Gillin581d6082018-10-22 15:55:04 +01001248 checkNullabilityWarningsTimestamp android.WritablePath
1249
Nan Zhang1598a9e2018-09-04 17:14:32 -07001250 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001251 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001252
1253 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001254
1255 jdiffDocZip android.WritablePath
1256 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001257}
1258
1259func DroidstubsFactory() android.Module {
1260 module := &Droidstubs{}
1261
1262 module.AddProperties(&module.properties,
1263 &module.Javadoc.properties)
1264
1265 InitDroiddocModule(module, android.HostAndDeviceSupported)
1266 return module
1267}
1268
1269func DroidstubsHostFactory() android.Module {
1270 module := &Droidstubs{}
1271
1272 module.AddProperties(&module.properties,
1273 &module.Javadoc.properties)
1274
1275 InitDroiddocModule(module, android.HostSupported)
1276 return module
1277}
1278
1279func (d *Droidstubs) ApiFilePath() android.Path {
1280 return d.apiFilePath
1281}
1282
1283func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1284 d.Javadoc.addDeps(ctx)
1285
1286 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1287 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1288 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1289 }
1290
1291 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1292 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1293 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1294 }
1295
1296 if String(d.properties.Previous_api) != "" {
1297 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1298 }
1299
1300 if len(d.properties.Merge_annotations_dirs) != 0 {
1301 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1302 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1303 }
1304 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001305
Pete Gillin77167902018-09-19 18:16:26 +01001306 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1307 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1308 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1309 }
1310 }
1311
Pete Gillinc382a562018-11-14 18:45:46 +00001312 if String(d.properties.Validate_nullability_from_list) != "" {
1313 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1314 }
Pete Gillin581d6082018-10-22 15:55:04 +01001315 if String(d.properties.Check_nullability_warnings) != "" {
1316 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1317 }
1318
Nan Zhang9c69a122018-08-22 10:22:08 -07001319 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1320 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1321 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1322 }
1323 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001324}
1325
1326func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1327 deps deps) (droiddocBuilderFlags, error) {
1328 var flags droiddocBuilderFlags
1329
1330 *implicits = append(*implicits, deps.bootClasspath...)
1331 *implicits = append(*implicits, deps.classpath...)
1332
1333 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1334 // since it doesn't support system modules yet.
1335 if len(deps.bootClasspath.Strings()) > 0 {
1336 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1337 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1338 }
1339 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1340
Sundong Ahn56dce442018-10-05 18:41:09 +09001341 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001342 return flags, nil
1343}
1344
1345func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1346 implicitOutputs *android.WritablePaths) string {
1347 var metalavaFlags string
1348 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1349 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1350 String(d.properties.Api_filename) != "" {
1351 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1352 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1353 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1354 d.apiFilePath = d.apiFile
1355 }
1356
1357 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1358 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1359 String(d.properties.Removed_api_filename) != "" {
1360 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1361 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1362 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1363 }
1364
1365 if String(d.properties.Private_api_filename) != "" {
1366 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1367 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1368 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1369 }
1370
1371 if String(d.properties.Dex_api_filename) != "" {
1372 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1373 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1374 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1375 }
1376
1377 if String(d.properties.Private_dex_api_filename) != "" {
1378 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1379 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1380 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1381 }
1382
1383 if String(d.properties.Removed_dex_api_filename) != "" {
1384 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1385 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1386 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1387 }
1388
1389 if String(d.properties.Exact_api_filename) != "" {
1390 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1391 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1392 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1393 }
1394
Nan Zhang9c69a122018-08-22 10:22:08 -07001395 if String(d.properties.Dex_mapping_filename) != "" {
1396 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1397 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1398 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1399 }
1400
Nan Zhang199645c2018-09-19 12:40:06 -07001401 if String(d.properties.Proguard_filename) != "" {
1402 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1403 metalavaFlags += " --proguard " + d.proguardFile.String()
1404 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1405 }
1406
Nan Zhang9c69a122018-08-22 10:22:08 -07001407 if Bool(d.properties.Write_sdk_values) {
1408 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1409 }
1410
Nan Zhang1598a9e2018-09-04 17:14:32 -07001411 if Bool(d.properties.Create_doc_stubs) {
1412 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1413 } else {
1414 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1415 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001416 return metalavaFlags
1417}
1418
1419func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001420 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1421 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001422 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001423 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001424 validatingNullability :=
1425 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1426 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001427 migratingNullability := String(d.properties.Previous_api) != ""
1428 if !(migratingNullability || validatingNullability) {
1429 ctx.PropertyErrorf("previous_api",
1430 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001431 }
Pete Gillina262c052018-09-14 14:25:48 +01001432 if migratingNullability {
1433 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1434 *implicits = append(*implicits, previousApi)
1435 flags += " --migrate-nullness " + previousApi.String()
1436 }
Pete Gillinc382a562018-11-14 18:45:46 +00001437 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1438 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1439 }
Pete Gillina262c052018-09-14 14:25:48 +01001440 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001441 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1442 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1443 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001444 }
Nan Zhanga40da042018-08-01 12:48:00 -07001445
1446 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1447 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1448
Nan Zhangf4936b02018-08-01 15:00:28 -07001449 flags += " --extract-annotations " + d.annotationsZip.String()
1450
Nan Zhang1598a9e2018-09-04 17:14:32 -07001451 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001452 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001453 "has to be non-empty if annotations was enabled!")
1454 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001455 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1456 if t, ok := m.(*ExportedDroiddocDir); ok {
1457 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001458 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001459 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001460 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001461 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1462 }
1463 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001464 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001465 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001466 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001467 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001468
Nan Zhangdee152b2018-12-26 16:06:37 -08001469 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001470}
1471
1472func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1473 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1474 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001475 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1476 if t, ok := m.(*ExportedDroiddocDir); ok {
1477 *implicits = append(*implicits, t.deps...)
1478 flags += " --merge-inclusion-annotations " + t.dir.String()
1479 } else {
1480 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1481 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1482 }
1483 })
Nan Zhanga40da042018-08-01 12:48:00 -07001484
1485 return flags
1486}
1487
Nan Zhang9c69a122018-08-22 10:22:08 -07001488func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1489 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1490 var flags string
1491 if Bool(d.properties.Api_levels_annotations_enabled) {
1492 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1493 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1494
1495 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1496 ctx.PropertyErrorf("api_levels_annotations_dirs",
1497 "has to be non-empty if api levels annotations was enabled!")
1498 }
1499
1500 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1501 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1502 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1503
1504 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1505 if t, ok := m.(*ExportedDroiddocDir); ok {
1506 var androidJars android.Paths
1507 for _, dep := range t.deps {
1508 if strings.HasSuffix(dep.String(), "android.jar") {
1509 androidJars = append(androidJars, dep)
1510 }
1511 }
1512 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001513 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001514 } else {
1515 ctx.PropertyErrorf("api_levels_annotations_dirs",
1516 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1517 }
1518 })
1519
1520 }
1521
1522 return flags
1523}
1524
Nan Zhang71bbe632018-09-17 14:32:21 -07001525func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1526 implicitOutputs *android.WritablePaths) string {
1527 var flags string
1528 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1529 if d.apiFile.String() == "" {
1530 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1531 }
1532
1533 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1534 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1535
1536 flags = " --api-xml " + d.apiXmlFile.String()
1537
1538 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1539 ctx.PropertyErrorf("check_api.last_released.api_file",
1540 "has to be non-empty if jdiff was enabled!")
1541 }
1542 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1543 "check_api.last_released.api_file")
1544 *implicits = append(*implicits, lastReleasedApi)
1545
1546 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1547 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1548
1549 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1550 d.lastReleasedApiXmlFile.String()
1551 }
1552
1553 return flags
1554}
1555
Nan Zhang1598a9e2018-09-04 17:14:32 -07001556func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1557 implicitOutputs android.WritablePaths, javaVersion,
1558 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001559
Nan Zhang86d2d552018-08-09 15:33:27 -07001560 ctx.Build(pctx, android.BuildParams{
1561 Rule: metalava,
1562 Description: "Metalava",
1563 Output: d.Javadoc.stubsSrcJar,
1564 Inputs: d.Javadoc.srcFiles,
1565 Implicits: implicits,
1566 ImplicitOutputs: implicitOutputs,
1567 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001568 "outDir": android.PathForModuleOut(ctx, "out").String(),
1569 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1570 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1571 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001572 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001573 "bootclasspathArgs": bootclasspathArgs,
1574 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001575 "sourcepathArgs": sourcepathArgs,
1576 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001577 },
1578 })
1579}
1580
Nan Zhang1598a9e2018-09-04 17:14:32 -07001581func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1582 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001583 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001584 output android.WritablePath) {
1585 ctx.Build(pctx, android.BuildParams{
1586 Rule: metalavaApiCheck,
1587 Description: "Metalava Check API",
1588 Output: output,
1589 Inputs: d.Javadoc.srcFiles,
1590 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1591 implicits...),
1592 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001593 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001594 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1595 "javaVersion": javaVersion,
1596 "bootclasspathArgs": bootclasspathArgs,
1597 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001598 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001599 "opts": opts,
1600 "msg": msg,
1601 },
1602 })
1603}
1604
Nan Zhang71bbe632018-09-17 14:32:21 -07001605func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1606 implicitOutputs android.WritablePaths,
1607 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1608 ctx.Build(pctx, android.BuildParams{
1609 Rule: javadoc,
1610 Description: "Jdiff",
1611 Output: d.jdiffStubsSrcJar,
1612 Inputs: d.Javadoc.srcFiles,
1613 Implicits: implicits,
1614 ImplicitOutputs: implicitOutputs,
1615 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001616 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1617 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1618 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001619 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1620 "opts": opts,
1621 "bootclasspathArgs": bootclasspathArgs,
1622 "classpathArgs": classpathArgs,
1623 "sourcepathArgs": sourcepathArgs,
1624 "docZip": d.jdiffDocZip.String(),
1625 },
1626 })
1627}
1628
Nan Zhang1598a9e2018-09-04 17:14:32 -07001629func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001630 deps := d.Javadoc.collectDeps(ctx)
1631
1632 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001633
Nan Zhanga40da042018-08-01 12:48:00 -07001634 var implicits android.Paths
1635 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001636 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001637
1638 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001639 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001640 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1641 }
1642
1643 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001644 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001645 jdiffImplicits := implicits
1646
Nan Zhanga40da042018-08-01 12:48:00 -07001647 if err != nil {
1648 return
1649 }
1650
Nan Zhang1598a9e2018-09-04 17:14:32 -07001651 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001652 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1653 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001654 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001655 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001656 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1657
Nan Zhang1598a9e2018-09-04 17:14:32 -07001658 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1659 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1660 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1661 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1662 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001663 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001664 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1665 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001666 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001667 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001668
Nan Zhang1598a9e2018-09-04 17:14:32 -07001669 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1670 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001671 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1672 "check_api.current.api_file")
1673 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1674 "check_api.current_removed_api_file")
1675
Nan Zhang2760dfc2018-08-24 17:32:54 +00001676 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001677 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1678 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001679 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001680
Nan Zhang1598a9e2018-09-04 17:14:32 -07001681 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001682 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001683 fmt.Sprintf(`\n******************************\n`+
1684 `You have tried to change the API from what has been previously approved.\n\n`+
1685 `To make these errors go away, you have two choices:\n`+
1686 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1687 ` errors above.\n\n`+
1688 ` 2. You can update current.txt by executing the following command:\n`+
1689 ` make %s-update-current-api\n\n`+
1690 ` To submit the revised current.txt to the main Android repository,\n`+
1691 ` you will need approval.\n`+
1692 `******************************\n`, ctx.ModuleName()),
1693 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001694
1695 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001696 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1697 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001698 }
Nan Zhanga40da042018-08-01 12:48:00 -07001699
Nan Zhang1598a9e2018-09-04 17:14:32 -07001700 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1701 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001702 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1703 "check_api.last_released.api_file")
1704 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1705 "check_api.last_released.removed_api_file")
1706
Nan Zhang2760dfc2018-08-24 17:32:54 +00001707 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001708 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1709 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001710 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001711
Nan Zhang1598a9e2018-09-04 17:14:32 -07001712 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001713 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001714 `\n******************************\n`+
1715 `You have tried to change the API from what has been previously released in\n`+
1716 `an SDK. Please fix the errors listed above.\n`+
1717 `******************************\n`,
1718 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001719 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001720
Pete Gillin581d6082018-10-22 15:55:04 +01001721 if String(d.properties.Check_nullability_warnings) != "" {
1722 if d.nullabilityWarningsFile == nil {
1723 ctx.PropertyErrorf("check_nullability_warnings",
1724 "Cannot specify check_nullability_warnings unless validating nullability")
1725 }
1726 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1727 "check_nullability_warnings")
1728 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1729 msg := fmt.Sprintf(`\n******************************\n`+
1730 `The warnings encountered during nullability annotation validation did\n`+
1731 `not match the checked in file of expected warnings. The diffs are shown\n`+
1732 `above. You have two options:\n`+
1733 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1734 ` 2. Update the file of expected warnings by running:\n`+
1735 ` cp %s %s\n`+
1736 ` and submitting the updated file as part of your change.`,
1737 d.nullabilityWarningsFile, checkNullabilityWarnings)
1738 ctx.Build(pctx, android.BuildParams{
1739 Rule: nullabilityWarningsCheck,
1740 Description: "Nullability Warnings Check",
1741 Output: d.checkNullabilityWarningsTimestamp,
1742 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1743 Args: map[string]string{
1744 "expected": checkNullabilityWarnings.String(),
1745 "actual": d.nullabilityWarningsFile.String(),
1746 "msg": msg,
1747 },
1748 })
1749 }
1750
Nan Zhang71bbe632018-09-17 14:32:21 -07001751 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1752
Nan Zhang86b06202018-09-21 17:09:21 -07001753 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1754 // since there's cron job downstream that fetch this .zip file periodically.
1755 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001756 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1757 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1758
1759 var jdiffImplicitOutputs android.WritablePaths
1760 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1761
1762 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1763 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1764
1765 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1766 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1767 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1768 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1769 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1770 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1771
1772 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1773 flags.sourcepathArgs, opts)
1774 }
Nan Zhang581fd212018-01-10 16:06:12 -08001775}
Dan Willemsencc090972018-02-26 14:33:31 -08001776
Nan Zhanga40da042018-08-01 12:48:00 -07001777//
Nan Zhangf4936b02018-08-01 15:00:28 -07001778// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001779//
Dan Willemsencc090972018-02-26 14:33:31 -08001780var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001781var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001782var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001783var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001784
Nan Zhangf4936b02018-08-01 15:00:28 -07001785type ExportedDroiddocDirProperties struct {
1786 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001787 Path *string
1788}
1789
Nan Zhangf4936b02018-08-01 15:00:28 -07001790type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001791 android.ModuleBase
1792
Nan Zhangf4936b02018-08-01 15:00:28 -07001793 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001794
1795 deps android.Paths
1796 dir android.Path
1797}
1798
Nan Zhangf4936b02018-08-01 15:00:28 -07001799func ExportedDroiddocDirFactory() android.Module {
1800 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001801 module.AddProperties(&module.properties)
1802 android.InitAndroidModule(module)
1803 return module
1804}
1805
Nan Zhangf4936b02018-08-01 15:00:28 -07001806func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001807
Nan Zhangf4936b02018-08-01 15:00:28 -07001808func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001809 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1810 d.dir = path
1811 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1812}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001813
1814//
1815// Defaults
1816//
1817type DocDefaults struct {
1818 android.ModuleBase
1819 android.DefaultsModuleBase
1820}
1821
1822func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1823}
1824
Nan Zhangb2b33de2018-02-23 11:18:47 -08001825func DocDefaultsFactory() android.Module {
1826 module := &DocDefaults{}
1827
1828 module.AddProperties(
1829 &JavadocProperties{},
1830 &DroiddocProperties{},
1831 )
1832
1833 android.InitDefaultsModule(module)
1834
1835 return module
1836}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001837
1838func StubsDefaultsFactory() android.Module {
1839 module := &DocDefaults{}
1840
1841 module.AddProperties(
1842 &JavadocProperties{},
1843 &DroidstubsProperties{},
1844 )
1845
1846 android.InitDefaultsModule(module)
1847
1848 return module
1849}