blob: fd7e2a48ad33becad99a7e59ee4b21ee25538794 [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.
Colin Cross27b922f2019-03-04 22:35:41 -0800160 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -0800161
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800169 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -0800170
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800208 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700209
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).
Colin Cross27b922f2019-03-04 22:35:41 -0800223 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700224
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).
Colin Cross27b922f2019-03-04 22:35:41 -0800228 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700229
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800246 Proofread_file *string `android:"path"`
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800250 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800251
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800263 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700264
265 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800266 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700267
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.
Colin Cross27b922f2019-03-04 22:35:41 -0800270 Knowntags []string `android:"path"`
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
Inseob Kim38449af2019-02-28 14:24:05 +0900310
311 // do not perform API check against Last_released, in the case that both two specified API
312 // files by Last_released are modules which don't exist.
313 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700314 }
Nan Zhang79614d12018-04-19 18:03:39 -0700315
Nan Zhang1598a9e2018-09-04 17:14:32 -0700316 // if set to true, generate docs through Dokka instead of Doclava.
317 Dokka_enabled *bool
318}
319
320type DroidstubsProperties struct {
321 // the tag name used to distinguish if the API files belong to public/system/test.
322 Api_tag_name *string
323
Nan Zhang199645c2018-09-19 12:40:06 -0700324 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700325 Api_filename *string
326
Nan Zhang199645c2018-09-19 12:40:06 -0700327 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700328 Dex_api_filename *string
329
Nan Zhang199645c2018-09-19 12:40:06 -0700330 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700331 Private_api_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Private_dex_api_filename *string
335
Nan Zhang199645c2018-09-19 12:40:06 -0700336 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700337 Removed_api_filename *string
338
Nan Zhang199645c2018-09-19 12:40:06 -0700339 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700340 Removed_dex_api_filename *string
341
Nan Zhang9c69a122018-08-22 10:22:08 -0700342 // mapping of dex signatures to source file and line number. This is a temporary property and
343 // will be deleted; you probably shouldn't be using it.
344 Dex_mapping_filename *string
345
Nan Zhang199645c2018-09-19 12:40:06 -0700346 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700347 Exact_api_filename *string
348
Nan Zhang199645c2018-09-19 12:40:06 -0700349 // the generated proguard filename by Metalava.
350 Proguard_filename *string
351
Nan Zhang1598a9e2018-09-04 17:14:32 -0700352 Check_api struct {
353 Last_released ApiToCheck
354
355 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900356
357 // do not perform API check against Last_released, in the case that both two specified API
358 // files by Last_released are modules which don't exist.
359 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700360 }
Nan Zhang79614d12018-04-19 18:03:39 -0700361
362 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800363 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700364
365 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700366 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700367
Pete Gillin77167902018-09-19 18:16:26 +0100368 // 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 -0700369 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700370
Pete Gillin77167902018-09-19 18:16:26 +0100371 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
372 Merge_inclusion_annotations_dirs []string
373
Pete Gillinc382a562018-11-14 18:45:46 +0000374 // a file containing a list of classes to do nullability validation for.
375 Validate_nullability_from_list *string
376
Pete Gillin581d6082018-10-22 15:55:04 +0100377 // a file containing expected warnings produced by validation of nullability annotations.
378 Check_nullability_warnings *string
379
Nan Zhang1598a9e2018-09-04 17:14:32 -0700380 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
381 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700382
383 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
384 Api_levels_annotations_enabled *bool
385
386 // the dirs which Metalava extracts API levels annotations from.
387 Api_levels_annotations_dirs []string
388
389 // if set to true, collect the values used by the Dev tools and
390 // write them in files packaged with the SDK. Defaults to false.
391 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700392
393 // If set to true, .xml based public API file will be also generated, and
394 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
395 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800396}
397
Nan Zhanga40da042018-08-01 12:48:00 -0700398//
399// Common flags passed down to build rule
400//
401type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700402 bootClasspathArgs string
403 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700404 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700405 dokkaClasspathArgs string
406 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700407 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700408
Nan Zhanga40da042018-08-01 12:48:00 -0700409 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700410 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700411 postDoclavaCmds string
412
Nan Zhang9c69a122018-08-22 10:22:08 -0700413 metalavaStubsFlags string
414 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800415 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100416 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700417 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700418
Nan Zhang71bbe632018-09-17 14:32:21 -0700419 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700420}
421
422func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
423 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
424 android.InitDefaultableModule(module)
425}
426
Nan Zhang1598a9e2018-09-04 17:14:32 -0700427func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
428 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
429 return true
430 } else if String(apiToCheck.Api_file) != "" {
431 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
432 } else if String(apiToCheck.Removed_api_file) != "" {
433 panic("for " + apiVersionTag + " api_file has to be non-empty!")
434 }
435
436 return false
437}
438
Inseob Kim38449af2019-02-28 14:24:05 +0900439func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
440 api_file := String(apiToCheck.Api_file)
441 removed_api_file := String(apiToCheck.Removed_api_file)
442
443 api_module := android.SrcIsModule(api_file)
444 removed_api_module := android.SrcIsModule(removed_api_file)
445
446 if api_module == "" || removed_api_module == "" {
447 return
448 }
449
450 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
451 return
452 }
453
454 apiToCheck.Api_file = nil
455 apiToCheck.Removed_api_file = nil
456}
457
Nan Zhang1598a9e2018-09-04 17:14:32 -0700458type ApiFilePath interface {
459 ApiFilePath() android.Path
460}
461
462func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
463 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
464 ctx.Build(pctx, android.BuildParams{
465 Rule: updateApi,
466 Description: "Update API",
467 Output: output,
468 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
469 destApiFile, destRemovedApiFile),
470 Args: map[string]string{
471 "destApiFile": destApiFile.String(),
472 "srcApiFile": srcApiFile.String(),
473 "destRemovedApiFile": destRemovedApiFile.String(),
474 "srcRemovedApiFile": srcRemovedApiFile.String(),
475 },
476 })
477}
478
Nan Zhanga40da042018-08-01 12:48:00 -0700479//
480// Javadoc
481//
Nan Zhang581fd212018-01-10 16:06:12 -0800482type Javadoc struct {
483 android.ModuleBase
484 android.DefaultableModuleBase
485
486 properties JavadocProperties
487
488 srcJars android.Paths
489 srcFiles android.Paths
490 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700491 argFiles android.Paths
492
493 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800494
Nan Zhangccff0f72018-03-08 17:26:16 -0800495 docZip android.WritablePath
496 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800497}
498
Nan Zhangb2b33de2018-02-23 11:18:47 -0800499func (j *Javadoc) Srcs() android.Paths {
500 return android.Paths{j.stubsSrcJar}
501}
502
Nan Zhang581fd212018-01-10 16:06:12 -0800503func JavadocFactory() android.Module {
504 module := &Javadoc{}
505
506 module.AddProperties(&module.properties)
507
508 InitDroiddocModule(module, android.HostAndDeviceSupported)
509 return module
510}
511
512func JavadocHostFactory() android.Module {
513 module := &Javadoc{}
514
515 module.AddProperties(&module.properties)
516
517 InitDroiddocModule(module, android.HostSupported)
518 return module
519}
520
Nan Zhanga40da042018-08-01 12:48:00 -0700521var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800522
Colin Cross83bb3162018-06-25 15:48:06 -0700523func (j *Javadoc) sdkVersion() string {
524 return String(j.properties.Sdk_version)
525}
526
527func (j *Javadoc) minSdkVersion() string {
528 return j.sdkVersion()
529}
530
Dan Willemsen419290a2018-10-31 15:28:47 -0700531func (j *Javadoc) targetSdkVersion() string {
532 return j.sdkVersion()
533}
534
Nan Zhang581fd212018-01-10 16:06:12 -0800535func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
536 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700537 if !Bool(j.properties.No_standard_libs) {
538 sdkDep := decodeSdkDep(ctx, sdkContext(j))
539 if sdkDep.useDefaultLibs {
540 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
541 if ctx.Config().TargetOpenJDK9() {
542 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
543 }
544 if !Bool(j.properties.No_framework_libs) {
545 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
546 }
547 } else if sdkDep.useModule {
548 if ctx.Config().TargetOpenJDK9() {
549 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
550 }
551 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700552 }
Nan Zhang581fd212018-01-10 16:06:12 -0800553 }
554 }
555
Colin Cross42d48b72018-08-29 14:10:52 -0700556 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700557 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700558 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700559 }
Nan Zhang581fd212018-01-10 16:06:12 -0800560}
561
Nan Zhangb2b33de2018-02-23 11:18:47 -0800562func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
563 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
564 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900565 // convert foo.bar.baz to foo/bar/baz
566 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
567 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800568 if _, found := whitelistPathPrefixes[prefix]; !found {
569 whitelistPathPrefixes[prefix] = true
570 }
571 }
572 }
573}
574
Nan Zhanga40da042018-08-01 12:48:00 -0700575func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
576 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900577
Colin Cross3047fa22019-04-18 10:56:44 -0700578 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900579
580 return flags
581}
582
583func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700584 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900585
586 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
587 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
588
589 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700590 var deps android.Paths
591
Jiyong Park1e440682018-05-23 18:42:04 +0900592 if aidlPreprocess.Valid() {
593 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700594 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900595 } else {
596 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
597 }
598
599 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
600 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
601 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
602 flags = append(flags, "-I"+src.String())
603 }
604
Colin Cross3047fa22019-04-18 10:56:44 -0700605 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900606}
607
608func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700609 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900610
611 outSrcFiles := make(android.Paths, 0, len(srcFiles))
612
613 for _, srcFile := range srcFiles {
614 switch srcFile.Ext() {
615 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700616 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Jiyong Park1e440682018-05-23 18:42:04 +0900617 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900618 case ".sysprop":
619 javaFile := genSysprop(ctx, srcFile)
620 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900621 default:
622 outSrcFiles = append(outSrcFiles, srcFile)
623 }
624 }
625
626 return outSrcFiles
627}
628
Nan Zhang581fd212018-01-10 16:06:12 -0800629func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
630 var deps deps
631
Colin Cross83bb3162018-06-25 15:48:06 -0700632 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800633 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700634 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800635 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700636 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800637 }
638
639 ctx.VisitDirectDeps(func(module android.Module) {
640 otherName := ctx.OtherModuleName(module)
641 tag := ctx.OtherModuleDependencyTag(module)
642
Colin Cross2d24c1b2018-05-23 10:59:18 -0700643 switch tag {
644 case bootClasspathTag:
645 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800646 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700647 } else {
648 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
649 }
650 case libTag:
651 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800652 case SdkLibraryDependency:
653 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700654 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900655 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700656 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800657 checkProducesJars(ctx, dep)
658 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800659 default:
660 ctx.ModuleErrorf("depends on non-java module %q", otherName)
661 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700662 case srcsLibTag:
663 switch dep := module.(type) {
664 case Dependency:
665 srcs := dep.(SrcDependency).CompiledSrcs()
666 whitelistPathPrefixes := make(map[string]bool)
667 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
668 for _, src := range srcs {
669 if _, ok := src.(android.WritablePath); ok { // generated sources
670 deps.srcs = append(deps.srcs, src)
671 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700672 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700673 if strings.HasPrefix(src.Rel(), k) {
674 deps.srcs = append(deps.srcs, src)
675 break
676 }
677 }
678 }
679 }
680 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
681 default:
682 ctx.ModuleErrorf("depends on non-java module %q", otherName)
683 }
Nan Zhang357466b2018-04-17 17:38:36 -0700684 case systemModulesTag:
685 if deps.systemModules != nil {
686 panic("Found two system module dependencies")
687 }
688 sm := module.(*SystemModules)
689 if sm.outputFile == nil {
690 panic("Missing directory for system module dependency")
691 }
692 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800693 }
694 })
695 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
696 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800697 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700698 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900699 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800700
701 // srcs may depend on some genrule output.
702 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800703 j.srcJars = append(j.srcJars, deps.srcJars...)
704
Nan Zhang581fd212018-01-10 16:06:12 -0800705 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800706 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800707
708 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800709 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800710
Nan Zhang9c69a122018-08-22 10:22:08 -0700711 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800712 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
713 }
714 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800715
Colin Cross8a497952019-03-05 22:25:09 -0800716 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000717 argFilesMap := map[string]string{}
718 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700719
Paul Duffin99e4a502019-02-11 15:38:42 +0000720 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800721 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000722 if _, exists := argFilesMap[label]; !exists {
723 argFilesMap[label] = strings.Join(paths.Strings(), " ")
724 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700725 } else {
726 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000727 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700728 }
729 }
730
731 var err error
732 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
733 if strings.HasPrefix(name, "location ") {
734 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000735 if paths, ok := argFilesMap[label]; ok {
736 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700737 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000738 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
739 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700740 }
741 } else if name == "genDir" {
742 return android.PathForModuleGen(ctx).String(), nil
743 }
744 return "", fmt.Errorf("unknown variable '$(%s)'", name)
745 })
746
747 if err != nil {
748 ctx.PropertyErrorf("args", "%s", err.Error())
749 }
750
Nan Zhang581fd212018-01-10 16:06:12 -0800751 return deps
752}
753
754func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
755 j.addDeps(ctx)
756}
757
758func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
759 deps := j.collectDeps(ctx)
760
761 var implicits android.Paths
762 implicits = append(implicits, deps.bootClasspath...)
763 implicits = append(implicits, deps.classpath...)
764
Nan Zhang1598a9e2018-09-04 17:14:32 -0700765 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700766
Colin Cross83bb3162018-06-25 15:48:06 -0700767 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700768 if len(deps.bootClasspath) > 0 {
769 var systemModules classpath
770 if deps.systemModules != nil {
771 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800772 }
Colin Cross997262f2018-06-19 22:49:39 -0700773 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
774 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800775 }
776 if len(deps.classpath.Strings()) > 0 {
777 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
778 }
779
780 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700781 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800782
Nan Zhangaf322cc2018-06-19 15:15:38 -0700783 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800784
Nan Zhang1598a9e2018-09-04 17:14:32 -0700785 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
786
Nan Zhang581fd212018-01-10 16:06:12 -0800787 ctx.Build(pctx, android.BuildParams{
788 Rule: javadoc,
789 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800790 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800791 ImplicitOutput: j.docZip,
792 Inputs: j.srcFiles,
793 Implicits: implicits,
794 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700795 "outDir": android.PathForModuleOut(ctx, "out").String(),
796 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
797 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800798 "srcJars": strings.Join(j.srcJars.Strings(), " "),
799 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700800 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800801 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700802 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800803 "docZip": j.docZip.String(),
804 },
805 })
806}
807
Nan Zhanga40da042018-08-01 12:48:00 -0700808//
809// Droiddoc
810//
811type Droiddoc struct {
812 Javadoc
813
814 properties DroiddocProperties
815 apiFile android.WritablePath
816 dexApiFile android.WritablePath
817 privateApiFile android.WritablePath
818 privateDexApiFile android.WritablePath
819 removedApiFile android.WritablePath
820 removedDexApiFile android.WritablePath
821 exactApiFile android.WritablePath
822 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700823 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700824
825 checkCurrentApiTimestamp android.WritablePath
826 updateCurrentApiTimestamp android.WritablePath
827 checkLastReleasedApiTimestamp android.WritablePath
828
Nan Zhanga40da042018-08-01 12:48:00 -0700829 apiFilePath android.Path
830}
831
Nan Zhanga40da042018-08-01 12:48:00 -0700832func DroiddocFactory() android.Module {
833 module := &Droiddoc{}
834
835 module.AddProperties(&module.properties,
836 &module.Javadoc.properties)
837
838 InitDroiddocModule(module, android.HostAndDeviceSupported)
839 return module
840}
841
842func DroiddocHostFactory() android.Module {
843 module := &Droiddoc{}
844
845 module.AddProperties(&module.properties,
846 &module.Javadoc.properties)
847
848 InitDroiddocModule(module, android.HostSupported)
849 return module
850}
851
852func (d *Droiddoc) ApiFilePath() android.Path {
853 return d.apiFilePath
854}
855
Nan Zhang581fd212018-01-10 16:06:12 -0800856func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
857 d.Javadoc.addDeps(ctx)
858
Inseob Kim38449af2019-02-28 14:24:05 +0900859 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
860 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
861 }
862
Nan Zhang79614d12018-04-19 18:03:39 -0700863 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800864 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
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 {
Colin Cross07e51612019-03-05 12:46:40 -0800936 htmlDir := d.properties.Html_dirs[0]
Colin Cross8a497952019-03-05 22:25:09 -0800937 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800938 args = args + " -htmldir " + htmlDir
Nan Zhanga40da042018-08-01 12:48:00 -0700939 }
940
941 if len(d.properties.Html_dirs) > 1 {
Colin Cross07e51612019-03-05 12:46:40 -0800942 htmlDir2 := d.properties.Html_dirs[1]
Colin Cross8a497952019-03-05 22:25:09 -0800943 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800944 args = args + " -htmldir2 " + htmlDir2
Nan Zhanga40da042018-08-01 12:48:00 -0700945 }
946
947 if len(d.properties.Html_dirs) > 2 {
948 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
949 }
950
Colin Cross8a497952019-03-05 22:25:09 -0800951 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Nan Zhanga40da042018-08-01 12:48:00 -0700952 *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
Inseob Kim38449af2019-02-28 14:24:05 +09001286 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1287 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1288 }
1289
Nan Zhang1598a9e2018-09-04 17:14:32 -07001290 if len(d.properties.Merge_annotations_dirs) != 0 {
1291 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1292 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1293 }
1294 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001295
Pete Gillin77167902018-09-19 18:16:26 +01001296 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1297 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1298 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1299 }
1300 }
1301
Nan Zhang9c69a122018-08-22 10:22:08 -07001302 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1303 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1304 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1305 }
1306 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001307}
1308
1309func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1310 deps deps) (droiddocBuilderFlags, error) {
1311 var flags droiddocBuilderFlags
1312
1313 *implicits = append(*implicits, deps.bootClasspath...)
1314 *implicits = append(*implicits, deps.classpath...)
1315
1316 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1317 // since it doesn't support system modules yet.
1318 if len(deps.bootClasspath.Strings()) > 0 {
1319 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1320 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1321 }
1322 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1323
Sundong Ahn56dce442018-10-05 18:41:09 +09001324 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001325 return flags, nil
1326}
1327
1328func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1329 implicitOutputs *android.WritablePaths) string {
1330 var metalavaFlags string
1331 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1332 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1333 String(d.properties.Api_filename) != "" {
1334 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1335 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1336 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1337 d.apiFilePath = d.apiFile
1338 }
1339
1340 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1341 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1342 String(d.properties.Removed_api_filename) != "" {
1343 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1344 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1345 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1346 }
1347
1348 if String(d.properties.Private_api_filename) != "" {
1349 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1350 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1351 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1352 }
1353
1354 if String(d.properties.Dex_api_filename) != "" {
1355 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1356 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1357 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1358 }
1359
1360 if String(d.properties.Private_dex_api_filename) != "" {
1361 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1362 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1363 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1364 }
1365
1366 if String(d.properties.Removed_dex_api_filename) != "" {
1367 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1368 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1369 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1370 }
1371
1372 if String(d.properties.Exact_api_filename) != "" {
1373 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1374 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1375 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1376 }
1377
Nan Zhang9c69a122018-08-22 10:22:08 -07001378 if String(d.properties.Dex_mapping_filename) != "" {
1379 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1380 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1381 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1382 }
1383
Nan Zhang199645c2018-09-19 12:40:06 -07001384 if String(d.properties.Proguard_filename) != "" {
1385 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1386 metalavaFlags += " --proguard " + d.proguardFile.String()
1387 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1388 }
1389
Nan Zhang9c69a122018-08-22 10:22:08 -07001390 if Bool(d.properties.Write_sdk_values) {
1391 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1392 }
1393
Nan Zhang1598a9e2018-09-04 17:14:32 -07001394 if Bool(d.properties.Create_doc_stubs) {
1395 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1396 } else {
1397 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1398 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001399 return metalavaFlags
1400}
1401
1402func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001403 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1404 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001405 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001406 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001407 validatingNullability :=
1408 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1409 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001410 migratingNullability := String(d.properties.Previous_api) != ""
1411 if !(migratingNullability || validatingNullability) {
1412 ctx.PropertyErrorf("previous_api",
1413 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001414 }
Pete Gillina262c052018-09-14 14:25:48 +01001415 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001416 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Pete Gillina262c052018-09-14 14:25:48 +01001417 *implicits = append(*implicits, previousApi)
1418 flags += " --migrate-nullness " + previousApi.String()
1419 }
Pete Gillinc382a562018-11-14 18:45:46 +00001420 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross8a497952019-03-05 22:25:09 -08001421 flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String()
Pete Gillinc382a562018-11-14 18:45:46 +00001422 }
Pete Gillina262c052018-09-14 14:25:48 +01001423 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001424 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1425 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1426 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001427 }
Nan Zhanga40da042018-08-01 12:48:00 -07001428
1429 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1430 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1431
Nan Zhangf4936b02018-08-01 15:00:28 -07001432 flags += " --extract-annotations " + d.annotationsZip.String()
1433
Nan Zhang1598a9e2018-09-04 17:14:32 -07001434 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001435 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001436 "has to be non-empty if annotations was enabled!")
1437 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001438 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1439 if t, ok := m.(*ExportedDroiddocDir); ok {
1440 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001441 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001442 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001443 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001444 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1445 }
1446 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001447 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001448 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001449 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001450 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001451
Nan Zhangdee152b2018-12-26 16:06:37 -08001452 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001453}
1454
1455func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1456 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1457 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001458 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1459 if t, ok := m.(*ExportedDroiddocDir); ok {
1460 *implicits = append(*implicits, t.deps...)
1461 flags += " --merge-inclusion-annotations " + t.dir.String()
1462 } else {
1463 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1464 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1465 }
1466 })
Nan Zhanga40da042018-08-01 12:48:00 -07001467
1468 return flags
1469}
1470
Nan Zhang9c69a122018-08-22 10:22:08 -07001471func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1472 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1473 var flags string
1474 if Bool(d.properties.Api_levels_annotations_enabled) {
1475 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1476 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1477
1478 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1479 ctx.PropertyErrorf("api_levels_annotations_dirs",
1480 "has to be non-empty if api levels annotations was enabled!")
1481 }
1482
1483 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1484 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1485 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1486
1487 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1488 if t, ok := m.(*ExportedDroiddocDir); ok {
1489 var androidJars android.Paths
1490 for _, dep := range t.deps {
1491 if strings.HasSuffix(dep.String(), "android.jar") {
1492 androidJars = append(androidJars, dep)
1493 }
1494 }
1495 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001496 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001497 } else {
1498 ctx.PropertyErrorf("api_levels_annotations_dirs",
1499 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1500 }
1501 })
1502
1503 }
1504
1505 return flags
1506}
1507
Nan Zhang71bbe632018-09-17 14:32:21 -07001508func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1509 implicitOutputs *android.WritablePaths) string {
1510 var flags string
1511 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1512 if d.apiFile.String() == "" {
1513 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1514 }
1515
1516 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1517 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1518
1519 flags = " --api-xml " + d.apiXmlFile.String()
1520
1521 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1522 ctx.PropertyErrorf("check_api.last_released.api_file",
1523 "has to be non-empty if jdiff was enabled!")
1524 }
1525 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1526 "check_api.last_released.api_file")
1527 *implicits = append(*implicits, lastReleasedApi)
1528
1529 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1530 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1531
1532 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1533 d.lastReleasedApiXmlFile.String()
1534 }
1535
1536 return flags
1537}
1538
Nan Zhang1598a9e2018-09-04 17:14:32 -07001539func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1540 implicitOutputs android.WritablePaths, javaVersion,
1541 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001542
Nan Zhang86d2d552018-08-09 15:33:27 -07001543 ctx.Build(pctx, android.BuildParams{
1544 Rule: metalava,
1545 Description: "Metalava",
1546 Output: d.Javadoc.stubsSrcJar,
1547 Inputs: d.Javadoc.srcFiles,
1548 Implicits: implicits,
1549 ImplicitOutputs: implicitOutputs,
1550 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001551 "outDir": android.PathForModuleOut(ctx, "out").String(),
1552 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1553 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1554 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001555 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001556 "bootclasspathArgs": bootclasspathArgs,
1557 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001558 "sourcepathArgs": sourcepathArgs,
1559 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001560 },
1561 })
1562}
1563
Nan Zhang1598a9e2018-09-04 17:14:32 -07001564func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1565 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001566 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001567 output android.WritablePath) {
1568 ctx.Build(pctx, android.BuildParams{
1569 Rule: metalavaApiCheck,
1570 Description: "Metalava Check API",
1571 Output: output,
1572 Inputs: d.Javadoc.srcFiles,
1573 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1574 implicits...),
1575 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001576 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001577 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1578 "javaVersion": javaVersion,
1579 "bootclasspathArgs": bootclasspathArgs,
1580 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001581 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001582 "opts": opts,
1583 "msg": msg,
1584 },
1585 })
1586}
1587
Nan Zhang71bbe632018-09-17 14:32:21 -07001588func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1589 implicitOutputs android.WritablePaths,
1590 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1591 ctx.Build(pctx, android.BuildParams{
1592 Rule: javadoc,
1593 Description: "Jdiff",
1594 Output: d.jdiffStubsSrcJar,
1595 Inputs: d.Javadoc.srcFiles,
1596 Implicits: implicits,
1597 ImplicitOutputs: implicitOutputs,
1598 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001599 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1600 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1601 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001602 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1603 "opts": opts,
1604 "bootclasspathArgs": bootclasspathArgs,
1605 "classpathArgs": classpathArgs,
1606 "sourcepathArgs": sourcepathArgs,
1607 "docZip": d.jdiffDocZip.String(),
1608 },
1609 })
1610}
1611
Nan Zhang1598a9e2018-09-04 17:14:32 -07001612func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001613 deps := d.Javadoc.collectDeps(ctx)
1614
1615 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001616
Nan Zhanga40da042018-08-01 12:48:00 -07001617 var implicits android.Paths
1618 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001619 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001620
1621 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001622 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001623 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1624 }
1625
1626 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001627 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001628 jdiffImplicits := implicits
1629
Nan Zhanga40da042018-08-01 12:48:00 -07001630 if err != nil {
1631 return
1632 }
1633
Nan Zhang1598a9e2018-09-04 17:14:32 -07001634 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001635 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1636 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001637 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001638 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001639 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1640
Nan Zhang1598a9e2018-09-04 17:14:32 -07001641 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1642 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1643 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1644 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1645 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001646 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001647 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1648 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001649 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001650 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001651
Nan Zhang1598a9e2018-09-04 17:14:32 -07001652 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1653 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001654 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1655 "check_api.current.api_file")
1656 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1657 "check_api.current_removed_api_file")
1658
Nan Zhang2760dfc2018-08-24 17:32:54 +00001659 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001660 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1661 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001662 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001663
Nan Zhang1598a9e2018-09-04 17:14:32 -07001664 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001665 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001666 fmt.Sprintf(`\n******************************\n`+
1667 `You have tried to change the API from what has been previously approved.\n\n`+
1668 `To make these errors go away, you have two choices:\n`+
1669 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1670 ` errors above.\n\n`+
1671 ` 2. You can update current.txt by executing the following command:\n`+
1672 ` make %s-update-current-api\n\n`+
1673 ` To submit the revised current.txt to the main Android repository,\n`+
1674 ` you will need approval.\n`+
1675 `******************************\n`, ctx.ModuleName()),
1676 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001677
1678 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001679 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1680 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001681 }
Nan Zhanga40da042018-08-01 12:48:00 -07001682
Nan Zhang1598a9e2018-09-04 17:14:32 -07001683 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1684 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001685 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1686 "check_api.last_released.api_file")
1687 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1688 "check_api.last_released.removed_api_file")
1689
Nan Zhang2760dfc2018-08-24 17:32:54 +00001690 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001691 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1692 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001693 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001694
Nan Zhang1598a9e2018-09-04 17:14:32 -07001695 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001696 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001697 `\n******************************\n`+
1698 `You have tried to change the API from what has been previously released in\n`+
1699 `an SDK. Please fix the errors listed above.\n`+
1700 `******************************\n`,
1701 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001702 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001703
Pete Gillin581d6082018-10-22 15:55:04 +01001704 if String(d.properties.Check_nullability_warnings) != "" {
1705 if d.nullabilityWarningsFile == nil {
1706 ctx.PropertyErrorf("check_nullability_warnings",
1707 "Cannot specify check_nullability_warnings unless validating nullability")
1708 }
1709 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1710 "check_nullability_warnings")
1711 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1712 msg := fmt.Sprintf(`\n******************************\n`+
1713 `The warnings encountered during nullability annotation validation did\n`+
1714 `not match the checked in file of expected warnings. The diffs are shown\n`+
1715 `above. You have two options:\n`+
1716 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1717 ` 2. Update the file of expected warnings by running:\n`+
1718 ` cp %s %s\n`+
1719 ` and submitting the updated file as part of your change.`,
1720 d.nullabilityWarningsFile, checkNullabilityWarnings)
1721 ctx.Build(pctx, android.BuildParams{
1722 Rule: nullabilityWarningsCheck,
1723 Description: "Nullability Warnings Check",
1724 Output: d.checkNullabilityWarningsTimestamp,
1725 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1726 Args: map[string]string{
1727 "expected": checkNullabilityWarnings.String(),
1728 "actual": d.nullabilityWarningsFile.String(),
1729 "msg": msg,
1730 },
1731 })
1732 }
1733
Nan Zhang71bbe632018-09-17 14:32:21 -07001734 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1735
Nan Zhang86b06202018-09-21 17:09:21 -07001736 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1737 // since there's cron job downstream that fetch this .zip file periodically.
1738 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001739 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1740 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1741
1742 var jdiffImplicitOutputs android.WritablePaths
1743 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1744
1745 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1746 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1747
1748 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1749 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1750 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1751 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1752 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1753 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1754
1755 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1756 flags.sourcepathArgs, opts)
1757 }
Nan Zhang581fd212018-01-10 16:06:12 -08001758}
Dan Willemsencc090972018-02-26 14:33:31 -08001759
Nan Zhanga40da042018-08-01 12:48:00 -07001760//
Nan Zhangf4936b02018-08-01 15:00:28 -07001761// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001762//
Dan Willemsencc090972018-02-26 14:33:31 -08001763var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001764var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001765var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001766var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001767
Nan Zhangf4936b02018-08-01 15:00:28 -07001768type ExportedDroiddocDirProperties struct {
1769 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001770 Path *string
1771}
1772
Nan Zhangf4936b02018-08-01 15:00:28 -07001773type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001774 android.ModuleBase
1775
Nan Zhangf4936b02018-08-01 15:00:28 -07001776 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001777
1778 deps android.Paths
1779 dir android.Path
1780}
1781
Nan Zhangf4936b02018-08-01 15:00:28 -07001782func ExportedDroiddocDirFactory() android.Module {
1783 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001784 module.AddProperties(&module.properties)
1785 android.InitAndroidModule(module)
1786 return module
1787}
1788
Nan Zhangf4936b02018-08-01 15:00:28 -07001789func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001790
Nan Zhangf4936b02018-08-01 15:00:28 -07001791func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001792 path := String(d.properties.Path)
1793 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001794 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001795}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001796
1797//
1798// Defaults
1799//
1800type DocDefaults struct {
1801 android.ModuleBase
1802 android.DefaultsModuleBase
1803}
1804
1805func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1806}
1807
Nan Zhangb2b33de2018-02-23 11:18:47 -08001808func DocDefaultsFactory() android.Module {
1809 module := &DocDefaults{}
1810
1811 module.AddProperties(
1812 &JavadocProperties{},
1813 &DroiddocProperties{},
1814 )
1815
1816 android.InitDefaultsModule(module)
1817
1818 return module
1819}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001820
1821func StubsDefaultsFactory() android.Module {
1822 module := &DocDefaults{}
1823
1824 module.AddProperties(
1825 &JavadocProperties{},
1826 &DroidstubsProperties{},
1827 )
1828
1829 android.InitDefaultsModule(module)
1830
1831 return module
1832}