blob: 57da6b621163c52860a0f65d5073adc85815ecac [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>
Colin Crosse4a05842019-05-28 10:17:14 -0700214 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700215 Args *string
216
217 // names of the output files used in args that will be generated
218 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800219}
220
Nan Zhang61819ce2018-05-04 18:49:16 -0700221type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900222 // path to the API txt file that the new API extracted from source code is checked
223 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800224 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700225
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900226 // path to the API txt file that the new @removed API extractd from source code is
227 // checked against. The path can be local to the module or from other module (via
228 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800229 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700230
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900231 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700232 Args *string
233}
234
Nan Zhang581fd212018-01-10 16:06:12 -0800235type DroiddocProperties struct {
236 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800237 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800238
Nan Zhanga40da042018-08-01 12:48:00 -0700239 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800240 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800241
242 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800243 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800244
245 // proofread file contains all of the text content of the javadocs concatenated into one file,
246 // suitable for spell-checking and other goodness.
Colin Cross27b922f2019-03-04 22:35:41 -0800247 Proofread_file *string `android:"path"`
Nan Zhang581fd212018-01-10 16:06:12 -0800248
249 // a todo file lists the program elements that are missing documentation.
250 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800251 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800252
253 // directory under current module source that provide additional resources (images).
254 Resourcesdir *string
255
256 // resources output directory under out/soong/.intermediates.
257 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800258
Nan Zhange2ba5d42018-07-11 15:16:55 -0700259 // if set to true, collect the values used by the Dev tools and
260 // write them in files packaged with the SDK. Defaults to false.
261 Write_sdk_values *bool
262
263 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800264 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700265
266 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800267 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700268
Nan Zhang581fd212018-01-10 16:06:12 -0800269 // a list of files under current module source dir which contains known tags in Java sources.
270 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800271 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700272
273 // the tag name used to distinguish if the API files belong to public/system/test.
274 Api_tag_name *string
275
276 // the generated public API filename by Doclava.
277 Api_filename *string
278
David Brazdilfbe4cc32018-05-31 13:56:46 +0100279 // the generated public Dex API filename by Doclava.
280 Dex_api_filename *string
281
Nan Zhang28c68b92018-03-13 16:17:01 -0700282 // the generated private API filename by Doclava.
283 Private_api_filename *string
284
285 // the generated private Dex API filename by Doclava.
286 Private_dex_api_filename *string
287
288 // the generated removed API filename by Doclava.
289 Removed_api_filename *string
290
David Brazdilaac0c3c2018-04-24 16:23:29 +0100291 // the generated removed Dex API filename by Doclava.
292 Removed_dex_api_filename *string
293
Mathew Inwood76c3de12018-06-22 15:28:11 +0100294 // mapping of dex signatures to source file and line number. This is a temporary property and
295 // will be deleted; you probably shouldn't be using it.
296 Dex_mapping_filename *string
297
Nan Zhang28c68b92018-03-13 16:17:01 -0700298 // the generated exact API filename by Doclava.
299 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700300
Nan Zhang66dc2362018-08-14 20:41:04 -0700301 // the generated proguard filename by Doclava.
302 Proguard_filename *string
303
Nan Zhang853f4202018-04-12 16:55:56 -0700304 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
305 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700306
307 Check_api struct {
308 Last_released ApiToCheck
309
310 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900311
312 // do not perform API check against Last_released, in the case that both two specified API
313 // files by Last_released are modules which don't exist.
314 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700315 }
Nan Zhang79614d12018-04-19 18:03:39 -0700316
Nan Zhang1598a9e2018-09-04 17:14:32 -0700317 // if set to true, generate docs through Dokka instead of Doclava.
318 Dokka_enabled *bool
319}
320
321type DroidstubsProperties struct {
322 // the tag name used to distinguish if the API files belong to public/system/test.
323 Api_tag_name *string
324
Nan Zhang199645c2018-09-19 12:40:06 -0700325 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700326 Api_filename *string
327
Nan Zhang199645c2018-09-19 12:40:06 -0700328 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700329 Dex_api_filename *string
330
Nan Zhang199645c2018-09-19 12:40:06 -0700331 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700332 Private_api_filename *string
333
Nan Zhang199645c2018-09-19 12:40:06 -0700334 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700335 Private_dex_api_filename *string
336
Nan Zhang199645c2018-09-19 12:40:06 -0700337 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338 Removed_api_filename *string
339
Nan Zhang199645c2018-09-19 12:40:06 -0700340 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700341 Removed_dex_api_filename *string
342
Nan Zhang9c69a122018-08-22 10:22:08 -0700343 // mapping of dex signatures to source file and line number. This is a temporary property and
344 // will be deleted; you probably shouldn't be using it.
345 Dex_mapping_filename *string
346
Nan Zhang199645c2018-09-19 12:40:06 -0700347 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700348 Exact_api_filename *string
349
Nan Zhang199645c2018-09-19 12:40:06 -0700350 // the generated proguard filename by Metalava.
351 Proguard_filename *string
352
Nan Zhang1598a9e2018-09-04 17:14:32 -0700353 Check_api struct {
354 Last_released ApiToCheck
355
356 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900357
358 // do not perform API check against Last_released, in the case that both two specified API
359 // files by Last_released are modules which don't exist.
360 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700361 }
Nan Zhang79614d12018-04-19 18:03:39 -0700362
363 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800364 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700365
366 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700367 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700368
Pete Gillin77167902018-09-19 18:16:26 +0100369 // 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 -0700370 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700371
Pete Gillin77167902018-09-19 18:16:26 +0100372 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
373 Merge_inclusion_annotations_dirs []string
374
Pete Gillinc382a562018-11-14 18:45:46 +0000375 // a file containing a list of classes to do nullability validation for.
376 Validate_nullability_from_list *string
377
Pete Gillin581d6082018-10-22 15:55:04 +0100378 // a file containing expected warnings produced by validation of nullability annotations.
379 Check_nullability_warnings *string
380
Nan Zhang1598a9e2018-09-04 17:14:32 -0700381 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
382 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700383
384 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
385 Api_levels_annotations_enabled *bool
386
387 // the dirs which Metalava extracts API levels annotations from.
388 Api_levels_annotations_dirs []string
389
390 // if set to true, collect the values used by the Dev tools and
391 // write them in files packaged with the SDK. Defaults to false.
392 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700393
394 // If set to true, .xml based public API file will be also generated, and
395 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
396 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800397}
398
Nan Zhanga40da042018-08-01 12:48:00 -0700399//
400// Common flags passed down to build rule
401//
402type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700403 bootClasspathArgs string
404 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700405 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700406 dokkaClasspathArgs string
407 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700408 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700409
Nan Zhanga40da042018-08-01 12:48:00 -0700410 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700411 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700412 postDoclavaCmds string
413
Nan Zhang9c69a122018-08-22 10:22:08 -0700414 metalavaStubsFlags string
415 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800416 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100417 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700418 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700419
Nan Zhang71bbe632018-09-17 14:32:21 -0700420 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700421}
422
423func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
424 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
425 android.InitDefaultableModule(module)
426}
427
Nan Zhang1598a9e2018-09-04 17:14:32 -0700428func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
429 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
430 return true
431 } else if String(apiToCheck.Api_file) != "" {
432 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
433 } else if String(apiToCheck.Removed_api_file) != "" {
434 panic("for " + apiVersionTag + " api_file has to be non-empty!")
435 }
436
437 return false
438}
439
Inseob Kim38449af2019-02-28 14:24:05 +0900440func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
441 api_file := String(apiToCheck.Api_file)
442 removed_api_file := String(apiToCheck.Removed_api_file)
443
444 api_module := android.SrcIsModule(api_file)
445 removed_api_module := android.SrcIsModule(removed_api_file)
446
447 if api_module == "" || removed_api_module == "" {
448 return
449 }
450
451 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
452 return
453 }
454
455 apiToCheck.Api_file = nil
456 apiToCheck.Removed_api_file = nil
457}
458
Nan Zhang1598a9e2018-09-04 17:14:32 -0700459type ApiFilePath interface {
460 ApiFilePath() android.Path
461}
462
463func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
464 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
465 ctx.Build(pctx, android.BuildParams{
466 Rule: updateApi,
467 Description: "Update API",
468 Output: output,
469 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
470 destApiFile, destRemovedApiFile),
471 Args: map[string]string{
472 "destApiFile": destApiFile.String(),
473 "srcApiFile": srcApiFile.String(),
474 "destRemovedApiFile": destRemovedApiFile.String(),
475 "srcRemovedApiFile": srcRemovedApiFile.String(),
476 },
477 })
478}
479
Nan Zhanga40da042018-08-01 12:48:00 -0700480//
481// Javadoc
482//
Nan Zhang581fd212018-01-10 16:06:12 -0800483type Javadoc struct {
484 android.ModuleBase
485 android.DefaultableModuleBase
486
487 properties JavadocProperties
488
489 srcJars android.Paths
490 srcFiles android.Paths
491 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700492 argFiles android.Paths
493
494 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800495
Nan Zhangccff0f72018-03-08 17:26:16 -0800496 docZip android.WritablePath
497 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800498}
499
Nan Zhangb2b33de2018-02-23 11:18:47 -0800500func (j *Javadoc) Srcs() android.Paths {
501 return android.Paths{j.stubsSrcJar}
502}
503
Nan Zhang581fd212018-01-10 16:06:12 -0800504func JavadocFactory() android.Module {
505 module := &Javadoc{}
506
507 module.AddProperties(&module.properties)
508
509 InitDroiddocModule(module, android.HostAndDeviceSupported)
510 return module
511}
512
513func JavadocHostFactory() android.Module {
514 module := &Javadoc{}
515
516 module.AddProperties(&module.properties)
517
518 InitDroiddocModule(module, android.HostSupported)
519 return module
520}
521
Nan Zhanga40da042018-08-01 12:48:00 -0700522var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800523
Colin Cross83bb3162018-06-25 15:48:06 -0700524func (j *Javadoc) sdkVersion() string {
525 return String(j.properties.Sdk_version)
526}
527
528func (j *Javadoc) minSdkVersion() string {
529 return j.sdkVersion()
530}
531
Dan Willemsen419290a2018-10-31 15:28:47 -0700532func (j *Javadoc) targetSdkVersion() string {
533 return j.sdkVersion()
534}
535
Nan Zhang581fd212018-01-10 16:06:12 -0800536func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
537 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700538 if !Bool(j.properties.No_standard_libs) {
539 sdkDep := decodeSdkDep(ctx, sdkContext(j))
540 if sdkDep.useDefaultLibs {
541 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
542 if ctx.Config().TargetOpenJDK9() {
543 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
544 }
545 if !Bool(j.properties.No_framework_libs) {
546 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
547 }
548 } else if sdkDep.useModule {
549 if ctx.Config().TargetOpenJDK9() {
550 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
551 }
552 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700553 }
Nan Zhang581fd212018-01-10 16:06:12 -0800554 }
555 }
556
Colin Cross42d48b72018-08-29 14:10:52 -0700557 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700558 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700559 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700560 }
Nan Zhang581fd212018-01-10 16:06:12 -0800561}
562
Nan Zhangb2b33de2018-02-23 11:18:47 -0800563func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
564 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
565 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900566 // convert foo.bar.baz to foo/bar/baz
567 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
568 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800569 if _, found := whitelistPathPrefixes[prefix]; !found {
570 whitelistPathPrefixes[prefix] = true
571 }
572 }
573 }
574}
575
Nan Zhanga40da042018-08-01 12:48:00 -0700576func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
577 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900578
Colin Cross3047fa22019-04-18 10:56:44 -0700579 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900580
581 return flags
582}
583
584func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700585 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900586
587 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
588 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
589
590 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700591 var deps android.Paths
592
Jiyong Park1e440682018-05-23 18:42:04 +0900593 if aidlPreprocess.Valid() {
594 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700595 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900596 } else {
597 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
598 }
599
600 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
601 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
602 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
603 flags = append(flags, "-I"+src.String())
604 }
605
Colin Cross3047fa22019-04-18 10:56:44 -0700606 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900607}
608
609func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700610 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900611
612 outSrcFiles := make(android.Paths, 0, len(srcFiles))
613
614 for _, srcFile := range srcFiles {
615 switch srcFile.Ext() {
616 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700617 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Jiyong Park1e440682018-05-23 18:42:04 +0900618 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900619 case ".sysprop":
620 javaFile := genSysprop(ctx, srcFile)
621 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900622 default:
623 outSrcFiles = append(outSrcFiles, srcFile)
624 }
625 }
626
627 return outSrcFiles
628}
629
Nan Zhang581fd212018-01-10 16:06:12 -0800630func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
631 var deps deps
632
Colin Cross83bb3162018-06-25 15:48:06 -0700633 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800634 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700635 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800636 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700637 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800638 }
639
640 ctx.VisitDirectDeps(func(module android.Module) {
641 otherName := ctx.OtherModuleName(module)
642 tag := ctx.OtherModuleDependencyTag(module)
643
Colin Cross2d24c1b2018-05-23 10:59:18 -0700644 switch tag {
645 case bootClasspathTag:
646 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800647 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700648 } else {
649 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
650 }
651 case libTag:
652 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800653 case SdkLibraryDependency:
654 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700655 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900656 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700657 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800658 checkProducesJars(ctx, dep)
659 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800660 default:
661 ctx.ModuleErrorf("depends on non-java module %q", otherName)
662 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700663 case srcsLibTag:
664 switch dep := module.(type) {
665 case Dependency:
666 srcs := dep.(SrcDependency).CompiledSrcs()
667 whitelistPathPrefixes := make(map[string]bool)
668 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
669 for _, src := range srcs {
670 if _, ok := src.(android.WritablePath); ok { // generated sources
671 deps.srcs = append(deps.srcs, src)
672 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700673 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700674 if strings.HasPrefix(src.Rel(), k) {
675 deps.srcs = append(deps.srcs, src)
676 break
677 }
678 }
679 }
680 }
681 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
682 default:
683 ctx.ModuleErrorf("depends on non-java module %q", otherName)
684 }
Nan Zhang357466b2018-04-17 17:38:36 -0700685 case systemModulesTag:
686 if deps.systemModules != nil {
687 panic("Found two system module dependencies")
688 }
689 sm := module.(*SystemModules)
690 if sm.outputFile == nil {
691 panic("Missing directory for system module dependency")
692 }
693 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800694 }
695 })
696 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
697 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800698 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700699 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900700 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800701
702 // srcs may depend on some genrule output.
703 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800704 j.srcJars = append(j.srcJars, deps.srcJars...)
705
Nan Zhang581fd212018-01-10 16:06:12 -0800706 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800707 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800708
709 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800710 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800711
Nan Zhang9c69a122018-08-22 10:22:08 -0700712 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800713 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
714 }
715 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800716
Colin Cross8a497952019-03-05 22:25:09 -0800717 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000718 argFilesMap := map[string]string{}
719 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700720
Paul Duffin99e4a502019-02-11 15:38:42 +0000721 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800722 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000723 if _, exists := argFilesMap[label]; !exists {
724 argFilesMap[label] = strings.Join(paths.Strings(), " ")
725 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700726 } else {
727 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000728 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700729 }
730 }
731
732 var err error
733 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
734 if strings.HasPrefix(name, "location ") {
735 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000736 if paths, ok := argFilesMap[label]; ok {
737 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700738 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000739 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
740 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700741 }
742 } else if name == "genDir" {
743 return android.PathForModuleGen(ctx).String(), nil
744 }
745 return "", fmt.Errorf("unknown variable '$(%s)'", name)
746 })
747
748 if err != nil {
749 ctx.PropertyErrorf("args", "%s", err.Error())
750 }
751
Nan Zhang581fd212018-01-10 16:06:12 -0800752 return deps
753}
754
755func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
756 j.addDeps(ctx)
757}
758
759func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
760 deps := j.collectDeps(ctx)
761
762 var implicits android.Paths
763 implicits = append(implicits, deps.bootClasspath...)
764 implicits = append(implicits, deps.classpath...)
765
Nan Zhang1598a9e2018-09-04 17:14:32 -0700766 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700767
Colin Cross83bb3162018-06-25 15:48:06 -0700768 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700769 if len(deps.bootClasspath) > 0 {
770 var systemModules classpath
771 if deps.systemModules != nil {
772 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800773 }
Colin Cross997262f2018-06-19 22:49:39 -0700774 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
775 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800776 }
777 if len(deps.classpath.Strings()) > 0 {
778 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
779 }
780
781 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700782 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800783
Nan Zhangaf322cc2018-06-19 15:15:38 -0700784 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800785
Nan Zhang1598a9e2018-09-04 17:14:32 -0700786 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
787
Nan Zhang581fd212018-01-10 16:06:12 -0800788 ctx.Build(pctx, android.BuildParams{
789 Rule: javadoc,
790 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800791 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800792 ImplicitOutput: j.docZip,
793 Inputs: j.srcFiles,
794 Implicits: implicits,
795 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700796 "outDir": android.PathForModuleOut(ctx, "out").String(),
797 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
798 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800799 "srcJars": strings.Join(j.srcJars.Strings(), " "),
800 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700801 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800802 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700803 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800804 "docZip": j.docZip.String(),
805 },
806 })
807}
808
Nan Zhanga40da042018-08-01 12:48:00 -0700809//
810// Droiddoc
811//
812type Droiddoc struct {
813 Javadoc
814
815 properties DroiddocProperties
816 apiFile android.WritablePath
817 dexApiFile android.WritablePath
818 privateApiFile android.WritablePath
819 privateDexApiFile android.WritablePath
820 removedApiFile android.WritablePath
821 removedDexApiFile android.WritablePath
822 exactApiFile android.WritablePath
823 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700824 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700825
826 checkCurrentApiTimestamp android.WritablePath
827 updateCurrentApiTimestamp android.WritablePath
828 checkLastReleasedApiTimestamp android.WritablePath
829
Nan Zhanga40da042018-08-01 12:48:00 -0700830 apiFilePath android.Path
831}
832
Nan Zhanga40da042018-08-01 12:48:00 -0700833func DroiddocFactory() android.Module {
834 module := &Droiddoc{}
835
836 module.AddProperties(&module.properties,
837 &module.Javadoc.properties)
838
839 InitDroiddocModule(module, android.HostAndDeviceSupported)
840 return module
841}
842
843func DroiddocHostFactory() android.Module {
844 module := &Droiddoc{}
845
846 module.AddProperties(&module.properties,
847 &module.Javadoc.properties)
848
849 InitDroiddocModule(module, android.HostSupported)
850 return module
851}
852
853func (d *Droiddoc) ApiFilePath() android.Path {
854 return d.apiFilePath
855}
856
Nan Zhang581fd212018-01-10 16:06:12 -0800857func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
858 d.Javadoc.addDeps(ctx)
859
Inseob Kim38449af2019-02-28 14:24:05 +0900860 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
861 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
862 }
863
Nan Zhang79614d12018-04-19 18:03:39 -0700864 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800865 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
866 }
Nan Zhang581fd212018-01-10 16:06:12 -0800867}
868
Nan Zhang66dc2362018-08-14 20:41:04 -0700869func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
870 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700871 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800872
Nan Zhanga40da042018-08-01 12:48:00 -0700873 *implicits = append(*implicits, deps.bootClasspath...)
874 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800875
Nan Zhangc94f9d82018-06-26 10:02:26 -0700876 if len(deps.bootClasspath.Strings()) > 0 {
877 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700878 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700879 }
Nan Zhanga40da042018-08-01 12:48:00 -0700880 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700881 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700882 dokkaClasspath := classpath{}
883 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
884 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
885 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700886
Nan Zhang9c69a122018-08-22 10:22:08 -0700887 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
888 // based stubs generation.
889 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
890 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
891 // the correct package name base path.
892 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
893 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
894 } else {
895 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
896 }
Nan Zhang581fd212018-01-10 16:06:12 -0800897
Nan Zhanga40da042018-08-01 12:48:00 -0700898 return flags, nil
899}
Nan Zhang581fd212018-01-10 16:06:12 -0800900
Nan Zhanga40da042018-08-01 12:48:00 -0700901func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700902 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800903
Nan Zhanga40da042018-08-01 12:48:00 -0700904 *implicits = append(*implicits, jsilver)
905 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700906
Nan Zhang46130972018-06-04 11:28:01 -0700907 var date string
908 if runtime.GOOS == "darwin" {
909 date = `date -r`
910 } else {
911 date = `date -d`
912 }
913
Nan Zhang443fa522018-08-20 20:58:28 -0700914 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
915 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
916 // 1.9 language features.
917 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700918 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800919 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700920 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700921
Nan Zhanga40da042018-08-01 12:48:00 -0700922 if String(d.properties.Custom_template) == "" {
923 // TODO: This is almost always droiddoc-templates-sdk
924 ctx.PropertyErrorf("custom_template", "must specify a template")
925 }
926
927 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700928 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700929 *implicits = append(*implicits, t.deps...)
930 args = args + " -templatedir " + t.dir.String()
931 } else {
932 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
933 }
934 })
935
936 if len(d.properties.Html_dirs) > 0 {
Colin Cross07e51612019-03-05 12:46:40 -0800937 htmlDir := d.properties.Html_dirs[0]
Colin Cross8a497952019-03-05 22:25:09 -0800938 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800939 args = args + " -htmldir " + htmlDir
Nan Zhanga40da042018-08-01 12:48:00 -0700940 }
941
942 if len(d.properties.Html_dirs) > 1 {
Colin Cross07e51612019-03-05 12:46:40 -0800943 htmlDir2 := d.properties.Html_dirs[1]
Colin Cross8a497952019-03-05 22:25:09 -0800944 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800945 args = args + " -htmldir2 " + htmlDir2
Nan Zhanga40da042018-08-01 12:48:00 -0700946 }
947
948 if len(d.properties.Html_dirs) > 2 {
949 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
950 }
951
Colin Cross8a497952019-03-05 22:25:09 -0800952 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Nan Zhanga40da042018-08-01 12:48:00 -0700953 *implicits = append(*implicits, knownTags...)
954
955 for _, kt := range knownTags {
956 args = args + " -knowntags " + kt.String()
957 }
958
959 for _, hdf := range d.properties.Hdf {
960 args = args + " -hdf " + hdf
961 }
962
963 if String(d.properties.Proofread_file) != "" {
964 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
965 args = args + " -proofread " + proofreadFile.String()
966 }
967
968 if String(d.properties.Todo_file) != "" {
969 // tricky part:
970 // we should not compute full path for todo_file through PathForModuleOut().
971 // the non-standard doclet will get the full path relative to "-o".
972 args = args + " -todo " + String(d.properties.Todo_file)
973 }
974
975 if String(d.properties.Resourcesdir) != "" {
976 // TODO: should we add files under resourcesDir to the implicits? It seems that
977 // resourcesDir is one sub dir of htmlDir
978 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
979 args = args + " -resourcesdir " + resourcesDir.String()
980 }
981
982 if String(d.properties.Resourcesoutdir) != "" {
983 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
984 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
985 }
986 return args
987}
988
Nan Zhang1598a9e2018-09-04 17:14:32 -0700989func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
990 implicitOutputs *android.WritablePaths) string {
991 var doclavaFlags string
992 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
993 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
994 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700995 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
996 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700997 *implicitOutputs = append(*implicitOutputs, d.apiFile)
998 d.apiFilePath = d.apiFile
999 }
1000
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1002 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1003 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001004 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1005 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001006 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1007 }
1008
1009 if String(d.properties.Private_api_filename) != "" {
1010 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1011 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001012 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1013 }
1014
1015 if String(d.properties.Dex_api_filename) != "" {
1016 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1017 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1018 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1019 }
1020
1021 if String(d.properties.Private_dex_api_filename) != "" {
1022 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1023 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001024 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1025 }
1026
1027 if String(d.properties.Removed_dex_api_filename) != "" {
1028 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1029 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001030 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1031 }
1032
1033 if String(d.properties.Exact_api_filename) != "" {
1034 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1035 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001036 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1037 }
1038
1039 if String(d.properties.Dex_mapping_filename) != "" {
1040 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1041 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001042 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1043 }
1044
Nan Zhang66dc2362018-08-14 20:41:04 -07001045 if String(d.properties.Proguard_filename) != "" {
1046 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1047 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001048 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1049 }
1050
Nan Zhanga40da042018-08-01 12:48:00 -07001051 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001052 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001053 }
1054
1055 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001056 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001057 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001058
1059 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001060}
1061
1062func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1063 var cmds string
1064 if String(d.properties.Static_doc_index_redirect) != "" {
1065 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1066 "static_doc_index_redirect")
1067 *implicits = append(*implicits, static_doc_index_redirect)
1068 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001069 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001070 }
1071
1072 if String(d.properties.Static_doc_properties) != "" {
1073 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1074 "static_doc_properties")
1075 *implicits = append(*implicits, static_doc_properties)
1076 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001077 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001078 }
1079 return cmds
1080}
1081
Nan Zhang1598a9e2018-09-04 17:14:32 -07001082func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1083 implicitOutputs android.WritablePaths,
1084 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1085 ctx.Build(pctx, android.BuildParams{
1086 Rule: javadoc,
1087 Description: "Doclava",
1088 Output: d.Javadoc.stubsSrcJar,
1089 Inputs: d.Javadoc.srcFiles,
1090 Implicits: implicits,
1091 ImplicitOutputs: implicitOutputs,
1092 Args: map[string]string{
1093 "outDir": android.PathForModuleOut(ctx, "out").String(),
1094 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1095 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1096 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1097 "opts": opts,
1098 "bootclasspathArgs": bootclasspathArgs,
1099 "classpathArgs": classpathArgs,
1100 "sourcepathArgs": sourcepathArgs,
1101 "docZip": d.Javadoc.docZip.String(),
1102 "postDoclavaCmds": postDoclavaCmds,
1103 },
1104 })
1105}
1106
1107func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1108 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1109 ctx.Build(pctx, android.BuildParams{
1110 Rule: apiCheck,
1111 Description: "Doclava Check API",
1112 Output: output,
1113 Inputs: nil,
1114 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1115 checkApiClasspath...),
1116 Args: map[string]string{
1117 "msg": msg,
1118 "classpath": checkApiClasspath.FormJavaClassPath(""),
1119 "opts": opts,
1120 "apiFile": apiFile.String(),
1121 "apiFileToCheck": d.apiFile.String(),
1122 "removedApiFile": removedApiFile.String(),
1123 "removedApiFileToCheck": d.removedApiFile.String(),
1124 },
1125 })
1126}
1127
1128func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1129 classpathArgs, opts string) {
1130 ctx.Build(pctx, android.BuildParams{
1131 Rule: dokka,
1132 Description: "Dokka",
1133 Output: d.Javadoc.stubsSrcJar,
1134 Inputs: d.Javadoc.srcFiles,
1135 Implicits: implicits,
1136 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001137 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1138 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1139 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001140 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1141 "classpathArgs": classpathArgs,
1142 "opts": opts,
1143 "docZip": d.Javadoc.docZip.String(),
1144 },
1145 })
1146}
1147
1148func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1149 deps := d.Javadoc.collectDeps(ctx)
1150
1151 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1152 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1153 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1154 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1155
1156 var implicits android.Paths
1157 implicits = append(implicits, d.Javadoc.srcJars...)
1158 implicits = append(implicits, d.Javadoc.argFiles...)
1159
1160 var implicitOutputs android.WritablePaths
1161 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1162 for _, o := range d.Javadoc.properties.Out {
1163 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1164 }
1165
1166 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1167 if err != nil {
1168 return
1169 }
1170
1171 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1172 if Bool(d.properties.Dokka_enabled) {
1173 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1174 } else {
1175 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1176 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1177 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1178 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1179 flags.postDoclavaCmds)
1180 }
1181
1182 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1183 !ctx.Config().IsPdkBuild() {
1184 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1185 "check_api.current.api_file")
1186 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1187 "check_api.current_removed_api_file")
1188
1189 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1190 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1191 fmt.Sprintf(`\n******************************\n`+
1192 `You have tried to change the API from what has been previously approved.\n\n`+
1193 `To make these errors go away, you have two choices:\n`+
1194 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1195 ` errors above.\n\n`+
1196 ` 2. You can update current.txt by executing the following command:\n`+
1197 ` make %s-update-current-api\n\n`+
1198 ` To submit the revised current.txt to the main Android repository,\n`+
1199 ` you will need approval.\n`+
1200 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1201 d.checkCurrentApiTimestamp)
1202
1203 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1204 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1205 d.updateCurrentApiTimestamp)
1206 }
1207
1208 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1209 !ctx.Config().IsPdkBuild() {
1210 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1211 "check_api.last_released.api_file")
1212 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1213 "check_api.last_released.removed_api_file")
1214
1215 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1216 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1217 `\n******************************\n`+
1218 `You have tried to change the API from what has been previously released in\n`+
1219 `an SDK. Please fix the errors listed above.\n`+
1220 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1221 d.checkLastReleasedApiTimestamp)
1222 }
1223}
1224
1225//
1226// Droidstubs
1227//
1228type Droidstubs struct {
1229 Javadoc
1230
Pete Gillin581d6082018-10-22 15:55:04 +01001231 properties DroidstubsProperties
1232 apiFile android.WritablePath
1233 apiXmlFile android.WritablePath
1234 lastReleasedApiXmlFile android.WritablePath
1235 dexApiFile android.WritablePath
1236 privateApiFile android.WritablePath
1237 privateDexApiFile android.WritablePath
1238 removedApiFile android.WritablePath
1239 removedDexApiFile android.WritablePath
1240 apiMappingFile android.WritablePath
1241 exactApiFile android.WritablePath
1242 proguardFile android.WritablePath
1243 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001244
1245 checkCurrentApiTimestamp android.WritablePath
1246 updateCurrentApiTimestamp android.WritablePath
1247 checkLastReleasedApiTimestamp android.WritablePath
1248
Pete Gillin581d6082018-10-22 15:55:04 +01001249 checkNullabilityWarningsTimestamp android.WritablePath
1250
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001252 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253
1254 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001255
1256 jdiffDocZip android.WritablePath
1257 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001258}
1259
1260func DroidstubsFactory() android.Module {
1261 module := &Droidstubs{}
1262
1263 module.AddProperties(&module.properties,
1264 &module.Javadoc.properties)
1265
1266 InitDroiddocModule(module, android.HostAndDeviceSupported)
1267 return module
1268}
1269
1270func DroidstubsHostFactory() android.Module {
1271 module := &Droidstubs{}
1272
1273 module.AddProperties(&module.properties,
1274 &module.Javadoc.properties)
1275
1276 InitDroiddocModule(module, android.HostSupported)
1277 return module
1278}
1279
1280func (d *Droidstubs) ApiFilePath() android.Path {
1281 return d.apiFilePath
1282}
1283
1284func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1285 d.Javadoc.addDeps(ctx)
1286
Inseob Kim38449af2019-02-28 14:24:05 +09001287 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1288 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1289 }
1290
Nan Zhang1598a9e2018-09-04 17:14:32 -07001291 if len(d.properties.Merge_annotations_dirs) != 0 {
1292 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1293 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1294 }
1295 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001296
Pete Gillin77167902018-09-19 18:16:26 +01001297 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1298 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1299 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1300 }
1301 }
1302
Nan Zhang9c69a122018-08-22 10:22:08 -07001303 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1304 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1305 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1306 }
1307 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001308}
1309
1310func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1311 deps deps) (droiddocBuilderFlags, error) {
1312 var flags droiddocBuilderFlags
1313
1314 *implicits = append(*implicits, deps.bootClasspath...)
1315 *implicits = append(*implicits, deps.classpath...)
1316
1317 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1318 // since it doesn't support system modules yet.
1319 if len(deps.bootClasspath.Strings()) > 0 {
1320 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1321 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1322 }
1323 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1324
Sundong Ahn56dce442018-10-05 18:41:09 +09001325 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 return flags, nil
1327}
1328
1329func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1330 implicitOutputs *android.WritablePaths) string {
1331 var metalavaFlags string
1332 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1333 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1334 String(d.properties.Api_filename) != "" {
1335 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1336 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1337 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1338 d.apiFilePath = d.apiFile
1339 }
1340
1341 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1342 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1343 String(d.properties.Removed_api_filename) != "" {
1344 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1345 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1346 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1347 }
1348
1349 if String(d.properties.Private_api_filename) != "" {
1350 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1351 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1352 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1353 }
1354
1355 if String(d.properties.Dex_api_filename) != "" {
1356 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1357 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1358 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1359 }
1360
1361 if String(d.properties.Private_dex_api_filename) != "" {
1362 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1363 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1364 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1365 }
1366
1367 if String(d.properties.Removed_dex_api_filename) != "" {
1368 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1369 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1370 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1371 }
1372
1373 if String(d.properties.Exact_api_filename) != "" {
1374 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1375 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1376 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1377 }
1378
Nan Zhang9c69a122018-08-22 10:22:08 -07001379 if String(d.properties.Dex_mapping_filename) != "" {
1380 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1381 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1382 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1383 }
1384
Nan Zhang199645c2018-09-19 12:40:06 -07001385 if String(d.properties.Proguard_filename) != "" {
1386 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1387 metalavaFlags += " --proguard " + d.proguardFile.String()
1388 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1389 }
1390
Nan Zhang9c69a122018-08-22 10:22:08 -07001391 if Bool(d.properties.Write_sdk_values) {
1392 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1393 }
1394
Nan Zhang1598a9e2018-09-04 17:14:32 -07001395 if Bool(d.properties.Create_doc_stubs) {
1396 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1397 } else {
1398 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1399 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001400 return metalavaFlags
1401}
1402
1403func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001404 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1405 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001406 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001407 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001408 validatingNullability :=
1409 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1410 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001411 migratingNullability := String(d.properties.Previous_api) != ""
1412 if !(migratingNullability || validatingNullability) {
1413 ctx.PropertyErrorf("previous_api",
1414 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001415 }
Pete Gillina262c052018-09-14 14:25:48 +01001416 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001417 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Pete Gillina262c052018-09-14 14:25:48 +01001418 *implicits = append(*implicits, previousApi)
1419 flags += " --migrate-nullness " + previousApi.String()
1420 }
Pete Gillinc382a562018-11-14 18:45:46 +00001421 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross8a497952019-03-05 22:25:09 -08001422 flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String()
Pete Gillinc382a562018-11-14 18:45:46 +00001423 }
Pete Gillina262c052018-09-14 14:25:48 +01001424 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001425 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1426 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1427 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001428 }
Nan Zhanga40da042018-08-01 12:48:00 -07001429
1430 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1431 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1432
Nan Zhangf4936b02018-08-01 15:00:28 -07001433 flags += " --extract-annotations " + d.annotationsZip.String()
1434
Nan Zhang1598a9e2018-09-04 17:14:32 -07001435 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001436 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001437 "has to be non-empty if annotations was enabled!")
1438 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001439 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1440 if t, ok := m.(*ExportedDroiddocDir); ok {
1441 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001442 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001443 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001444 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001445 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1446 }
1447 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001448 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001449 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001450 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001451 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001452
Nan Zhangdee152b2018-12-26 16:06:37 -08001453 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001454}
1455
1456func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1457 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1458 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001459 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1460 if t, ok := m.(*ExportedDroiddocDir); ok {
1461 *implicits = append(*implicits, t.deps...)
1462 flags += " --merge-inclusion-annotations " + t.dir.String()
1463 } else {
1464 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1465 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1466 }
1467 })
Nan Zhanga40da042018-08-01 12:48:00 -07001468
1469 return flags
1470}
1471
Nan Zhang9c69a122018-08-22 10:22:08 -07001472func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1473 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1474 var flags string
1475 if Bool(d.properties.Api_levels_annotations_enabled) {
1476 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1477 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1478
1479 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1480 ctx.PropertyErrorf("api_levels_annotations_dirs",
1481 "has to be non-empty if api levels annotations was enabled!")
1482 }
1483
1484 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1485 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1486 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1487
1488 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1489 if t, ok := m.(*ExportedDroiddocDir); ok {
1490 var androidJars android.Paths
1491 for _, dep := range t.deps {
1492 if strings.HasSuffix(dep.String(), "android.jar") {
1493 androidJars = append(androidJars, dep)
1494 }
1495 }
1496 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001497 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001498 } else {
1499 ctx.PropertyErrorf("api_levels_annotations_dirs",
1500 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1501 }
1502 })
1503
1504 }
1505
1506 return flags
1507}
1508
Nan Zhang71bbe632018-09-17 14:32:21 -07001509func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1510 implicitOutputs *android.WritablePaths) string {
1511 var flags string
1512 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1513 if d.apiFile.String() == "" {
1514 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1515 }
1516
1517 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1518 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1519
1520 flags = " --api-xml " + d.apiXmlFile.String()
1521
1522 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1523 ctx.PropertyErrorf("check_api.last_released.api_file",
1524 "has to be non-empty if jdiff was enabled!")
1525 }
1526 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1527 "check_api.last_released.api_file")
1528 *implicits = append(*implicits, lastReleasedApi)
1529
1530 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1531 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1532
1533 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1534 d.lastReleasedApiXmlFile.String()
1535 }
1536
1537 return flags
1538}
1539
Nan Zhang1598a9e2018-09-04 17:14:32 -07001540func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1541 implicitOutputs android.WritablePaths, javaVersion,
1542 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001543
Nan Zhang86d2d552018-08-09 15:33:27 -07001544 ctx.Build(pctx, android.BuildParams{
1545 Rule: metalava,
1546 Description: "Metalava",
1547 Output: d.Javadoc.stubsSrcJar,
1548 Inputs: d.Javadoc.srcFiles,
1549 Implicits: implicits,
1550 ImplicitOutputs: implicitOutputs,
1551 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001552 "outDir": android.PathForModuleOut(ctx, "out").String(),
1553 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1554 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1555 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001556 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001557 "bootclasspathArgs": bootclasspathArgs,
1558 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001559 "sourcepathArgs": sourcepathArgs,
1560 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001561 },
1562 })
1563}
1564
Nan Zhang1598a9e2018-09-04 17:14:32 -07001565func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1566 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001567 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001568 output android.WritablePath) {
1569 ctx.Build(pctx, android.BuildParams{
1570 Rule: metalavaApiCheck,
1571 Description: "Metalava Check API",
1572 Output: output,
1573 Inputs: d.Javadoc.srcFiles,
1574 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1575 implicits...),
1576 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001577 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001578 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1579 "javaVersion": javaVersion,
1580 "bootclasspathArgs": bootclasspathArgs,
1581 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001582 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001583 "opts": opts,
1584 "msg": msg,
1585 },
1586 })
1587}
1588
Nan Zhang71bbe632018-09-17 14:32:21 -07001589func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1590 implicitOutputs android.WritablePaths,
1591 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1592 ctx.Build(pctx, android.BuildParams{
1593 Rule: javadoc,
1594 Description: "Jdiff",
1595 Output: d.jdiffStubsSrcJar,
1596 Inputs: d.Javadoc.srcFiles,
1597 Implicits: implicits,
1598 ImplicitOutputs: implicitOutputs,
1599 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001600 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1601 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1602 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001603 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1604 "opts": opts,
1605 "bootclasspathArgs": bootclasspathArgs,
1606 "classpathArgs": classpathArgs,
1607 "sourcepathArgs": sourcepathArgs,
1608 "docZip": d.jdiffDocZip.String(),
1609 },
1610 })
1611}
1612
Nan Zhang1598a9e2018-09-04 17:14:32 -07001613func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001614 deps := d.Javadoc.collectDeps(ctx)
1615
1616 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001617
Nan Zhanga40da042018-08-01 12:48:00 -07001618 var implicits android.Paths
1619 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001620 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001621
1622 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001623 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001624 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1625 }
1626
1627 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001628 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001629 jdiffImplicits := implicits
1630
Nan Zhanga40da042018-08-01 12:48:00 -07001631 if err != nil {
1632 return
1633 }
1634
Nan Zhang1598a9e2018-09-04 17:14:32 -07001635 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001636 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1637 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001638 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001639 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001640 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1641
Nan Zhang1598a9e2018-09-04 17:14:32 -07001642 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1643 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1644 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1645 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1646 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001647 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001648 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1649 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001650 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001651 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001652
Nan Zhang1598a9e2018-09-04 17:14:32 -07001653 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1654 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001655 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1656 "check_api.current.api_file")
1657 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1658 "check_api.current_removed_api_file")
1659
Nan Zhang2760dfc2018-08-24 17:32:54 +00001660 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001661 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1662 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001663 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001664
Nan Zhang1598a9e2018-09-04 17:14:32 -07001665 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001666 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001667 fmt.Sprintf(`\n******************************\n`+
1668 `You have tried to change the API from what has been previously approved.\n\n`+
1669 `To make these errors go away, you have two choices:\n`+
1670 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1671 ` errors above.\n\n`+
1672 ` 2. You can update current.txt by executing the following command:\n`+
1673 ` make %s-update-current-api\n\n`+
1674 ` To submit the revised current.txt to the main Android repository,\n`+
1675 ` you will need approval.\n`+
1676 `******************************\n`, ctx.ModuleName()),
1677 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001678
1679 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001680 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1681 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001682 }
Nan Zhanga40da042018-08-01 12:48:00 -07001683
Nan Zhang1598a9e2018-09-04 17:14:32 -07001684 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1685 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001686 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1687 "check_api.last_released.api_file")
1688 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1689 "check_api.last_released.removed_api_file")
1690
Nan Zhang2760dfc2018-08-24 17:32:54 +00001691 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001692 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1693 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001694 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001695
Nan Zhang1598a9e2018-09-04 17:14:32 -07001696 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001697 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001698 `\n******************************\n`+
1699 `You have tried to change the API from what has been previously released in\n`+
1700 `an SDK. Please fix the errors listed above.\n`+
1701 `******************************\n`,
1702 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001703 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001704
Pete Gillin581d6082018-10-22 15:55:04 +01001705 if String(d.properties.Check_nullability_warnings) != "" {
1706 if d.nullabilityWarningsFile == nil {
1707 ctx.PropertyErrorf("check_nullability_warnings",
1708 "Cannot specify check_nullability_warnings unless validating nullability")
1709 }
1710 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1711 "check_nullability_warnings")
1712 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1713 msg := fmt.Sprintf(`\n******************************\n`+
1714 `The warnings encountered during nullability annotation validation did\n`+
1715 `not match the checked in file of expected warnings. The diffs are shown\n`+
1716 `above. You have two options:\n`+
1717 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1718 ` 2. Update the file of expected warnings by running:\n`+
1719 ` cp %s %s\n`+
1720 ` and submitting the updated file as part of your change.`,
1721 d.nullabilityWarningsFile, checkNullabilityWarnings)
1722 ctx.Build(pctx, android.BuildParams{
1723 Rule: nullabilityWarningsCheck,
1724 Description: "Nullability Warnings Check",
1725 Output: d.checkNullabilityWarningsTimestamp,
1726 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1727 Args: map[string]string{
1728 "expected": checkNullabilityWarnings.String(),
1729 "actual": d.nullabilityWarningsFile.String(),
1730 "msg": msg,
1731 },
1732 })
1733 }
1734
Nan Zhang71bbe632018-09-17 14:32:21 -07001735 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1736
Nan Zhang86b06202018-09-21 17:09:21 -07001737 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1738 // since there's cron job downstream that fetch this .zip file periodically.
1739 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001740 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1741 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1742
1743 var jdiffImplicitOutputs android.WritablePaths
1744 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1745
1746 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1747 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1748
1749 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1750 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1751 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1752 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1753 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1754 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1755
1756 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1757 flags.sourcepathArgs, opts)
1758 }
Nan Zhang581fd212018-01-10 16:06:12 -08001759}
Dan Willemsencc090972018-02-26 14:33:31 -08001760
Nan Zhanga40da042018-08-01 12:48:00 -07001761//
Nan Zhangf4936b02018-08-01 15:00:28 -07001762// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001763//
Dan Willemsencc090972018-02-26 14:33:31 -08001764var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001765var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001766var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001767var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001768
Nan Zhangf4936b02018-08-01 15:00:28 -07001769type ExportedDroiddocDirProperties struct {
1770 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001771 Path *string
1772}
1773
Nan Zhangf4936b02018-08-01 15:00:28 -07001774type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001775 android.ModuleBase
1776
Nan Zhangf4936b02018-08-01 15:00:28 -07001777 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001778
1779 deps android.Paths
1780 dir android.Path
1781}
1782
Nan Zhangf4936b02018-08-01 15:00:28 -07001783func ExportedDroiddocDirFactory() android.Module {
1784 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001785 module.AddProperties(&module.properties)
1786 android.InitAndroidModule(module)
1787 return module
1788}
1789
Nan Zhangf4936b02018-08-01 15:00:28 -07001790func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001791
Nan Zhangf4936b02018-08-01 15:00:28 -07001792func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001793 path := String(d.properties.Path)
1794 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001795 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001796}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001797
1798//
1799// Defaults
1800//
1801type DocDefaults struct {
1802 android.ModuleBase
1803 android.DefaultsModuleBase
1804}
1805
1806func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1807}
1808
Nan Zhangb2b33de2018-02-23 11:18:47 -08001809func DocDefaultsFactory() android.Module {
1810 module := &DocDefaults{}
1811
1812 module.AddProperties(
1813 &JavadocProperties{},
1814 &DroiddocProperties{},
1815 )
1816
1817 android.InitDefaultsModule(module)
1818
1819 return module
1820}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001821
1822func StubsDefaultsFactory() android.Module {
1823 module := &DocDefaults{}
1824
1825 module.AddProperties(
1826 &JavadocProperties{},
1827 &DroidstubsProperties{},
1828 )
1829
1830 android.InitDefaultsModule(module)
1831
1832 return module
1833}