blob: be1b2815316b36897f109a189723e171b1690e5e [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 && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -070076 `${config.JavaCmd} ${config.JavaVmFlags} -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 && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -070098 `${config.JavaCmd} ${config.JavaVmFlags} -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 && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -0700123 `${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.DokkaJar} $srcJarDir ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -0700124 `$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 framework libraries (ext, and framework for device targets)
Nan Zhange66c7272018-03-06 12:59:27 -0800175 No_framework_libs *bool
176
Nan Zhangb2b33de2018-02-23 11:18:47 -0800177 // the java library (in classpath) for documentation that provides java srcs and srcjars.
178 Srcs_lib *string
179
180 // the base dirs under srcs_lib will be scanned for java srcs.
181 Srcs_lib_whitelist_dirs []string
182
183 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
184 Srcs_lib_whitelist_pkgs []string
185
Nan Zhang581fd212018-01-10 16:06:12 -0800186 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800187 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800188
189 // if not blank, set to the version of the sdk to compile against
190 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900191
192 Aidl struct {
193 // Top level directories to pass to aidl tool
194 Include_dirs []string
195
196 // Directories rooted at the Android.bp file to pass to aidl tool
197 Local_include_dirs []string
198 }
Nan Zhang357466b2018-04-17 17:38:36 -0700199
200 // If not blank, set the java version passed to javadoc as -source
201 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700202
203 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800204 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700205
206 // user customized droiddoc args.
207 // Available variables for substitution:
208 //
209 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700210 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700211 Args *string
212
213 // names of the output files used in args that will be generated
214 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800215}
216
Nan Zhang61819ce2018-05-04 18:49:16 -0700217type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900218 // path to the API txt file that the new API extracted from source code is checked
219 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800220 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700221
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900222 // path to the API txt file that the new @removed API extractd from source code is
223 // checked against. The path can be local to the module or from other module (via
224 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800225 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700226
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900227 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700228 Args *string
229}
230
Nan Zhang581fd212018-01-10 16:06:12 -0800231type DroiddocProperties struct {
232 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800233 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800234
Nan Zhanga40da042018-08-01 12:48:00 -0700235 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800237
238 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800239 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800240
241 // proofread file contains all of the text content of the javadocs concatenated into one file,
242 // suitable for spell-checking and other goodness.
Colin Cross27b922f2019-03-04 22:35:41 -0800243 Proofread_file *string `android:"path"`
Nan Zhang581fd212018-01-10 16:06:12 -0800244
245 // a todo file lists the program elements that are missing documentation.
246 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800247 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800248
249 // directory under current module source that provide additional resources (images).
250 Resourcesdir *string
251
252 // resources output directory under out/soong/.intermediates.
253 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800254
Nan Zhange2ba5d42018-07-11 15:16:55 -0700255 // if set to true, collect the values used by the Dev tools and
256 // write them in files packaged with the SDK. Defaults to false.
257 Write_sdk_values *bool
258
259 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800260 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700261
262 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800263 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700264
Nan Zhang581fd212018-01-10 16:06:12 -0800265 // a list of files under current module source dir which contains known tags in Java sources.
266 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800267 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700268
269 // the tag name used to distinguish if the API files belong to public/system/test.
270 Api_tag_name *string
271
272 // the generated public API filename by Doclava.
273 Api_filename *string
274
David Brazdilfbe4cc32018-05-31 13:56:46 +0100275 // the generated public Dex API filename by Doclava.
276 Dex_api_filename *string
277
Nan Zhang28c68b92018-03-13 16:17:01 -0700278 // the generated private API filename by Doclava.
279 Private_api_filename *string
280
281 // the generated private Dex API filename by Doclava.
282 Private_dex_api_filename *string
283
284 // the generated removed API filename by Doclava.
285 Removed_api_filename *string
286
David Brazdilaac0c3c2018-04-24 16:23:29 +0100287 // the generated removed Dex API filename by Doclava.
288 Removed_dex_api_filename *string
289
Mathew Inwood76c3de12018-06-22 15:28:11 +0100290 // mapping of dex signatures to source file and line number. This is a temporary property and
291 // will be deleted; you probably shouldn't be using it.
292 Dex_mapping_filename *string
293
Nan Zhang28c68b92018-03-13 16:17:01 -0700294 // the generated exact API filename by Doclava.
295 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700296
Nan Zhang66dc2362018-08-14 20:41:04 -0700297 // the generated proguard filename by Doclava.
298 Proguard_filename *string
299
Nan Zhang853f4202018-04-12 16:55:56 -0700300 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
301 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700302
303 Check_api struct {
304 Last_released ApiToCheck
305
306 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900307
308 // do not perform API check against Last_released, in the case that both two specified API
309 // files by Last_released are modules which don't exist.
310 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700311 }
Nan Zhang79614d12018-04-19 18:03:39 -0700312
Nan Zhang1598a9e2018-09-04 17:14:32 -0700313 // if set to true, generate docs through Dokka instead of Doclava.
314 Dokka_enabled *bool
315}
316
317type DroidstubsProperties struct {
318 // the tag name used to distinguish if the API files belong to public/system/test.
319 Api_tag_name *string
320
Nan Zhang199645c2018-09-19 12:40:06 -0700321 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700322 Api_filename *string
323
Nan Zhang199645c2018-09-19 12:40:06 -0700324 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700325 Dex_api_filename *string
326
Nan Zhang199645c2018-09-19 12:40:06 -0700327 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700328 Private_api_filename *string
329
Nan Zhang199645c2018-09-19 12:40:06 -0700330 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700331 Private_dex_api_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Removed_api_filename *string
335
Nan Zhang199645c2018-09-19 12:40:06 -0700336 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700337 Removed_dex_api_filename *string
338
Nan Zhang9c69a122018-08-22 10:22:08 -0700339 // mapping of dex signatures to source file and line number. This is a temporary property and
340 // will be deleted; you probably shouldn't be using it.
341 Dex_mapping_filename *string
342
Nan Zhang199645c2018-09-19 12:40:06 -0700343 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700344 Exact_api_filename *string
345
Nan Zhang199645c2018-09-19 12:40:06 -0700346 // the generated proguard filename by Metalava.
347 Proguard_filename *string
348
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349 Check_api struct {
350 Last_released ApiToCheck
351
352 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900353
354 // do not perform API check against Last_released, in the case that both two specified API
355 // files by Last_released are modules which don't exist.
356 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700357 }
Nan Zhang79614d12018-04-19 18:03:39 -0700358
359 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800360 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700361
362 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700363 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700364
Pete Gillin77167902018-09-19 18:16:26 +0100365 // 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 -0700366 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700367
Pete Gillin77167902018-09-19 18:16:26 +0100368 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
369 Merge_inclusion_annotations_dirs []string
370
Pete Gillinc382a562018-11-14 18:45:46 +0000371 // a file containing a list of classes to do nullability validation for.
372 Validate_nullability_from_list *string
373
Pete Gillin581d6082018-10-22 15:55:04 +0100374 // a file containing expected warnings produced by validation of nullability annotations.
375 Check_nullability_warnings *string
376
Nan Zhang1598a9e2018-09-04 17:14:32 -0700377 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
378 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700379
380 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
381 Api_levels_annotations_enabled *bool
382
383 // the dirs which Metalava extracts API levels annotations from.
384 Api_levels_annotations_dirs []string
385
386 // if set to true, collect the values used by the Dev tools and
387 // write them in files packaged with the SDK. Defaults to false.
388 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700389
390 // If set to true, .xml based public API file will be also generated, and
391 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
392 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800393}
394
Nan Zhanga40da042018-08-01 12:48:00 -0700395//
396// Common flags passed down to build rule
397//
398type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700399 bootClasspathArgs string
400 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700401 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700402 dokkaClasspathArgs string
403 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700404 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700405
Nan Zhanga40da042018-08-01 12:48:00 -0700406 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700407 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700408 postDoclavaCmds string
409
Nan Zhang9c69a122018-08-22 10:22:08 -0700410 metalavaStubsFlags string
411 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800412 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100413 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700414 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700415
Nan Zhang71bbe632018-09-17 14:32:21 -0700416 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700417}
418
419func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
420 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
421 android.InitDefaultableModule(module)
422}
423
Nan Zhang1598a9e2018-09-04 17:14:32 -0700424func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
425 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
426 return true
427 } else if String(apiToCheck.Api_file) != "" {
428 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
429 } else if String(apiToCheck.Removed_api_file) != "" {
430 panic("for " + apiVersionTag + " api_file has to be non-empty!")
431 }
432
433 return false
434}
435
Inseob Kim38449af2019-02-28 14:24:05 +0900436func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
437 api_file := String(apiToCheck.Api_file)
438 removed_api_file := String(apiToCheck.Removed_api_file)
439
440 api_module := android.SrcIsModule(api_file)
441 removed_api_module := android.SrcIsModule(removed_api_file)
442
443 if api_module == "" || removed_api_module == "" {
444 return
445 }
446
447 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
448 return
449 }
450
451 apiToCheck.Api_file = nil
452 apiToCheck.Removed_api_file = nil
453}
454
Nan Zhang1598a9e2018-09-04 17:14:32 -0700455type ApiFilePath interface {
456 ApiFilePath() android.Path
457}
458
459func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
460 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
461 ctx.Build(pctx, android.BuildParams{
462 Rule: updateApi,
463 Description: "Update API",
464 Output: output,
465 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
466 destApiFile, destRemovedApiFile),
467 Args: map[string]string{
468 "destApiFile": destApiFile.String(),
469 "srcApiFile": srcApiFile.String(),
470 "destRemovedApiFile": destRemovedApiFile.String(),
471 "srcRemovedApiFile": srcRemovedApiFile.String(),
472 },
473 })
474}
475
Nan Zhanga40da042018-08-01 12:48:00 -0700476//
477// Javadoc
478//
Nan Zhang581fd212018-01-10 16:06:12 -0800479type Javadoc struct {
480 android.ModuleBase
481 android.DefaultableModuleBase
482
483 properties JavadocProperties
484
485 srcJars android.Paths
486 srcFiles android.Paths
487 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700488 argFiles android.Paths
489
490 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800491
Nan Zhangccff0f72018-03-08 17:26:16 -0800492 docZip android.WritablePath
493 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800494}
495
Colin Cross41955e82019-05-29 14:40:35 -0700496func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
497 switch tag {
498 case "":
499 return android.Paths{j.stubsSrcJar}, nil
500 default:
501 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
502 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800503}
504
Nan Zhang581fd212018-01-10 16:06:12 -0800505func JavadocFactory() android.Module {
506 module := &Javadoc{}
507
508 module.AddProperties(&module.properties)
509
510 InitDroiddocModule(module, android.HostAndDeviceSupported)
511 return module
512}
513
514func JavadocHostFactory() android.Module {
515 module := &Javadoc{}
516
517 module.AddProperties(&module.properties)
518
519 InitDroiddocModule(module, android.HostSupported)
520 return module
521}
522
Colin Cross41955e82019-05-29 14:40:35 -0700523var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800524
Colin Cross83bb3162018-06-25 15:48:06 -0700525func (j *Javadoc) sdkVersion() string {
526 return String(j.properties.Sdk_version)
527}
528
529func (j *Javadoc) minSdkVersion() string {
530 return j.sdkVersion()
531}
532
Dan Willemsen419290a2018-10-31 15:28:47 -0700533func (j *Javadoc) targetSdkVersion() string {
534 return j.sdkVersion()
535}
536
Paul Duffin250e6192019-06-07 10:44:37 +0100537func (j *Javadoc) noFrameworkLibs() bool {
538 return Bool(j.properties.No_framework_libs)
539}
540
Nan Zhang581fd212018-01-10 16:06:12 -0800541func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
542 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100543 sdkDep := decodeSdkDep(ctx, sdkContext(j))
544 if sdkDep.hasStandardLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700545 if sdkDep.useDefaultLibs {
546 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
547 if ctx.Config().TargetOpenJDK9() {
548 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
549 }
Paul Duffin250e6192019-06-07 10:44:37 +0100550 if sdkDep.hasFrameworkLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700551 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
552 }
553 } else if sdkDep.useModule {
554 if ctx.Config().TargetOpenJDK9() {
555 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
556 }
557 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700558 }
Nan Zhang581fd212018-01-10 16:06:12 -0800559 }
560 }
561
Colin Cross42d48b72018-08-29 14:10:52 -0700562 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700563 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700564 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700565 }
Nan Zhang581fd212018-01-10 16:06:12 -0800566}
567
Nan Zhangb2b33de2018-02-23 11:18:47 -0800568func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
569 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
570 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900571 // convert foo.bar.baz to foo/bar/baz
572 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
573 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800574 if _, found := whitelistPathPrefixes[prefix]; !found {
575 whitelistPathPrefixes[prefix] = true
576 }
577 }
578 }
579}
580
Nan Zhanga40da042018-08-01 12:48:00 -0700581func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
582 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900583
Colin Cross3047fa22019-04-18 10:56:44 -0700584 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900585
586 return flags
587}
588
589func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700590 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900591
592 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
593 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
594
595 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700596 var deps android.Paths
597
Jiyong Park1e440682018-05-23 18:42:04 +0900598 if aidlPreprocess.Valid() {
599 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700600 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900601 } else {
602 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
603 }
604
605 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
606 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
607 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
608 flags = append(flags, "-I"+src.String())
609 }
610
Colin Cross3047fa22019-04-18 10:56:44 -0700611 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900612}
613
614func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700615 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900616
617 outSrcFiles := make(android.Paths, 0, len(srcFiles))
618
619 for _, srcFile := range srcFiles {
620 switch srcFile.Ext() {
621 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700622 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Jiyong Park1e440682018-05-23 18:42:04 +0900623 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900624 case ".sysprop":
625 javaFile := genSysprop(ctx, srcFile)
626 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900627 default:
628 outSrcFiles = append(outSrcFiles, srcFile)
629 }
630 }
631
632 return outSrcFiles
633}
634
Nan Zhang581fd212018-01-10 16:06:12 -0800635func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
636 var deps deps
637
Colin Cross83bb3162018-06-25 15:48:06 -0700638 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800639 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700640 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800641 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700642 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800643 }
644
645 ctx.VisitDirectDeps(func(module android.Module) {
646 otherName := ctx.OtherModuleName(module)
647 tag := ctx.OtherModuleDependencyTag(module)
648
Colin Cross2d24c1b2018-05-23 10:59:18 -0700649 switch tag {
650 case bootClasspathTag:
651 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800652 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700653 } else {
654 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
655 }
656 case libTag:
657 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800658 case SdkLibraryDependency:
659 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700660 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900661 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700662 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800663 checkProducesJars(ctx, dep)
664 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800665 default:
666 ctx.ModuleErrorf("depends on non-java module %q", otherName)
667 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700668 case srcsLibTag:
669 switch dep := module.(type) {
670 case Dependency:
671 srcs := dep.(SrcDependency).CompiledSrcs()
672 whitelistPathPrefixes := make(map[string]bool)
673 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
674 for _, src := range srcs {
675 if _, ok := src.(android.WritablePath); ok { // generated sources
676 deps.srcs = append(deps.srcs, src)
677 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700678 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700679 if strings.HasPrefix(src.Rel(), k) {
680 deps.srcs = append(deps.srcs, src)
681 break
682 }
683 }
684 }
685 }
686 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
687 default:
688 ctx.ModuleErrorf("depends on non-java module %q", otherName)
689 }
Nan Zhang357466b2018-04-17 17:38:36 -0700690 case systemModulesTag:
691 if deps.systemModules != nil {
692 panic("Found two system module dependencies")
693 }
694 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000695 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700696 panic("Missing directory for system module dependency")
697 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000698 deps.systemModules = sm.outputDir
699 deps.systemModulesDeps = sm.outputDeps
Nan Zhang581fd212018-01-10 16:06:12 -0800700 }
701 })
702 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
703 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800704 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700705 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900706 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800707
708 // srcs may depend on some genrule output.
709 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800710 j.srcJars = append(j.srcJars, deps.srcJars...)
711
Nan Zhang581fd212018-01-10 16:06:12 -0800712 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800713 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800714
715 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800716 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800717
Nan Zhang9c69a122018-08-22 10:22:08 -0700718 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800719 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
720 }
721 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800722
Colin Cross8a497952019-03-05 22:25:09 -0800723 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000724 argFilesMap := map[string]string{}
725 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700726
Paul Duffin99e4a502019-02-11 15:38:42 +0000727 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800728 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000729 if _, exists := argFilesMap[label]; !exists {
730 argFilesMap[label] = strings.Join(paths.Strings(), " ")
731 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700732 } else {
733 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000734 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700735 }
736 }
737
738 var err error
739 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
740 if strings.HasPrefix(name, "location ") {
741 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000742 if paths, ok := argFilesMap[label]; ok {
743 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700744 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000745 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
746 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700747 }
748 } else if name == "genDir" {
749 return android.PathForModuleGen(ctx).String(), nil
750 }
751 return "", fmt.Errorf("unknown variable '$(%s)'", name)
752 })
753
754 if err != nil {
755 ctx.PropertyErrorf("args", "%s", err.Error())
756 }
757
Nan Zhang581fd212018-01-10 16:06:12 -0800758 return deps
759}
760
761func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
762 j.addDeps(ctx)
763}
764
765func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
766 deps := j.collectDeps(ctx)
767
768 var implicits android.Paths
769 implicits = append(implicits, deps.bootClasspath...)
770 implicits = append(implicits, deps.classpath...)
771
Nan Zhang1598a9e2018-09-04 17:14:32 -0700772 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700773
Colin Cross83bb3162018-06-25 15:48:06 -0700774 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700775 if len(deps.bootClasspath) > 0 {
776 var systemModules classpath
777 if deps.systemModules != nil {
778 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800779 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000780 implicits = append(implicits, deps.systemModulesDeps...)
Colin Cross997262f2018-06-19 22:49:39 -0700781 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
782 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800783 }
784 if len(deps.classpath.Strings()) > 0 {
785 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
786 }
787
788 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700789 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800790
Nan Zhangaf322cc2018-06-19 15:15:38 -0700791 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800792
Nan Zhang1598a9e2018-09-04 17:14:32 -0700793 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
794
Nan Zhang581fd212018-01-10 16:06:12 -0800795 ctx.Build(pctx, android.BuildParams{
796 Rule: javadoc,
797 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800798 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800799 ImplicitOutput: j.docZip,
800 Inputs: j.srcFiles,
801 Implicits: implicits,
802 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700803 "outDir": android.PathForModuleOut(ctx, "out").String(),
804 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
805 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800806 "srcJars": strings.Join(j.srcJars.Strings(), " "),
807 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700808 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800809 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700810 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800811 "docZip": j.docZip.String(),
812 },
813 })
814}
815
Nan Zhanga40da042018-08-01 12:48:00 -0700816//
817// Droiddoc
818//
819type Droiddoc struct {
820 Javadoc
821
822 properties DroiddocProperties
823 apiFile android.WritablePath
824 dexApiFile android.WritablePath
825 privateApiFile android.WritablePath
826 privateDexApiFile android.WritablePath
827 removedApiFile android.WritablePath
828 removedDexApiFile android.WritablePath
829 exactApiFile android.WritablePath
830 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700831 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700832
833 checkCurrentApiTimestamp android.WritablePath
834 updateCurrentApiTimestamp android.WritablePath
835 checkLastReleasedApiTimestamp android.WritablePath
836
Nan Zhanga40da042018-08-01 12:48:00 -0700837 apiFilePath android.Path
838}
839
Nan Zhanga40da042018-08-01 12:48:00 -0700840func DroiddocFactory() android.Module {
841 module := &Droiddoc{}
842
843 module.AddProperties(&module.properties,
844 &module.Javadoc.properties)
845
846 InitDroiddocModule(module, android.HostAndDeviceSupported)
847 return module
848}
849
850func DroiddocHostFactory() android.Module {
851 module := &Droiddoc{}
852
853 module.AddProperties(&module.properties,
854 &module.Javadoc.properties)
855
856 InitDroiddocModule(module, android.HostSupported)
857 return module
858}
859
860func (d *Droiddoc) ApiFilePath() android.Path {
861 return d.apiFilePath
862}
863
Nan Zhang581fd212018-01-10 16:06:12 -0800864func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
865 d.Javadoc.addDeps(ctx)
866
Inseob Kim38449af2019-02-28 14:24:05 +0900867 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
868 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
869 }
870
Nan Zhang79614d12018-04-19 18:03:39 -0700871 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800872 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
873 }
Nan Zhang581fd212018-01-10 16:06:12 -0800874}
875
Nan Zhang66dc2362018-08-14 20:41:04 -0700876func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
877 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700878 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800879
Nan Zhanga40da042018-08-01 12:48:00 -0700880 *implicits = append(*implicits, deps.bootClasspath...)
881 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800882
Nan Zhangc94f9d82018-06-26 10:02:26 -0700883 if len(deps.bootClasspath.Strings()) > 0 {
884 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700885 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700886 }
Nan Zhanga40da042018-08-01 12:48:00 -0700887 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700888 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700889 dokkaClasspath := classpath{}
890 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
891 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
892 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700893
Nan Zhang9c69a122018-08-22 10:22:08 -0700894 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
895 // based stubs generation.
896 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
897 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
898 // the correct package name base path.
899 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
900 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
901 } else {
902 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
903 }
Nan Zhang581fd212018-01-10 16:06:12 -0800904
Nan Zhanga40da042018-08-01 12:48:00 -0700905 return flags, nil
906}
Nan Zhang581fd212018-01-10 16:06:12 -0800907
Nan Zhanga40da042018-08-01 12:48:00 -0700908func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700909 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800910
Nan Zhanga40da042018-08-01 12:48:00 -0700911 *implicits = append(*implicits, jsilver)
912 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700913
Nan Zhang46130972018-06-04 11:28:01 -0700914 var date string
915 if runtime.GOOS == "darwin" {
916 date = `date -r`
917 } else {
918 date = `date -d`
919 }
920
Nan Zhang443fa522018-08-20 20:58:28 -0700921 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
922 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
923 // 1.9 language features.
924 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700925 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800926 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700927 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700928
Nan Zhanga40da042018-08-01 12:48:00 -0700929 if String(d.properties.Custom_template) == "" {
930 // TODO: This is almost always droiddoc-templates-sdk
931 ctx.PropertyErrorf("custom_template", "must specify a template")
932 }
933
934 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700935 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700936 *implicits = append(*implicits, t.deps...)
937 args = args + " -templatedir " + t.dir.String()
938 } else {
939 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
940 }
941 })
942
943 if len(d.properties.Html_dirs) > 0 {
Colin Cross07e51612019-03-05 12:46:40 -0800944 htmlDir := d.properties.Html_dirs[0]
Colin Cross8a497952019-03-05 22:25:09 -0800945 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800946 args = args + " -htmldir " + htmlDir
Nan Zhanga40da042018-08-01 12:48:00 -0700947 }
948
949 if len(d.properties.Html_dirs) > 1 {
Colin Cross07e51612019-03-05 12:46:40 -0800950 htmlDir2 := d.properties.Html_dirs[1]
Colin Cross8a497952019-03-05 22:25:09 -0800951 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800952 args = args + " -htmldir2 " + htmlDir2
Nan Zhanga40da042018-08-01 12:48:00 -0700953 }
954
955 if len(d.properties.Html_dirs) > 2 {
956 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
957 }
958
Colin Cross8a497952019-03-05 22:25:09 -0800959 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Nan Zhanga40da042018-08-01 12:48:00 -0700960 *implicits = append(*implicits, knownTags...)
961
962 for _, kt := range knownTags {
963 args = args + " -knowntags " + kt.String()
964 }
965
966 for _, hdf := range d.properties.Hdf {
967 args = args + " -hdf " + hdf
968 }
969
970 if String(d.properties.Proofread_file) != "" {
971 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
972 args = args + " -proofread " + proofreadFile.String()
973 }
974
975 if String(d.properties.Todo_file) != "" {
976 // tricky part:
977 // we should not compute full path for todo_file through PathForModuleOut().
978 // the non-standard doclet will get the full path relative to "-o".
979 args = args + " -todo " + String(d.properties.Todo_file)
980 }
981
982 if String(d.properties.Resourcesdir) != "" {
983 // TODO: should we add files under resourcesDir to the implicits? It seems that
984 // resourcesDir is one sub dir of htmlDir
985 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
986 args = args + " -resourcesdir " + resourcesDir.String()
987 }
988
989 if String(d.properties.Resourcesoutdir) != "" {
990 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
991 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
992 }
993 return args
994}
995
Nan Zhang1598a9e2018-09-04 17:14:32 -0700996func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
997 implicitOutputs *android.WritablePaths) string {
998 var doclavaFlags string
999 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1000 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1001 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001002 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1003 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001004 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1005 d.apiFilePath = d.apiFile
1006 }
1007
Nan Zhang1598a9e2018-09-04 17:14:32 -07001008 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1009 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1010 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001011 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1012 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001013 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1014 }
1015
1016 if String(d.properties.Private_api_filename) != "" {
1017 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1018 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001019 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1020 }
1021
1022 if String(d.properties.Dex_api_filename) != "" {
1023 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1024 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1025 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1026 }
1027
1028 if String(d.properties.Private_dex_api_filename) != "" {
1029 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1030 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001031 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1032 }
1033
1034 if String(d.properties.Removed_dex_api_filename) != "" {
1035 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1036 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001037 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1038 }
1039
1040 if String(d.properties.Exact_api_filename) != "" {
1041 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1042 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001043 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1044 }
1045
1046 if String(d.properties.Dex_mapping_filename) != "" {
1047 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1048 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001049 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1050 }
1051
Nan Zhang66dc2362018-08-14 20:41:04 -07001052 if String(d.properties.Proguard_filename) != "" {
1053 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1054 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001055 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1056 }
1057
Nan Zhanga40da042018-08-01 12:48:00 -07001058 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001059 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001060 }
1061
1062 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001063 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001064 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001065
1066 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001067}
1068
1069func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1070 var cmds string
1071 if String(d.properties.Static_doc_index_redirect) != "" {
1072 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1073 "static_doc_index_redirect")
1074 *implicits = append(*implicits, static_doc_index_redirect)
1075 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001076 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001077 }
1078
1079 if String(d.properties.Static_doc_properties) != "" {
1080 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1081 "static_doc_properties")
1082 *implicits = append(*implicits, static_doc_properties)
1083 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001084 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001085 }
1086 return cmds
1087}
1088
Nan Zhang1598a9e2018-09-04 17:14:32 -07001089func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1090 implicitOutputs android.WritablePaths,
1091 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1092 ctx.Build(pctx, android.BuildParams{
1093 Rule: javadoc,
1094 Description: "Doclava",
1095 Output: d.Javadoc.stubsSrcJar,
1096 Inputs: d.Javadoc.srcFiles,
1097 Implicits: implicits,
1098 ImplicitOutputs: implicitOutputs,
1099 Args: map[string]string{
1100 "outDir": android.PathForModuleOut(ctx, "out").String(),
1101 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1102 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1103 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1104 "opts": opts,
1105 "bootclasspathArgs": bootclasspathArgs,
1106 "classpathArgs": classpathArgs,
1107 "sourcepathArgs": sourcepathArgs,
1108 "docZip": d.Javadoc.docZip.String(),
1109 "postDoclavaCmds": postDoclavaCmds,
1110 },
1111 })
1112}
1113
1114func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1115 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1116 ctx.Build(pctx, android.BuildParams{
1117 Rule: apiCheck,
1118 Description: "Doclava Check API",
1119 Output: output,
1120 Inputs: nil,
1121 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1122 checkApiClasspath...),
1123 Args: map[string]string{
1124 "msg": msg,
1125 "classpath": checkApiClasspath.FormJavaClassPath(""),
1126 "opts": opts,
1127 "apiFile": apiFile.String(),
1128 "apiFileToCheck": d.apiFile.String(),
1129 "removedApiFile": removedApiFile.String(),
1130 "removedApiFileToCheck": d.removedApiFile.String(),
1131 },
1132 })
1133}
1134
1135func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1136 classpathArgs, opts string) {
1137 ctx.Build(pctx, android.BuildParams{
1138 Rule: dokka,
1139 Description: "Dokka",
1140 Output: d.Javadoc.stubsSrcJar,
1141 Inputs: d.Javadoc.srcFiles,
1142 Implicits: implicits,
1143 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001144 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1145 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1146 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001147 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1148 "classpathArgs": classpathArgs,
1149 "opts": opts,
1150 "docZip": d.Javadoc.docZip.String(),
1151 },
1152 })
1153}
1154
1155func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1156 deps := d.Javadoc.collectDeps(ctx)
1157
1158 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1159 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1160 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1161 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1162
1163 var implicits android.Paths
1164 implicits = append(implicits, d.Javadoc.srcJars...)
1165 implicits = append(implicits, d.Javadoc.argFiles...)
1166
1167 var implicitOutputs android.WritablePaths
1168 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1169 for _, o := range d.Javadoc.properties.Out {
1170 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1171 }
1172
1173 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1174 if err != nil {
1175 return
1176 }
1177
1178 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1179 if Bool(d.properties.Dokka_enabled) {
1180 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1181 } else {
1182 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1183 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1184 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1185 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1186 flags.postDoclavaCmds)
1187 }
1188
1189 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1190 !ctx.Config().IsPdkBuild() {
1191 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1192 "check_api.current.api_file")
1193 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1194 "check_api.current_removed_api_file")
1195
1196 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1197 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1198 fmt.Sprintf(`\n******************************\n`+
1199 `You have tried to change the API from what has been previously approved.\n\n`+
1200 `To make these errors go away, you have two choices:\n`+
1201 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1202 ` errors above.\n\n`+
1203 ` 2. You can update current.txt by executing the following command:\n`+
1204 ` make %s-update-current-api\n\n`+
1205 ` To submit the revised current.txt to the main Android repository,\n`+
1206 ` you will need approval.\n`+
1207 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1208 d.checkCurrentApiTimestamp)
1209
1210 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1211 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1212 d.updateCurrentApiTimestamp)
1213 }
1214
1215 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1216 !ctx.Config().IsPdkBuild() {
1217 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1218 "check_api.last_released.api_file")
1219 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1220 "check_api.last_released.removed_api_file")
1221
1222 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1223 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1224 `\n******************************\n`+
1225 `You have tried to change the API from what has been previously released in\n`+
1226 `an SDK. Please fix the errors listed above.\n`+
1227 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1228 d.checkLastReleasedApiTimestamp)
1229 }
1230}
1231
1232//
1233// Droidstubs
1234//
1235type Droidstubs struct {
1236 Javadoc
1237
Pete Gillin581d6082018-10-22 15:55:04 +01001238 properties DroidstubsProperties
1239 apiFile android.WritablePath
1240 apiXmlFile android.WritablePath
1241 lastReleasedApiXmlFile android.WritablePath
1242 dexApiFile android.WritablePath
1243 privateApiFile android.WritablePath
1244 privateDexApiFile android.WritablePath
1245 removedApiFile android.WritablePath
1246 removedDexApiFile android.WritablePath
1247 apiMappingFile android.WritablePath
1248 exactApiFile android.WritablePath
1249 proguardFile android.WritablePath
1250 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251
1252 checkCurrentApiTimestamp android.WritablePath
1253 updateCurrentApiTimestamp android.WritablePath
1254 checkLastReleasedApiTimestamp android.WritablePath
1255
Pete Gillin581d6082018-10-22 15:55:04 +01001256 checkNullabilityWarningsTimestamp android.WritablePath
1257
Nan Zhang1598a9e2018-09-04 17:14:32 -07001258 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001259 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001260
1261 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001262
1263 jdiffDocZip android.WritablePath
1264 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001265}
1266
1267func DroidstubsFactory() android.Module {
1268 module := &Droidstubs{}
1269
1270 module.AddProperties(&module.properties,
1271 &module.Javadoc.properties)
1272
1273 InitDroiddocModule(module, android.HostAndDeviceSupported)
1274 return module
1275}
1276
1277func DroidstubsHostFactory() android.Module {
1278 module := &Droidstubs{}
1279
1280 module.AddProperties(&module.properties,
1281 &module.Javadoc.properties)
1282
1283 InitDroiddocModule(module, android.HostSupported)
1284 return module
1285}
1286
1287func (d *Droidstubs) ApiFilePath() android.Path {
1288 return d.apiFilePath
1289}
1290
1291func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1292 d.Javadoc.addDeps(ctx)
1293
Inseob Kim38449af2019-02-28 14:24:05 +09001294 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1295 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1296 }
1297
Nan Zhang1598a9e2018-09-04 17:14:32 -07001298 if len(d.properties.Merge_annotations_dirs) != 0 {
1299 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1300 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1301 }
1302 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001303
Pete Gillin77167902018-09-19 18:16:26 +01001304 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1305 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1306 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1307 }
1308 }
1309
Nan Zhang9c69a122018-08-22 10:22:08 -07001310 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1311 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1312 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1313 }
1314 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001315}
1316
1317func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1318 deps deps) (droiddocBuilderFlags, error) {
1319 var flags droiddocBuilderFlags
1320
1321 *implicits = append(*implicits, deps.bootClasspath...)
1322 *implicits = append(*implicits, deps.classpath...)
1323
1324 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1325 // since it doesn't support system modules yet.
1326 if len(deps.bootClasspath.Strings()) > 0 {
1327 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1328 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1329 }
1330 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1331
Sundong Ahn56dce442018-10-05 18:41:09 +09001332 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001333 return flags, nil
1334}
1335
1336func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1337 implicitOutputs *android.WritablePaths) string {
1338 var metalavaFlags string
1339 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1340 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1341 String(d.properties.Api_filename) != "" {
1342 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1343 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1344 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1345 d.apiFilePath = d.apiFile
1346 }
1347
1348 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1349 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1350 String(d.properties.Removed_api_filename) != "" {
1351 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1352 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1353 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1354 }
1355
1356 if String(d.properties.Private_api_filename) != "" {
1357 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1358 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1359 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1360 }
1361
1362 if String(d.properties.Dex_api_filename) != "" {
1363 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1364 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1365 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1366 }
1367
1368 if String(d.properties.Private_dex_api_filename) != "" {
1369 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1370 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1371 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1372 }
1373
1374 if String(d.properties.Removed_dex_api_filename) != "" {
1375 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1376 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1377 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1378 }
1379
1380 if String(d.properties.Exact_api_filename) != "" {
1381 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1382 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1383 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1384 }
1385
Nan Zhang9c69a122018-08-22 10:22:08 -07001386 if String(d.properties.Dex_mapping_filename) != "" {
1387 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1388 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1389 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1390 }
1391
Nan Zhang199645c2018-09-19 12:40:06 -07001392 if String(d.properties.Proguard_filename) != "" {
1393 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1394 metalavaFlags += " --proguard " + d.proguardFile.String()
1395 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1396 }
1397
Nan Zhang9c69a122018-08-22 10:22:08 -07001398 if Bool(d.properties.Write_sdk_values) {
1399 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1400 }
1401
Nan Zhang1598a9e2018-09-04 17:14:32 -07001402 if Bool(d.properties.Create_doc_stubs) {
1403 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1404 } else {
1405 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1406 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001407 return metalavaFlags
1408}
1409
1410func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001411 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1412 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001413 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001414 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001415 validatingNullability :=
1416 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1417 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001418 migratingNullability := String(d.properties.Previous_api) != ""
1419 if !(migratingNullability || validatingNullability) {
1420 ctx.PropertyErrorf("previous_api",
1421 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001422 }
Pete Gillina262c052018-09-14 14:25:48 +01001423 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001424 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Pete Gillina262c052018-09-14 14:25:48 +01001425 *implicits = append(*implicits, previousApi)
1426 flags += " --migrate-nullness " + previousApi.String()
1427 }
Pete Gillinc382a562018-11-14 18:45:46 +00001428 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross8a497952019-03-05 22:25:09 -08001429 flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String()
Pete Gillinc382a562018-11-14 18:45:46 +00001430 }
Pete Gillina262c052018-09-14 14:25:48 +01001431 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001432 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1433 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1434 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001435 }
Nan Zhanga40da042018-08-01 12:48:00 -07001436
1437 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1438 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1439
Nan Zhangf4936b02018-08-01 15:00:28 -07001440 flags += " --extract-annotations " + d.annotationsZip.String()
1441
Nan Zhang1598a9e2018-09-04 17:14:32 -07001442 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001443 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001444 "has to be non-empty if annotations was enabled!")
1445 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001446 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1447 if t, ok := m.(*ExportedDroiddocDir); ok {
1448 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001449 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001450 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001451 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001452 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1453 }
1454 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001455 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001456 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001457 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001458 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001459
Nan Zhangdee152b2018-12-26 16:06:37 -08001460 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001461}
1462
1463func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1464 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1465 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001466 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1467 if t, ok := m.(*ExportedDroiddocDir); ok {
1468 *implicits = append(*implicits, t.deps...)
1469 flags += " --merge-inclusion-annotations " + t.dir.String()
1470 } else {
1471 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1472 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1473 }
1474 })
Nan Zhanga40da042018-08-01 12:48:00 -07001475
1476 return flags
1477}
1478
Nan Zhang9c69a122018-08-22 10:22:08 -07001479func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1480 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1481 var flags string
1482 if Bool(d.properties.Api_levels_annotations_enabled) {
1483 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1484 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1485
1486 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1487 ctx.PropertyErrorf("api_levels_annotations_dirs",
1488 "has to be non-empty if api levels annotations was enabled!")
1489 }
1490
1491 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1492 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1493 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1494
1495 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1496 if t, ok := m.(*ExportedDroiddocDir); ok {
1497 var androidJars android.Paths
1498 for _, dep := range t.deps {
1499 if strings.HasSuffix(dep.String(), "android.jar") {
1500 androidJars = append(androidJars, dep)
1501 }
1502 }
1503 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001504 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001505 } else {
1506 ctx.PropertyErrorf("api_levels_annotations_dirs",
1507 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1508 }
1509 })
1510
1511 }
1512
1513 return flags
1514}
1515
Nan Zhang71bbe632018-09-17 14:32:21 -07001516func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1517 implicitOutputs *android.WritablePaths) string {
1518 var flags string
1519 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1520 if d.apiFile.String() == "" {
1521 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1522 }
1523
1524 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1525 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1526
1527 flags = " --api-xml " + d.apiXmlFile.String()
1528
1529 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1530 ctx.PropertyErrorf("check_api.last_released.api_file",
1531 "has to be non-empty if jdiff was enabled!")
1532 }
1533 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1534 "check_api.last_released.api_file")
1535 *implicits = append(*implicits, lastReleasedApi)
1536
1537 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1538 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1539
1540 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1541 d.lastReleasedApiXmlFile.String()
1542 }
1543
1544 return flags
1545}
1546
Nan Zhang1598a9e2018-09-04 17:14:32 -07001547func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1548 implicitOutputs android.WritablePaths, javaVersion,
1549 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001550
Nan Zhang86d2d552018-08-09 15:33:27 -07001551 ctx.Build(pctx, android.BuildParams{
1552 Rule: metalava,
1553 Description: "Metalava",
1554 Output: d.Javadoc.stubsSrcJar,
1555 Inputs: d.Javadoc.srcFiles,
1556 Implicits: implicits,
1557 ImplicitOutputs: implicitOutputs,
1558 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001559 "outDir": android.PathForModuleOut(ctx, "out").String(),
1560 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1561 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1562 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001563 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001564 "bootclasspathArgs": bootclasspathArgs,
1565 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001566 "sourcepathArgs": sourcepathArgs,
1567 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001568 },
1569 })
1570}
1571
Nan Zhang1598a9e2018-09-04 17:14:32 -07001572func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1573 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001574 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001575 output android.WritablePath) {
1576 ctx.Build(pctx, android.BuildParams{
1577 Rule: metalavaApiCheck,
1578 Description: "Metalava Check API",
1579 Output: output,
1580 Inputs: d.Javadoc.srcFiles,
1581 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1582 implicits...),
1583 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001584 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001585 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1586 "javaVersion": javaVersion,
1587 "bootclasspathArgs": bootclasspathArgs,
1588 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001589 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001590 "opts": opts,
1591 "msg": msg,
1592 },
1593 })
1594}
1595
Nan Zhang71bbe632018-09-17 14:32:21 -07001596func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1597 implicitOutputs android.WritablePaths,
1598 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1599 ctx.Build(pctx, android.BuildParams{
1600 Rule: javadoc,
1601 Description: "Jdiff",
1602 Output: d.jdiffStubsSrcJar,
1603 Inputs: d.Javadoc.srcFiles,
1604 Implicits: implicits,
1605 ImplicitOutputs: implicitOutputs,
1606 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001607 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1608 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1609 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001610 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1611 "opts": opts,
1612 "bootclasspathArgs": bootclasspathArgs,
1613 "classpathArgs": classpathArgs,
1614 "sourcepathArgs": sourcepathArgs,
1615 "docZip": d.jdiffDocZip.String(),
1616 },
1617 })
1618}
1619
Nan Zhang1598a9e2018-09-04 17:14:32 -07001620func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001621 deps := d.Javadoc.collectDeps(ctx)
1622
1623 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001624
Nan Zhanga40da042018-08-01 12:48:00 -07001625 var implicits android.Paths
1626 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001627 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001628
1629 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001630 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001631 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1632 }
1633
1634 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001635 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001636 jdiffImplicits := implicits
1637
Nan Zhanga40da042018-08-01 12:48:00 -07001638 if err != nil {
1639 return
1640 }
1641
Nan Zhang1598a9e2018-09-04 17:14:32 -07001642 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001643 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1644 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001645 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001646 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001647 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1648
Nan Zhang1598a9e2018-09-04 17:14:32 -07001649 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1650 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1651 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1652 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1653 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001654 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001655 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1656 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001657 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001658 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001659
Nan Zhang1598a9e2018-09-04 17:14:32 -07001660 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1661 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001662 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1663 "check_api.current.api_file")
1664 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1665 "check_api.current_removed_api_file")
1666
Nan Zhang2760dfc2018-08-24 17:32:54 +00001667 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001668 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1669 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001670 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001671
Nan Zhang1598a9e2018-09-04 17:14:32 -07001672 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001673 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001674 fmt.Sprintf(`\n******************************\n`+
1675 `You have tried to change the API from what has been previously approved.\n\n`+
1676 `To make these errors go away, you have two choices:\n`+
1677 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1678 ` errors above.\n\n`+
1679 ` 2. You can update current.txt by executing the following command:\n`+
1680 ` make %s-update-current-api\n\n`+
1681 ` To submit the revised current.txt to the main Android repository,\n`+
1682 ` you will need approval.\n`+
1683 `******************************\n`, ctx.ModuleName()),
1684 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001685
1686 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001687 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1688 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001689 }
Nan Zhanga40da042018-08-01 12:48:00 -07001690
Nan Zhang1598a9e2018-09-04 17:14:32 -07001691 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1692 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001693 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1694 "check_api.last_released.api_file")
1695 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1696 "check_api.last_released.removed_api_file")
1697
Nan Zhang2760dfc2018-08-24 17:32:54 +00001698 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001699 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1700 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001701 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001702
Nan Zhang1598a9e2018-09-04 17:14:32 -07001703 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001704 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001705 `\n******************************\n`+
1706 `You have tried to change the API from what has been previously released in\n`+
1707 `an SDK. Please fix the errors listed above.\n`+
1708 `******************************\n`,
1709 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001710 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001711
Pete Gillin581d6082018-10-22 15:55:04 +01001712 if String(d.properties.Check_nullability_warnings) != "" {
1713 if d.nullabilityWarningsFile == nil {
1714 ctx.PropertyErrorf("check_nullability_warnings",
1715 "Cannot specify check_nullability_warnings unless validating nullability")
1716 }
1717 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1718 "check_nullability_warnings")
1719 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1720 msg := fmt.Sprintf(`\n******************************\n`+
1721 `The warnings encountered during nullability annotation validation did\n`+
1722 `not match the checked in file of expected warnings. The diffs are shown\n`+
1723 `above. You have two options:\n`+
1724 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1725 ` 2. Update the file of expected warnings by running:\n`+
1726 ` cp %s %s\n`+
1727 ` and submitting the updated file as part of your change.`,
1728 d.nullabilityWarningsFile, checkNullabilityWarnings)
1729 ctx.Build(pctx, android.BuildParams{
1730 Rule: nullabilityWarningsCheck,
1731 Description: "Nullability Warnings Check",
1732 Output: d.checkNullabilityWarningsTimestamp,
1733 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1734 Args: map[string]string{
1735 "expected": checkNullabilityWarnings.String(),
1736 "actual": d.nullabilityWarningsFile.String(),
1737 "msg": msg,
1738 },
1739 })
1740 }
1741
Nan Zhang71bbe632018-09-17 14:32:21 -07001742 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1743
Nan Zhang86b06202018-09-21 17:09:21 -07001744 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1745 // since there's cron job downstream that fetch this .zip file periodically.
1746 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001747 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1748 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1749
1750 var jdiffImplicitOutputs android.WritablePaths
1751 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1752
1753 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1754 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1755
Pete Gillin2b1ea2e2019-06-10 14:20:11 +01001756 opts := " -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
Nan Zhang71bbe632018-09-17 14:32:21 -07001757 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1758 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1759 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1760 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1761 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1762
1763 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1764 flags.sourcepathArgs, opts)
1765 }
Nan Zhang581fd212018-01-10 16:06:12 -08001766}
Dan Willemsencc090972018-02-26 14:33:31 -08001767
Nan Zhanga40da042018-08-01 12:48:00 -07001768//
Nan Zhangf4936b02018-08-01 15:00:28 -07001769// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001770//
Dan Willemsencc090972018-02-26 14:33:31 -08001771var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001772var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001773var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001774var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001775
Nan Zhangf4936b02018-08-01 15:00:28 -07001776type ExportedDroiddocDirProperties struct {
1777 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001778 Path *string
1779}
1780
Nan Zhangf4936b02018-08-01 15:00:28 -07001781type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001782 android.ModuleBase
1783
Nan Zhangf4936b02018-08-01 15:00:28 -07001784 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001785
1786 deps android.Paths
1787 dir android.Path
1788}
1789
Nan Zhangf4936b02018-08-01 15:00:28 -07001790func ExportedDroiddocDirFactory() android.Module {
1791 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001792 module.AddProperties(&module.properties)
1793 android.InitAndroidModule(module)
1794 return module
1795}
1796
Nan Zhangf4936b02018-08-01 15:00:28 -07001797func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001798
Nan Zhangf4936b02018-08-01 15:00:28 -07001799func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001800 path := String(d.properties.Path)
1801 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001802 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001803}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001804
1805//
1806// Defaults
1807//
1808type DocDefaults struct {
1809 android.ModuleBase
1810 android.DefaultsModuleBase
1811}
1812
Nan Zhangb2b33de2018-02-23 11:18:47 -08001813func DocDefaultsFactory() android.Module {
1814 module := &DocDefaults{}
1815
1816 module.AddProperties(
1817 &JavadocProperties{},
1818 &DroiddocProperties{},
1819 )
1820
1821 android.InitDefaultsModule(module)
1822
1823 return module
1824}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001825
1826func StubsDefaultsFactory() android.Module {
1827 module := &DocDefaults{}
1828
1829 module.AddProperties(
1830 &JavadocProperties{},
1831 &DroidstubsProperties{},
1832 )
1833
1834 android.InitDefaultsModule(module)
1835
1836 return module
1837}