blob: 734b411a8e17a750fb9e1a427f10d7608dbd05c2 [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
Nan Zhangb2b33de2018-02-23 11:18:47 -0800174 // the java library (in classpath) for documentation that provides java srcs and srcjars.
175 Srcs_lib *string
176
177 // the base dirs under srcs_lib will be scanned for java srcs.
178 Srcs_lib_whitelist_dirs []string
179
180 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
181 Srcs_lib_whitelist_pkgs []string
182
Nan Zhang581fd212018-01-10 16:06:12 -0800183 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800184 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800185
186 // if not blank, set to the version of the sdk to compile against
187 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900188
189 Aidl struct {
190 // Top level directories to pass to aidl tool
191 Include_dirs []string
192
193 // Directories rooted at the Android.bp file to pass to aidl tool
194 Local_include_dirs []string
195 }
Nan Zhang357466b2018-04-17 17:38:36 -0700196
197 // If not blank, set the java version passed to javadoc as -source
198 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700199
200 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800201 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700202
203 // user customized droiddoc args.
204 // Available variables for substitution:
205 //
206 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700207 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700208 Args *string
209
210 // names of the output files used in args that will be generated
211 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800212}
213
Nan Zhang61819ce2018-05-04 18:49:16 -0700214type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900215 // path to the API txt file that the new API extracted from source code is checked
216 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800217 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700218
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900219 // path to the API txt file that the new @removed API extractd from source code is
220 // checked against. The path can be local to the module or from other module (via
221 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800222 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700223
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900224 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700225 Args *string
226}
227
Nan Zhang581fd212018-01-10 16:06:12 -0800228type DroiddocProperties struct {
229 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800230 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800231
Nan Zhanga40da042018-08-01 12:48:00 -0700232 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800233 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800234
235 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800237
238 // proofread file contains all of the text content of the javadocs concatenated into one file,
239 // suitable for spell-checking and other goodness.
Colin Cross27b922f2019-03-04 22:35:41 -0800240 Proofread_file *string `android:"path"`
Nan Zhang581fd212018-01-10 16:06:12 -0800241
242 // a todo file lists the program elements that are missing documentation.
243 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800244 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800245
246 // directory under current module source that provide additional resources (images).
247 Resourcesdir *string
248
249 // resources output directory under out/soong/.intermediates.
250 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800251
Nan Zhange2ba5d42018-07-11 15:16:55 -0700252 // if set to true, collect the values used by the Dev tools and
253 // write them in files packaged with the SDK. Defaults to false.
254 Write_sdk_values *bool
255
256 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800257 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700258
259 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800260 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700261
Nan Zhang581fd212018-01-10 16:06:12 -0800262 // a list of files under current module source dir which contains known tags in Java sources.
263 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800264 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700265
266 // the tag name used to distinguish if the API files belong to public/system/test.
267 Api_tag_name *string
268
269 // the generated public API filename by Doclava.
270 Api_filename *string
271
David Brazdilfbe4cc32018-05-31 13:56:46 +0100272 // the generated public Dex API filename by Doclava.
273 Dex_api_filename *string
274
Nan Zhang28c68b92018-03-13 16:17:01 -0700275 // the generated private API filename by Doclava.
276 Private_api_filename *string
277
278 // the generated private Dex API filename by Doclava.
279 Private_dex_api_filename *string
280
281 // the generated removed API filename by Doclava.
282 Removed_api_filename *string
283
David Brazdilaac0c3c2018-04-24 16:23:29 +0100284 // the generated removed Dex API filename by Doclava.
285 Removed_dex_api_filename *string
286
Mathew Inwood76c3de12018-06-22 15:28:11 +0100287 // mapping of dex signatures to source file and line number. This is a temporary property and
288 // will be deleted; you probably shouldn't be using it.
289 Dex_mapping_filename *string
290
Nan Zhang28c68b92018-03-13 16:17:01 -0700291 // the generated exact API filename by Doclava.
292 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700293
Nan Zhang66dc2362018-08-14 20:41:04 -0700294 // the generated proguard filename by Doclava.
295 Proguard_filename *string
296
Nan Zhang853f4202018-04-12 16:55:56 -0700297 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
298 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700299
300 Check_api struct {
301 Last_released ApiToCheck
302
303 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900304
305 // do not perform API check against Last_released, in the case that both two specified API
306 // files by Last_released are modules which don't exist.
307 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700308 }
Nan Zhang79614d12018-04-19 18:03:39 -0700309
Nan Zhang1598a9e2018-09-04 17:14:32 -0700310 // if set to true, generate docs through Dokka instead of Doclava.
311 Dokka_enabled *bool
312}
313
314type DroidstubsProperties struct {
315 // the tag name used to distinguish if the API files belong to public/system/test.
316 Api_tag_name *string
317
Nan Zhang199645c2018-09-19 12:40:06 -0700318 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700319 Api_filename *string
320
Nan Zhang199645c2018-09-19 12:40:06 -0700321 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700322 Dex_api_filename *string
323
Nan Zhang199645c2018-09-19 12:40:06 -0700324 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700325 Private_api_filename *string
326
Nan Zhang199645c2018-09-19 12:40:06 -0700327 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700328 Private_dex_api_filename *string
329
Nan Zhang199645c2018-09-19 12:40:06 -0700330 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700331 Removed_api_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Removed_dex_api_filename *string
335
Nan Zhang9c69a122018-08-22 10:22:08 -0700336 // mapping of dex signatures to source file and line number. This is a temporary property and
337 // will be deleted; you probably shouldn't be using it.
338 Dex_mapping_filename *string
339
Nan Zhang199645c2018-09-19 12:40:06 -0700340 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700341 Exact_api_filename *string
342
Nan Zhang199645c2018-09-19 12:40:06 -0700343 // the generated proguard filename by Metalava.
344 Proguard_filename *string
345
Nan Zhang1598a9e2018-09-04 17:14:32 -0700346 Check_api struct {
347 Last_released ApiToCheck
348
349 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900350
351 // do not perform API check against Last_released, in the case that both two specified API
352 // files by Last_released are modules which don't exist.
353 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700354 }
Nan Zhang79614d12018-04-19 18:03:39 -0700355
356 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800357 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700358
359 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700360 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700361
Pete Gillin77167902018-09-19 18:16:26 +0100362 // 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 -0700363 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700364
Pete Gillin77167902018-09-19 18:16:26 +0100365 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
366 Merge_inclusion_annotations_dirs []string
367
Pete Gillinc382a562018-11-14 18:45:46 +0000368 // a file containing a list of classes to do nullability validation for.
369 Validate_nullability_from_list *string
370
Pete Gillin581d6082018-10-22 15:55:04 +0100371 // a file containing expected warnings produced by validation of nullability annotations.
372 Check_nullability_warnings *string
373
Nan Zhang1598a9e2018-09-04 17:14:32 -0700374 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
375 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700376
377 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
378 Api_levels_annotations_enabled *bool
379
380 // the dirs which Metalava extracts API levels annotations from.
381 Api_levels_annotations_dirs []string
382
383 // if set to true, collect the values used by the Dev tools and
384 // write them in files packaged with the SDK. Defaults to false.
385 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700386
387 // If set to true, .xml based public API file will be also generated, and
388 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
389 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800390}
391
Nan Zhanga40da042018-08-01 12:48:00 -0700392//
393// Common flags passed down to build rule
394//
395type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700396 bootClasspathArgs string
397 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700398 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700399 dokkaClasspathArgs string
400 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700401 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700402
Nan Zhanga40da042018-08-01 12:48:00 -0700403 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700404 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700405 postDoclavaCmds string
406
Nan Zhang9c69a122018-08-22 10:22:08 -0700407 metalavaStubsFlags string
408 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800409 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100410 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700411 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700412
Nan Zhang71bbe632018-09-17 14:32:21 -0700413 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700414}
415
416func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
417 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
418 android.InitDefaultableModule(module)
419}
420
Nan Zhang1598a9e2018-09-04 17:14:32 -0700421func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
422 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
423 return true
424 } else if String(apiToCheck.Api_file) != "" {
425 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
426 } else if String(apiToCheck.Removed_api_file) != "" {
427 panic("for " + apiVersionTag + " api_file has to be non-empty!")
428 }
429
430 return false
431}
432
Inseob Kim38449af2019-02-28 14:24:05 +0900433func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
434 api_file := String(apiToCheck.Api_file)
435 removed_api_file := String(apiToCheck.Removed_api_file)
436
437 api_module := android.SrcIsModule(api_file)
438 removed_api_module := android.SrcIsModule(removed_api_file)
439
440 if api_module == "" || removed_api_module == "" {
441 return
442 }
443
444 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
445 return
446 }
447
448 apiToCheck.Api_file = nil
449 apiToCheck.Removed_api_file = nil
450}
451
Nan Zhang1598a9e2018-09-04 17:14:32 -0700452type ApiFilePath interface {
453 ApiFilePath() android.Path
454}
455
456func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
457 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
458 ctx.Build(pctx, android.BuildParams{
459 Rule: updateApi,
460 Description: "Update API",
461 Output: output,
462 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
463 destApiFile, destRemovedApiFile),
464 Args: map[string]string{
465 "destApiFile": destApiFile.String(),
466 "srcApiFile": srcApiFile.String(),
467 "destRemovedApiFile": destRemovedApiFile.String(),
468 "srcRemovedApiFile": srcRemovedApiFile.String(),
469 },
470 })
471}
472
Nan Zhanga40da042018-08-01 12:48:00 -0700473//
474// Javadoc
475//
Nan Zhang581fd212018-01-10 16:06:12 -0800476type Javadoc struct {
477 android.ModuleBase
478 android.DefaultableModuleBase
479
480 properties JavadocProperties
481
482 srcJars android.Paths
483 srcFiles android.Paths
484 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700485 argFiles android.Paths
486
487 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800488
Nan Zhangccff0f72018-03-08 17:26:16 -0800489 docZip android.WritablePath
490 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800491}
492
Colin Cross41955e82019-05-29 14:40:35 -0700493func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
494 switch tag {
495 case "":
496 return android.Paths{j.stubsSrcJar}, nil
497 default:
498 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
499 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800500}
501
Nan Zhang581fd212018-01-10 16:06:12 -0800502func JavadocFactory() android.Module {
503 module := &Javadoc{}
504
505 module.AddProperties(&module.properties)
506
507 InitDroiddocModule(module, android.HostAndDeviceSupported)
508 return module
509}
510
511func JavadocHostFactory() android.Module {
512 module := &Javadoc{}
513
514 module.AddProperties(&module.properties)
515
516 InitDroiddocModule(module, android.HostSupported)
517 return module
518}
519
Colin Cross41955e82019-05-29 14:40:35 -0700520var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800521
Colin Cross83bb3162018-06-25 15:48:06 -0700522func (j *Javadoc) sdkVersion() string {
523 return String(j.properties.Sdk_version)
524}
525
526func (j *Javadoc) minSdkVersion() string {
527 return j.sdkVersion()
528}
529
Dan Willemsen419290a2018-10-31 15:28:47 -0700530func (j *Javadoc) targetSdkVersion() string {
531 return j.sdkVersion()
532}
533
Nan Zhang581fd212018-01-10 16:06:12 -0800534func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
535 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100536 sdkDep := decodeSdkDep(ctx, sdkContext(j))
537 if sdkDep.hasStandardLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700538 if sdkDep.useDefaultLibs {
539 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
540 if ctx.Config().TargetOpenJDK9() {
541 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
542 }
Paul Duffin250e6192019-06-07 10:44:37 +0100543 if sdkDep.hasFrameworkLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700544 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
545 }
546 } else if sdkDep.useModule {
547 if ctx.Config().TargetOpenJDK9() {
548 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
549 }
550 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700551 }
Nan Zhang581fd212018-01-10 16:06:12 -0800552 }
553 }
554
Colin Cross42d48b72018-08-29 14:10:52 -0700555 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700556 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700557 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700558 }
Nan Zhang581fd212018-01-10 16:06:12 -0800559}
560
Nan Zhangb2b33de2018-02-23 11:18:47 -0800561func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
562 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
563 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900564 // convert foo.bar.baz to foo/bar/baz
565 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
566 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800567 if _, found := whitelistPathPrefixes[prefix]; !found {
568 whitelistPathPrefixes[prefix] = true
569 }
570 }
571 }
572}
573
Nan Zhanga40da042018-08-01 12:48:00 -0700574func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
575 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900576
Colin Cross3047fa22019-04-18 10:56:44 -0700577 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900578
579 return flags
580}
581
582func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700583 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900584
585 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
586 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
587
588 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700589 var deps android.Paths
590
Jiyong Park1e440682018-05-23 18:42:04 +0900591 if aidlPreprocess.Valid() {
592 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700593 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900594 } else {
595 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
596 }
597
598 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
599 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
600 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
601 flags = append(flags, "-I"+src.String())
602 }
603
Colin Cross3047fa22019-04-18 10:56:44 -0700604 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900605}
606
607func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700608 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900609
610 outSrcFiles := make(android.Paths, 0, len(srcFiles))
611
612 for _, srcFile := range srcFiles {
613 switch srcFile.Ext() {
614 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700615 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Jiyong Park1e440682018-05-23 18:42:04 +0900616 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900617 case ".sysprop":
618 javaFile := genSysprop(ctx, srcFile)
619 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900620 default:
621 outSrcFiles = append(outSrcFiles, srcFile)
622 }
623 }
624
625 return outSrcFiles
626}
627
Nan Zhang581fd212018-01-10 16:06:12 -0800628func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
629 var deps deps
630
Colin Cross83bb3162018-06-25 15:48:06 -0700631 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800632 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700633 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800634 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700635 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800636 }
637
638 ctx.VisitDirectDeps(func(module android.Module) {
639 otherName := ctx.OtherModuleName(module)
640 tag := ctx.OtherModuleDependencyTag(module)
641
Colin Cross2d24c1b2018-05-23 10:59:18 -0700642 switch tag {
643 case bootClasspathTag:
644 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800645 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700646 } else {
647 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
648 }
649 case libTag:
650 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800651 case SdkLibraryDependency:
652 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700653 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900654 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700655 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800656 checkProducesJars(ctx, dep)
657 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800658 default:
659 ctx.ModuleErrorf("depends on non-java module %q", otherName)
660 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700661 case srcsLibTag:
662 switch dep := module.(type) {
663 case Dependency:
664 srcs := dep.(SrcDependency).CompiledSrcs()
665 whitelistPathPrefixes := make(map[string]bool)
666 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
667 for _, src := range srcs {
668 if _, ok := src.(android.WritablePath); ok { // generated sources
669 deps.srcs = append(deps.srcs, src)
670 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700671 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700672 if strings.HasPrefix(src.Rel(), k) {
673 deps.srcs = append(deps.srcs, src)
674 break
675 }
676 }
677 }
678 }
679 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
680 default:
681 ctx.ModuleErrorf("depends on non-java module %q", otherName)
682 }
Nan Zhang357466b2018-04-17 17:38:36 -0700683 case systemModulesTag:
684 if deps.systemModules != nil {
685 panic("Found two system module dependencies")
686 }
687 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000688 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700689 panic("Missing directory for system module dependency")
690 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000691 deps.systemModules = sm.outputDir
692 deps.systemModulesDeps = sm.outputDeps
Nan Zhang581fd212018-01-10 16:06:12 -0800693 }
694 })
695 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
696 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800697 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700698 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900699 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800700
701 // srcs may depend on some genrule output.
702 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800703 j.srcJars = append(j.srcJars, deps.srcJars...)
704
Nan Zhang581fd212018-01-10 16:06:12 -0800705 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800706 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800707
708 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800709 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800710
Nan Zhang9c69a122018-08-22 10:22:08 -0700711 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800712 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
713 }
714 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800715
Colin Cross8a497952019-03-05 22:25:09 -0800716 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000717 argFilesMap := map[string]string{}
718 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700719
Paul Duffin99e4a502019-02-11 15:38:42 +0000720 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800721 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000722 if _, exists := argFilesMap[label]; !exists {
723 argFilesMap[label] = strings.Join(paths.Strings(), " ")
724 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700725 } else {
726 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000727 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700728 }
729 }
730
731 var err error
732 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
733 if strings.HasPrefix(name, "location ") {
734 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000735 if paths, ok := argFilesMap[label]; ok {
736 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700737 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000738 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
739 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700740 }
741 } else if name == "genDir" {
742 return android.PathForModuleGen(ctx).String(), nil
743 }
744 return "", fmt.Errorf("unknown variable '$(%s)'", name)
745 })
746
747 if err != nil {
748 ctx.PropertyErrorf("args", "%s", err.Error())
749 }
750
Nan Zhang581fd212018-01-10 16:06:12 -0800751 return deps
752}
753
754func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
755 j.addDeps(ctx)
756}
757
758func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
759 deps := j.collectDeps(ctx)
760
761 var implicits android.Paths
762 implicits = append(implicits, deps.bootClasspath...)
763 implicits = append(implicits, deps.classpath...)
764
Nan Zhang1598a9e2018-09-04 17:14:32 -0700765 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700766
Colin Cross83bb3162018-06-25 15:48:06 -0700767 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700768 if len(deps.bootClasspath) > 0 {
769 var systemModules classpath
770 if deps.systemModules != nil {
771 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800772 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000773 implicits = append(implicits, deps.systemModulesDeps...)
Colin Cross997262f2018-06-19 22:49:39 -0700774 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
775 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800776 }
777 if len(deps.classpath.Strings()) > 0 {
778 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
779 }
780
781 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700782 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800783
Nan Zhangaf322cc2018-06-19 15:15:38 -0700784 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800785
Nan Zhang1598a9e2018-09-04 17:14:32 -0700786 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
787
Nan Zhang581fd212018-01-10 16:06:12 -0800788 ctx.Build(pctx, android.BuildParams{
789 Rule: javadoc,
790 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800791 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800792 ImplicitOutput: j.docZip,
793 Inputs: j.srcFiles,
794 Implicits: implicits,
795 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700796 "outDir": android.PathForModuleOut(ctx, "out").String(),
797 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
798 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800799 "srcJars": strings.Join(j.srcJars.Strings(), " "),
800 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700801 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800802 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700803 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800804 "docZip": j.docZip.String(),
805 },
806 })
807}
808
Nan Zhanga40da042018-08-01 12:48:00 -0700809//
810// Droiddoc
811//
812type Droiddoc struct {
813 Javadoc
814
815 properties DroiddocProperties
816 apiFile android.WritablePath
817 dexApiFile android.WritablePath
818 privateApiFile android.WritablePath
819 privateDexApiFile android.WritablePath
820 removedApiFile android.WritablePath
821 removedDexApiFile android.WritablePath
822 exactApiFile android.WritablePath
823 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700824 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700825
826 checkCurrentApiTimestamp android.WritablePath
827 updateCurrentApiTimestamp android.WritablePath
828 checkLastReleasedApiTimestamp android.WritablePath
829
Nan Zhanga40da042018-08-01 12:48:00 -0700830 apiFilePath android.Path
831}
832
Nan Zhanga40da042018-08-01 12:48:00 -0700833func DroiddocFactory() android.Module {
834 module := &Droiddoc{}
835
836 module.AddProperties(&module.properties,
837 &module.Javadoc.properties)
838
839 InitDroiddocModule(module, android.HostAndDeviceSupported)
840 return module
841}
842
843func DroiddocHostFactory() android.Module {
844 module := &Droiddoc{}
845
846 module.AddProperties(&module.properties,
847 &module.Javadoc.properties)
848
849 InitDroiddocModule(module, android.HostSupported)
850 return module
851}
852
853func (d *Droiddoc) ApiFilePath() android.Path {
854 return d.apiFilePath
855}
856
Nan Zhang581fd212018-01-10 16:06:12 -0800857func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
858 d.Javadoc.addDeps(ctx)
859
Inseob Kim38449af2019-02-28 14:24:05 +0900860 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
861 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
862 }
863
Nan Zhang79614d12018-04-19 18:03:39 -0700864 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800865 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
866 }
Nan Zhang581fd212018-01-10 16:06:12 -0800867}
868
Nan Zhang66dc2362018-08-14 20:41:04 -0700869func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
870 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700871 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800872
Nan Zhanga40da042018-08-01 12:48:00 -0700873 *implicits = append(*implicits, deps.bootClasspath...)
874 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800875
Nan Zhangc94f9d82018-06-26 10:02:26 -0700876 if len(deps.bootClasspath.Strings()) > 0 {
877 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700878 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700879 }
Nan Zhanga40da042018-08-01 12:48:00 -0700880 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700881 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700882 dokkaClasspath := classpath{}
883 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
884 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
885 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700886
Nan Zhang9c69a122018-08-22 10:22:08 -0700887 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
888 // based stubs generation.
889 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
890 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
891 // the correct package name base path.
892 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
893 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
894 } else {
895 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
896 }
Nan Zhang581fd212018-01-10 16:06:12 -0800897
Nan Zhanga40da042018-08-01 12:48:00 -0700898 return flags, nil
899}
Nan Zhang581fd212018-01-10 16:06:12 -0800900
Nan Zhanga40da042018-08-01 12:48:00 -0700901func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700902 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800903
Nan Zhanga40da042018-08-01 12:48:00 -0700904 *implicits = append(*implicits, jsilver)
905 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700906
Nan Zhang46130972018-06-04 11:28:01 -0700907 var date string
908 if runtime.GOOS == "darwin" {
909 date = `date -r`
910 } else {
911 date = `date -d`
912 }
913
Nan Zhang443fa522018-08-20 20:58:28 -0700914 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
915 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
916 // 1.9 language features.
917 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700918 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800919 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700920 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700921
Nan Zhanga40da042018-08-01 12:48:00 -0700922 if String(d.properties.Custom_template) == "" {
923 // TODO: This is almost always droiddoc-templates-sdk
924 ctx.PropertyErrorf("custom_template", "must specify a template")
925 }
926
927 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700928 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700929 *implicits = append(*implicits, t.deps...)
930 args = args + " -templatedir " + t.dir.String()
931 } else {
932 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
933 }
934 })
935
936 if len(d.properties.Html_dirs) > 0 {
Colin Cross07e51612019-03-05 12:46:40 -0800937 htmlDir := d.properties.Html_dirs[0]
Colin Cross8a497952019-03-05 22:25:09 -0800938 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800939 args = args + " -htmldir " + htmlDir
Nan Zhanga40da042018-08-01 12:48:00 -0700940 }
941
942 if len(d.properties.Html_dirs) > 1 {
Colin Cross07e51612019-03-05 12:46:40 -0800943 htmlDir2 := d.properties.Html_dirs[1]
Colin Cross8a497952019-03-05 22:25:09 -0800944 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800945 args = args + " -htmldir2 " + htmlDir2
Nan Zhanga40da042018-08-01 12:48:00 -0700946 }
947
948 if len(d.properties.Html_dirs) > 2 {
949 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
950 }
951
Colin Cross8a497952019-03-05 22:25:09 -0800952 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Nan Zhanga40da042018-08-01 12:48:00 -0700953 *implicits = append(*implicits, knownTags...)
954
955 for _, kt := range knownTags {
956 args = args + " -knowntags " + kt.String()
957 }
958
959 for _, hdf := range d.properties.Hdf {
960 args = args + " -hdf " + hdf
961 }
962
963 if String(d.properties.Proofread_file) != "" {
964 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
965 args = args + " -proofread " + proofreadFile.String()
966 }
967
968 if String(d.properties.Todo_file) != "" {
969 // tricky part:
970 // we should not compute full path for todo_file through PathForModuleOut().
971 // the non-standard doclet will get the full path relative to "-o".
972 args = args + " -todo " + String(d.properties.Todo_file)
973 }
974
975 if String(d.properties.Resourcesdir) != "" {
976 // TODO: should we add files under resourcesDir to the implicits? It seems that
977 // resourcesDir is one sub dir of htmlDir
978 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
979 args = args + " -resourcesdir " + resourcesDir.String()
980 }
981
982 if String(d.properties.Resourcesoutdir) != "" {
983 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
984 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
985 }
986 return args
987}
988
Nan Zhang1598a9e2018-09-04 17:14:32 -0700989func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
990 implicitOutputs *android.WritablePaths) string {
991 var doclavaFlags string
992 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
993 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
994 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700995 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
996 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700997 *implicitOutputs = append(*implicitOutputs, d.apiFile)
998 d.apiFilePath = d.apiFile
999 }
1000
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1002 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1003 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001004 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1005 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001006 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1007 }
1008
1009 if String(d.properties.Private_api_filename) != "" {
1010 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1011 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001012 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1013 }
1014
1015 if String(d.properties.Dex_api_filename) != "" {
1016 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1017 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1018 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1019 }
1020
1021 if String(d.properties.Private_dex_api_filename) != "" {
1022 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1023 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001024 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1025 }
1026
1027 if String(d.properties.Removed_dex_api_filename) != "" {
1028 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1029 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001030 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1031 }
1032
1033 if String(d.properties.Exact_api_filename) != "" {
1034 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1035 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001036 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1037 }
1038
1039 if String(d.properties.Dex_mapping_filename) != "" {
1040 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1041 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001042 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1043 }
1044
Nan Zhang66dc2362018-08-14 20:41:04 -07001045 if String(d.properties.Proguard_filename) != "" {
1046 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1047 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001048 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1049 }
1050
Nan Zhanga40da042018-08-01 12:48:00 -07001051 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001052 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001053 }
1054
1055 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001056 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001057 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001058
1059 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001060}
1061
1062func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1063 var cmds string
1064 if String(d.properties.Static_doc_index_redirect) != "" {
1065 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1066 "static_doc_index_redirect")
1067 *implicits = append(*implicits, static_doc_index_redirect)
1068 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001069 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001070 }
1071
1072 if String(d.properties.Static_doc_properties) != "" {
1073 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1074 "static_doc_properties")
1075 *implicits = append(*implicits, static_doc_properties)
1076 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001077 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001078 }
1079 return cmds
1080}
1081
Nan Zhang1598a9e2018-09-04 17:14:32 -07001082func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1083 implicitOutputs android.WritablePaths,
1084 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1085 ctx.Build(pctx, android.BuildParams{
1086 Rule: javadoc,
1087 Description: "Doclava",
1088 Output: d.Javadoc.stubsSrcJar,
1089 Inputs: d.Javadoc.srcFiles,
1090 Implicits: implicits,
1091 ImplicitOutputs: implicitOutputs,
1092 Args: map[string]string{
1093 "outDir": android.PathForModuleOut(ctx, "out").String(),
1094 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1095 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1096 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1097 "opts": opts,
1098 "bootclasspathArgs": bootclasspathArgs,
1099 "classpathArgs": classpathArgs,
1100 "sourcepathArgs": sourcepathArgs,
1101 "docZip": d.Javadoc.docZip.String(),
1102 "postDoclavaCmds": postDoclavaCmds,
1103 },
1104 })
1105}
1106
1107func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1108 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1109 ctx.Build(pctx, android.BuildParams{
1110 Rule: apiCheck,
1111 Description: "Doclava Check API",
1112 Output: output,
1113 Inputs: nil,
1114 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1115 checkApiClasspath...),
1116 Args: map[string]string{
1117 "msg": msg,
1118 "classpath": checkApiClasspath.FormJavaClassPath(""),
1119 "opts": opts,
1120 "apiFile": apiFile.String(),
1121 "apiFileToCheck": d.apiFile.String(),
1122 "removedApiFile": removedApiFile.String(),
1123 "removedApiFileToCheck": d.removedApiFile.String(),
1124 },
1125 })
1126}
1127
1128func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1129 classpathArgs, opts string) {
1130 ctx.Build(pctx, android.BuildParams{
1131 Rule: dokka,
1132 Description: "Dokka",
1133 Output: d.Javadoc.stubsSrcJar,
1134 Inputs: d.Javadoc.srcFiles,
1135 Implicits: implicits,
1136 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001137 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1138 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1139 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001140 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1141 "classpathArgs": classpathArgs,
1142 "opts": opts,
1143 "docZip": d.Javadoc.docZip.String(),
1144 },
1145 })
1146}
1147
1148func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1149 deps := d.Javadoc.collectDeps(ctx)
1150
1151 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1152 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1153 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1154 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1155
1156 var implicits android.Paths
1157 implicits = append(implicits, d.Javadoc.srcJars...)
1158 implicits = append(implicits, d.Javadoc.argFiles...)
1159
1160 var implicitOutputs android.WritablePaths
1161 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1162 for _, o := range d.Javadoc.properties.Out {
1163 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1164 }
1165
1166 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1167 if err != nil {
1168 return
1169 }
1170
1171 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1172 if Bool(d.properties.Dokka_enabled) {
1173 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1174 } else {
1175 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1176 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1177 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1178 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1179 flags.postDoclavaCmds)
1180 }
1181
1182 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1183 !ctx.Config().IsPdkBuild() {
1184 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1185 "check_api.current.api_file")
1186 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1187 "check_api.current_removed_api_file")
1188
1189 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1190 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1191 fmt.Sprintf(`\n******************************\n`+
1192 `You have tried to change the API from what has been previously approved.\n\n`+
1193 `To make these errors go away, you have two choices:\n`+
1194 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1195 ` errors above.\n\n`+
1196 ` 2. You can update current.txt by executing the following command:\n`+
1197 ` make %s-update-current-api\n\n`+
1198 ` To submit the revised current.txt to the main Android repository,\n`+
1199 ` you will need approval.\n`+
1200 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1201 d.checkCurrentApiTimestamp)
1202
1203 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1204 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1205 d.updateCurrentApiTimestamp)
1206 }
1207
1208 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1209 !ctx.Config().IsPdkBuild() {
1210 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1211 "check_api.last_released.api_file")
1212 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1213 "check_api.last_released.removed_api_file")
1214
1215 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1216 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1217 `\n******************************\n`+
1218 `You have tried to change the API from what has been previously released in\n`+
1219 `an SDK. Please fix the errors listed above.\n`+
1220 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1221 d.checkLastReleasedApiTimestamp)
1222 }
1223}
1224
1225//
1226// Droidstubs
1227//
1228type Droidstubs struct {
1229 Javadoc
1230
Pete Gillin581d6082018-10-22 15:55:04 +01001231 properties DroidstubsProperties
1232 apiFile android.WritablePath
1233 apiXmlFile android.WritablePath
1234 lastReleasedApiXmlFile android.WritablePath
1235 dexApiFile android.WritablePath
1236 privateApiFile android.WritablePath
1237 privateDexApiFile android.WritablePath
1238 removedApiFile android.WritablePath
1239 removedDexApiFile android.WritablePath
1240 apiMappingFile android.WritablePath
1241 exactApiFile android.WritablePath
1242 proguardFile android.WritablePath
1243 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001244
1245 checkCurrentApiTimestamp android.WritablePath
1246 updateCurrentApiTimestamp android.WritablePath
1247 checkLastReleasedApiTimestamp android.WritablePath
1248
Pete Gillin581d6082018-10-22 15:55:04 +01001249 checkNullabilityWarningsTimestamp android.WritablePath
1250
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001252 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253
1254 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001255
1256 jdiffDocZip android.WritablePath
1257 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001258}
1259
1260func DroidstubsFactory() android.Module {
1261 module := &Droidstubs{}
1262
1263 module.AddProperties(&module.properties,
1264 &module.Javadoc.properties)
1265
1266 InitDroiddocModule(module, android.HostAndDeviceSupported)
1267 return module
1268}
1269
1270func DroidstubsHostFactory() android.Module {
1271 module := &Droidstubs{}
1272
1273 module.AddProperties(&module.properties,
1274 &module.Javadoc.properties)
1275
1276 InitDroiddocModule(module, android.HostSupported)
1277 return module
1278}
1279
1280func (d *Droidstubs) ApiFilePath() android.Path {
1281 return d.apiFilePath
1282}
1283
1284func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1285 d.Javadoc.addDeps(ctx)
1286
Inseob Kim38449af2019-02-28 14:24:05 +09001287 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1288 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1289 }
1290
Nan Zhang1598a9e2018-09-04 17:14:32 -07001291 if len(d.properties.Merge_annotations_dirs) != 0 {
1292 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1293 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1294 }
1295 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001296
Pete Gillin77167902018-09-19 18:16:26 +01001297 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1298 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1299 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1300 }
1301 }
1302
Nan Zhang9c69a122018-08-22 10:22:08 -07001303 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1304 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1305 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1306 }
1307 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001308}
1309
1310func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1311 deps deps) (droiddocBuilderFlags, error) {
1312 var flags droiddocBuilderFlags
1313
1314 *implicits = append(*implicits, deps.bootClasspath...)
1315 *implicits = append(*implicits, deps.classpath...)
1316
1317 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1318 // since it doesn't support system modules yet.
1319 if len(deps.bootClasspath.Strings()) > 0 {
1320 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1321 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1322 }
1323 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1324
Sundong Ahn56dce442018-10-05 18:41:09 +09001325 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 return flags, nil
1327}
1328
1329func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1330 implicitOutputs *android.WritablePaths) string {
1331 var metalavaFlags string
1332 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1333 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1334 String(d.properties.Api_filename) != "" {
1335 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1336 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1337 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1338 d.apiFilePath = d.apiFile
1339 }
1340
1341 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1342 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1343 String(d.properties.Removed_api_filename) != "" {
1344 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1345 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1346 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1347 }
1348
1349 if String(d.properties.Private_api_filename) != "" {
1350 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1351 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1352 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1353 }
1354
1355 if String(d.properties.Dex_api_filename) != "" {
1356 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1357 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1358 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1359 }
1360
1361 if String(d.properties.Private_dex_api_filename) != "" {
1362 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1363 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1364 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1365 }
1366
1367 if String(d.properties.Removed_dex_api_filename) != "" {
1368 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1369 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1370 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1371 }
1372
1373 if String(d.properties.Exact_api_filename) != "" {
1374 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1375 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1376 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1377 }
1378
Nan Zhang9c69a122018-08-22 10:22:08 -07001379 if String(d.properties.Dex_mapping_filename) != "" {
1380 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1381 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1382 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1383 }
1384
Nan Zhang199645c2018-09-19 12:40:06 -07001385 if String(d.properties.Proguard_filename) != "" {
1386 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1387 metalavaFlags += " --proguard " + d.proguardFile.String()
1388 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1389 }
1390
Nan Zhang9c69a122018-08-22 10:22:08 -07001391 if Bool(d.properties.Write_sdk_values) {
1392 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1393 }
1394
Nan Zhang1598a9e2018-09-04 17:14:32 -07001395 if Bool(d.properties.Create_doc_stubs) {
1396 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1397 } else {
1398 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1399 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001400 return metalavaFlags
1401}
1402
1403func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001404 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1405 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001406 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001407 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001408 validatingNullability :=
1409 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1410 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001411 migratingNullability := String(d.properties.Previous_api) != ""
1412 if !(migratingNullability || validatingNullability) {
1413 ctx.PropertyErrorf("previous_api",
1414 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001415 }
Pete Gillina262c052018-09-14 14:25:48 +01001416 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001417 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Pete Gillina262c052018-09-14 14:25:48 +01001418 *implicits = append(*implicits, previousApi)
1419 flags += " --migrate-nullness " + previousApi.String()
1420 }
Pete Gillinc382a562018-11-14 18:45:46 +00001421 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross8a497952019-03-05 22:25:09 -08001422 flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String()
Pete Gillinc382a562018-11-14 18:45:46 +00001423 }
Pete Gillina262c052018-09-14 14:25:48 +01001424 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001425 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1426 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1427 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001428 }
Nan Zhanga40da042018-08-01 12:48:00 -07001429
1430 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1431 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1432
Nan Zhangf4936b02018-08-01 15:00:28 -07001433 flags += " --extract-annotations " + d.annotationsZip.String()
1434
Nan Zhang1598a9e2018-09-04 17:14:32 -07001435 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001436 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001437 "has to be non-empty if annotations was enabled!")
1438 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001439 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1440 if t, ok := m.(*ExportedDroiddocDir); ok {
1441 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001442 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001443 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001444 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001445 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1446 }
1447 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001448 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001449 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001450 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001451 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001452
Nan Zhangdee152b2018-12-26 16:06:37 -08001453 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001454}
1455
1456func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1457 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1458 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001459 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1460 if t, ok := m.(*ExportedDroiddocDir); ok {
1461 *implicits = append(*implicits, t.deps...)
1462 flags += " --merge-inclusion-annotations " + t.dir.String()
1463 } else {
1464 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1465 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1466 }
1467 })
Nan Zhanga40da042018-08-01 12:48:00 -07001468
1469 return flags
1470}
1471
Nan Zhang9c69a122018-08-22 10:22:08 -07001472func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1473 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1474 var flags string
1475 if Bool(d.properties.Api_levels_annotations_enabled) {
1476 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1477 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1478
1479 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1480 ctx.PropertyErrorf("api_levels_annotations_dirs",
1481 "has to be non-empty if api levels annotations was enabled!")
1482 }
1483
1484 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1485 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1486 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1487
1488 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1489 if t, ok := m.(*ExportedDroiddocDir); ok {
1490 var androidJars android.Paths
1491 for _, dep := range t.deps {
1492 if strings.HasSuffix(dep.String(), "android.jar") {
1493 androidJars = append(androidJars, dep)
1494 }
1495 }
1496 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001497 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001498 } else {
1499 ctx.PropertyErrorf("api_levels_annotations_dirs",
1500 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1501 }
1502 })
1503
1504 }
1505
1506 return flags
1507}
1508
Nan Zhang71bbe632018-09-17 14:32:21 -07001509func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1510 implicitOutputs *android.WritablePaths) string {
1511 var flags string
1512 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1513 if d.apiFile.String() == "" {
1514 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1515 }
1516
1517 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1518 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1519
1520 flags = " --api-xml " + d.apiXmlFile.String()
1521
1522 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1523 ctx.PropertyErrorf("check_api.last_released.api_file",
1524 "has to be non-empty if jdiff was enabled!")
1525 }
1526 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1527 "check_api.last_released.api_file")
1528 *implicits = append(*implicits, lastReleasedApi)
1529
1530 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1531 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1532
1533 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1534 d.lastReleasedApiXmlFile.String()
1535 }
1536
1537 return flags
1538}
1539
Nan Zhang1598a9e2018-09-04 17:14:32 -07001540func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1541 implicitOutputs android.WritablePaths, javaVersion,
1542 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001543
Nan Zhang86d2d552018-08-09 15:33:27 -07001544 ctx.Build(pctx, android.BuildParams{
1545 Rule: metalava,
1546 Description: "Metalava",
1547 Output: d.Javadoc.stubsSrcJar,
1548 Inputs: d.Javadoc.srcFiles,
1549 Implicits: implicits,
1550 ImplicitOutputs: implicitOutputs,
1551 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001552 "outDir": android.PathForModuleOut(ctx, "out").String(),
1553 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1554 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1555 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001556 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001557 "bootclasspathArgs": bootclasspathArgs,
1558 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001559 "sourcepathArgs": sourcepathArgs,
1560 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001561 },
1562 })
1563}
1564
Nan Zhang1598a9e2018-09-04 17:14:32 -07001565func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1566 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001567 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001568 output android.WritablePath) {
1569 ctx.Build(pctx, android.BuildParams{
1570 Rule: metalavaApiCheck,
1571 Description: "Metalava Check API",
1572 Output: output,
1573 Inputs: d.Javadoc.srcFiles,
1574 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1575 implicits...),
1576 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001577 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001578 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1579 "javaVersion": javaVersion,
1580 "bootclasspathArgs": bootclasspathArgs,
1581 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001582 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001583 "opts": opts,
1584 "msg": msg,
1585 },
1586 })
1587}
1588
Nan Zhang71bbe632018-09-17 14:32:21 -07001589func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1590 implicitOutputs android.WritablePaths,
1591 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1592 ctx.Build(pctx, android.BuildParams{
1593 Rule: javadoc,
1594 Description: "Jdiff",
1595 Output: d.jdiffStubsSrcJar,
1596 Inputs: d.Javadoc.srcFiles,
1597 Implicits: implicits,
1598 ImplicitOutputs: implicitOutputs,
1599 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001600 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1601 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1602 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001603 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1604 "opts": opts,
1605 "bootclasspathArgs": bootclasspathArgs,
1606 "classpathArgs": classpathArgs,
1607 "sourcepathArgs": sourcepathArgs,
1608 "docZip": d.jdiffDocZip.String(),
1609 },
1610 })
1611}
1612
Nan Zhang1598a9e2018-09-04 17:14:32 -07001613func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001614 deps := d.Javadoc.collectDeps(ctx)
1615
1616 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001617
Nan Zhanga40da042018-08-01 12:48:00 -07001618 var implicits android.Paths
1619 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001620 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001621
1622 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001623 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001624 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1625 }
1626
1627 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001628 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001629 jdiffImplicits := implicits
1630
Nan Zhanga40da042018-08-01 12:48:00 -07001631 if err != nil {
1632 return
1633 }
1634
Nan Zhang1598a9e2018-09-04 17:14:32 -07001635 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001636 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1637 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001638 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001639 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001640 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1641
Nan Zhang1598a9e2018-09-04 17:14:32 -07001642 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1643 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1644 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1645 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1646 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001647 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001648 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1649 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001650 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001651 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001652
Nan Zhang1598a9e2018-09-04 17:14:32 -07001653 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1654 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001655 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1656 "check_api.current.api_file")
1657 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1658 "check_api.current_removed_api_file")
1659
Nan Zhang2760dfc2018-08-24 17:32:54 +00001660 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001661 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1662 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001663 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001664
Nan Zhang1598a9e2018-09-04 17:14:32 -07001665 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001666 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001667 fmt.Sprintf(`\n******************************\n`+
1668 `You have tried to change the API from what has been previously approved.\n\n`+
1669 `To make these errors go away, you have two choices:\n`+
1670 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1671 ` errors above.\n\n`+
1672 ` 2. You can update current.txt by executing the following command:\n`+
1673 ` make %s-update-current-api\n\n`+
1674 ` To submit the revised current.txt to the main Android repository,\n`+
1675 ` you will need approval.\n`+
1676 `******************************\n`, ctx.ModuleName()),
1677 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001678
1679 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001680 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1681 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001682 }
Nan Zhanga40da042018-08-01 12:48:00 -07001683
Nan Zhang1598a9e2018-09-04 17:14:32 -07001684 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1685 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001686 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1687 "check_api.last_released.api_file")
1688 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1689 "check_api.last_released.removed_api_file")
1690
Nan Zhang2760dfc2018-08-24 17:32:54 +00001691 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001692 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1693 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001694 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001695
Nan Zhang1598a9e2018-09-04 17:14:32 -07001696 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001697 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001698 `\n******************************\n`+
1699 `You have tried to change the API from what has been previously released in\n`+
1700 `an SDK. Please fix the errors listed above.\n`+
1701 `******************************\n`,
1702 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001703 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001704
Pete Gillin581d6082018-10-22 15:55:04 +01001705 if String(d.properties.Check_nullability_warnings) != "" {
1706 if d.nullabilityWarningsFile == nil {
1707 ctx.PropertyErrorf("check_nullability_warnings",
1708 "Cannot specify check_nullability_warnings unless validating nullability")
1709 }
1710 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1711 "check_nullability_warnings")
1712 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1713 msg := fmt.Sprintf(`\n******************************\n`+
1714 `The warnings encountered during nullability annotation validation did\n`+
1715 `not match the checked in file of expected warnings. The diffs are shown\n`+
1716 `above. You have two options:\n`+
1717 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1718 ` 2. Update the file of expected warnings by running:\n`+
1719 ` cp %s %s\n`+
1720 ` and submitting the updated file as part of your change.`,
1721 d.nullabilityWarningsFile, checkNullabilityWarnings)
1722 ctx.Build(pctx, android.BuildParams{
1723 Rule: nullabilityWarningsCheck,
1724 Description: "Nullability Warnings Check",
1725 Output: d.checkNullabilityWarningsTimestamp,
1726 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1727 Args: map[string]string{
1728 "expected": checkNullabilityWarnings.String(),
1729 "actual": d.nullabilityWarningsFile.String(),
1730 "msg": msg,
1731 },
1732 })
1733 }
1734
Nan Zhang71bbe632018-09-17 14:32:21 -07001735 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1736
Nan Zhang86b06202018-09-21 17:09:21 -07001737 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1738 // since there's cron job downstream that fetch this .zip file periodically.
1739 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001740 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1741 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1742
1743 var jdiffImplicitOutputs android.WritablePaths
1744 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1745
1746 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1747 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1748
Pete Gillin2b1ea2e2019-06-10 14:20:11 +01001749 opts := " -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
Nan Zhang71bbe632018-09-17 14:32:21 -07001750 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1751 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1752 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1753 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1754 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1755
1756 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1757 flags.sourcepathArgs, opts)
1758 }
Nan Zhang581fd212018-01-10 16:06:12 -08001759}
Dan Willemsencc090972018-02-26 14:33:31 -08001760
Nan Zhanga40da042018-08-01 12:48:00 -07001761//
Nan Zhangf4936b02018-08-01 15:00:28 -07001762// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001763//
Dan Willemsencc090972018-02-26 14:33:31 -08001764var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001765var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001766var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001767var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001768
Nan Zhangf4936b02018-08-01 15:00:28 -07001769type ExportedDroiddocDirProperties struct {
1770 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001771 Path *string
1772}
1773
Nan Zhangf4936b02018-08-01 15:00:28 -07001774type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001775 android.ModuleBase
1776
Nan Zhangf4936b02018-08-01 15:00:28 -07001777 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001778
1779 deps android.Paths
1780 dir android.Path
1781}
1782
Nan Zhangf4936b02018-08-01 15:00:28 -07001783func ExportedDroiddocDirFactory() android.Module {
1784 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001785 module.AddProperties(&module.properties)
1786 android.InitAndroidModule(module)
1787 return module
1788}
1789
Nan Zhangf4936b02018-08-01 15:00:28 -07001790func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001791
Nan Zhangf4936b02018-08-01 15:00:28 -07001792func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001793 path := String(d.properties.Path)
1794 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001795 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001796}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001797
1798//
1799// Defaults
1800//
1801type DocDefaults struct {
1802 android.ModuleBase
1803 android.DefaultsModuleBase
1804}
1805
Nan Zhangb2b33de2018-02-23 11:18:47 -08001806func DocDefaultsFactory() android.Module {
1807 module := &DocDefaults{}
1808
1809 module.AddProperties(
1810 &JavadocProperties{},
1811 &DroiddocProperties{},
1812 )
1813
1814 android.InitDefaultsModule(module)
1815
1816 return module
1817}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001818
1819func StubsDefaultsFactory() android.Module {
1820 module := &DocDefaults{}
1821
1822 module.AddProperties(
1823 &JavadocProperties{},
1824 &DroidstubsProperties{},
1825 )
1826
1827 android.InitDefaultsModule(module)
1828
1829 return module
1830}