blob: 18f337a263c6b60627c0350779825b773eb7f3bc [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"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090026 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29var (
30 javadoc = pctx.AndroidStaticRule("javadoc",
31 blueprint.RuleParams{
32 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070033 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang40b41b42018-10-02 16:11:17 -070034 `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070035 `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` +
Nan Zhang581fd212018-01-10 16:06:12 -080036 `-d $outDir -quiet && ` +
37 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Colin Cross44c29a82019-01-24 16:36:57 -080038 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds && ` +
39 `rm -rf "$srcJarDir"`,
40
Nan Zhang581fd212018-01-10 16:06:12 -080041 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070042 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080043 "${config.JavadocCmd}",
44 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080045 },
Nan Zhang40b41b42018-10-02 16:11:17 -070046 CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
47 Rspfile: "$out.rsp",
48 RspfileContent: "$in",
49 Restat: true,
Nan Zhang581fd212018-01-10 16:06:12 -080050 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070051 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang1598a9e2018-09-04 17:14:32 -070052 "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070053
54 apiCheck = pctx.AndroidStaticRule("apiCheck",
55 blueprint.RuleParams{
56 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
57 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090058 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070059 CommandDeps: []string{
60 "${config.ApiCheckCmd}",
61 },
62 },
63 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
64
65 updateApi = pctx.AndroidStaticRule("updateApi",
66 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070067 Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` +
Nan Zhang61819ce2018-05-04 18:49:16 -070068 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
69 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070070 "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile")
Nan Zhang79614d12018-04-19 18:03:39 -070071
72 metalava = pctx.AndroidStaticRule("metalava",
73 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070074 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
75 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070076 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -070077 `${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -080078 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070079 `$opts && ` +
Colin Cross44c29a82019-01-24 16:36:57 -080080 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` +
81 `rm -rf "$srcJarDir"`,
Nan Zhang79614d12018-04-19 18:03:39 -070082 CommandDeps: []string{
83 "${config.ZipSyncCmd}",
84 "${config.JavaCmd}",
85 "${config.MetalavaJar}",
Nan Zhang79614d12018-04-19 18:03:39 -070086 "${config.SoongZipCmd}",
87 },
88 Rspfile: "$out.rsp",
89 RspfileContent: "$in",
90 Restat: true,
91 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070092 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
93 "classpathArgs", "sourcepathArgs", "opts")
Nan Zhang2760dfc2018-08-24 17:32:54 +000094
95 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
96 blueprint.RuleParams{
97 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
98 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -070099 `${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -0800100 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Colin Cross44c29a82019-01-24 16:36:57 -0800101 `$opts && touch $out && rm -rf "$srcJarDir") || ` +
Nan Zhang2760dfc2018-08-24 17:32:54 +0000102 `( echo -e "$msg" ; exit 38 )`,
103 CommandDeps: []string{
104 "${config.ZipSyncCmd}",
105 "${config.JavaCmd}",
106 "${config.MetalavaJar}",
107 },
108 Rspfile: "$out.rsp",
109 RspfileContent: "$in",
110 },
Nan Zhang1598a9e2018-09-04 17:14:32 -0700111 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg")
112
Pete Gillin581d6082018-10-22 15:55:04 +0100113 nullabilityWarningsCheck = pctx.AndroidStaticRule("nullabilityWarningsCheck",
114 blueprint.RuleParams{
115 Command: `( diff $expected $actual && touch $out ) || ( echo -e "$msg" ; exit 38 )`,
116 },
117 "expected", "actual", "msg")
118
Nan Zhang1598a9e2018-09-04 17:14:32 -0700119 dokka = pctx.AndroidStaticRule("dokka",
120 blueprint.RuleParams{
121 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
122 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
123 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Sasha Smundak26c6d9e2019-06-11 13:30:13 -0700124 `${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.DokkaJar} $srcJarDir ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -0700125 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
126 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Colin Cross44c29a82019-01-24 16:36:57 -0800127 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir && ` +
128 `rm -rf "$srcJarDir"`,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700129 CommandDeps: []string{
130 "${config.ZipSyncCmd}",
131 "${config.DokkaJar}",
132 "${config.MetalavaJar}",
133 "${config.SoongZipCmd}",
134 },
135 Restat: true,
136 },
137 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800138)
139
140func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800141 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700142 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800143
Nan Zhang581fd212018-01-10 16:06:12 -0800144 android.RegisterModuleType("droiddoc", DroiddocFactory)
145 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700146 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800147 android.RegisterModuleType("javadoc", JavadocFactory)
148 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700149
150 android.RegisterModuleType("droidstubs", DroidstubsFactory)
151 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800152}
153
Colin Crossa1ce2a02018-06-20 15:19:39 -0700154var (
155 srcsLibTag = dependencyTag{name: "sources from javalib"}
156)
157
Nan Zhang581fd212018-01-10 16:06:12 -0800158type JavadocProperties struct {
159 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
160 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -0800161 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -0800162
163 // list of directories rooted at the Android.bp file that will
164 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800165 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800166
167 // list of source files that should not be used to build the Java module.
168 // This is most useful in the arch/multilib variants to remove non-common files
169 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800170 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -0800171
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800173 Libs []string `android:"arch_variant"`
174
Paul Duffin2fbbfb82019-02-13 12:49:33 +0000175 // don't build against the framework libraries (ext, and framework for device targets)
Nan Zhange66c7272018-03-06 12:59:27 -0800176 No_framework_libs *bool
177
Nan Zhangb2b33de2018-02-23 11:18:47 -0800178 // the java library (in classpath) for documentation that provides java srcs and srcjars.
179 Srcs_lib *string
180
181 // the base dirs under srcs_lib will be scanned for java srcs.
182 Srcs_lib_whitelist_dirs []string
183
184 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
185 Srcs_lib_whitelist_pkgs []string
186
Nan Zhang581fd212018-01-10 16:06:12 -0800187 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800188 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800189
190 // if not blank, set to the version of the sdk to compile against
191 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900192
193 Aidl struct {
194 // Top level directories to pass to aidl tool
195 Include_dirs []string
196
197 // Directories rooted at the Android.bp file to pass to aidl tool
198 Local_include_dirs []string
199 }
Nan Zhang357466b2018-04-17 17:38:36 -0700200
201 // If not blank, set the java version passed to javadoc as -source
202 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700203
204 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800205 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700206
207 // user customized droiddoc args.
208 // Available variables for substitution:
209 //
210 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700211 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700212 Args *string
213
214 // names of the output files used in args that will be generated
215 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800216}
217
Nan Zhang61819ce2018-05-04 18:49:16 -0700218type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900219 // path to the API txt file that the new API extracted from source code is checked
220 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800221 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700222
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900223 // path to the API txt file that the new @removed API extractd from source code is
224 // checked against. The path can be local to the module or from other module (via
225 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800226 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700227
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900228 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700229 Args *string
230}
231
Nan Zhang581fd212018-01-10 16:06:12 -0800232type DroiddocProperties struct {
233 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800234 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800235
Nan Zhanga40da042018-08-01 12:48:00 -0700236 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800237 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800238
239 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800240 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800241
242 // proofread file contains all of the text content of the javadocs concatenated into one file,
243 // suitable for spell-checking and other goodness.
Colin Cross27b922f2019-03-04 22:35:41 -0800244 Proofread_file *string `android:"path"`
Nan Zhang581fd212018-01-10 16:06:12 -0800245
246 // a todo file lists the program elements that are missing documentation.
247 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800248 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800249
250 // directory under current module source that provide additional resources (images).
251 Resourcesdir *string
252
253 // resources output directory under out/soong/.intermediates.
254 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800255
Nan Zhange2ba5d42018-07-11 15:16:55 -0700256 // if set to true, collect the values used by the Dev tools and
257 // write them in files packaged with the SDK. Defaults to false.
258 Write_sdk_values *bool
259
260 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800261 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700262
263 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800264 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700265
Nan Zhang581fd212018-01-10 16:06:12 -0800266 // a list of files under current module source dir which contains known tags in Java sources.
267 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800268 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700269
270 // the tag name used to distinguish if the API files belong to public/system/test.
271 Api_tag_name *string
272
273 // the generated public API filename by Doclava.
274 Api_filename *string
275
David Brazdilfbe4cc32018-05-31 13:56:46 +0100276 // the generated public Dex API filename by Doclava.
277 Dex_api_filename *string
278
Nan Zhang28c68b92018-03-13 16:17:01 -0700279 // the generated private API filename by Doclava.
280 Private_api_filename *string
281
282 // the generated private Dex API filename by Doclava.
283 Private_dex_api_filename *string
284
285 // the generated removed API filename by Doclava.
286 Removed_api_filename *string
287
David Brazdilaac0c3c2018-04-24 16:23:29 +0100288 // the generated removed Dex API filename by Doclava.
289 Removed_dex_api_filename *string
290
Mathew Inwood76c3de12018-06-22 15:28:11 +0100291 // mapping of dex signatures to source file and line number. This is a temporary property and
292 // will be deleted; you probably shouldn't be using it.
293 Dex_mapping_filename *string
294
Nan Zhang28c68b92018-03-13 16:17:01 -0700295 // the generated exact API filename by Doclava.
296 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700297
Nan Zhang66dc2362018-08-14 20:41:04 -0700298 // the generated proguard filename by Doclava.
299 Proguard_filename *string
300
Nan Zhang853f4202018-04-12 16:55:56 -0700301 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
302 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700303
304 Check_api struct {
305 Last_released ApiToCheck
306
307 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900308
309 // do not perform API check against Last_released, in the case that both two specified API
310 // files by Last_released are modules which don't exist.
311 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700312 }
Nan Zhang79614d12018-04-19 18:03:39 -0700313
Nan Zhang1598a9e2018-09-04 17:14:32 -0700314 // if set to true, generate docs through Dokka instead of Doclava.
315 Dokka_enabled *bool
316}
317
318type DroidstubsProperties struct {
319 // the tag name used to distinguish if the API files belong to public/system/test.
320 Api_tag_name *string
321
Nan Zhang199645c2018-09-19 12:40:06 -0700322 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700323 Api_filename *string
324
Nan Zhang199645c2018-09-19 12:40:06 -0700325 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700326 Dex_api_filename *string
327
Nan Zhang199645c2018-09-19 12:40:06 -0700328 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700329 Private_api_filename *string
330
Nan Zhang199645c2018-09-19 12:40:06 -0700331 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700332 Private_dex_api_filename *string
333
Nan Zhang199645c2018-09-19 12:40:06 -0700334 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700335 Removed_api_filename *string
336
Nan Zhang199645c2018-09-19 12:40:06 -0700337 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338 Removed_dex_api_filename *string
339
Nan Zhang9c69a122018-08-22 10:22:08 -0700340 // mapping of dex signatures to source file and line number. This is a temporary property and
341 // will be deleted; you probably shouldn't be using it.
342 Dex_mapping_filename *string
343
Nan Zhang199645c2018-09-19 12:40:06 -0700344 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700345 Exact_api_filename *string
346
Nan Zhang199645c2018-09-19 12:40:06 -0700347 // the generated proguard filename by Metalava.
348 Proguard_filename *string
349
Nan Zhang1598a9e2018-09-04 17:14:32 -0700350 Check_api struct {
351 Last_released ApiToCheck
352
353 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900354
355 // do not perform API check against Last_released, in the case that both two specified API
356 // files by Last_released are modules which don't exist.
357 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700358 }
Nan Zhang79614d12018-04-19 18:03:39 -0700359
360 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800361 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700362
363 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700364 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700365
Pete Gillin77167902018-09-19 18:16:26 +0100366 // 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 -0700367 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700368
Pete Gillin77167902018-09-19 18:16:26 +0100369 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
370 Merge_inclusion_annotations_dirs []string
371
Pete Gillinc382a562018-11-14 18:45:46 +0000372 // a file containing a list of classes to do nullability validation for.
373 Validate_nullability_from_list *string
374
Pete Gillin581d6082018-10-22 15:55:04 +0100375 // a file containing expected warnings produced by validation of nullability annotations.
376 Check_nullability_warnings *string
377
Nan Zhang1598a9e2018-09-04 17:14:32 -0700378 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
379 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700380
381 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
382 Api_levels_annotations_enabled *bool
383
384 // the dirs which Metalava extracts API levels annotations from.
385 Api_levels_annotations_dirs []string
386
387 // if set to true, collect the values used by the Dev tools and
388 // write them in files packaged with the SDK. Defaults to false.
389 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700390
391 // If set to true, .xml based public API file will be also generated, and
392 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
393 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800394}
395
Nan Zhanga40da042018-08-01 12:48:00 -0700396//
397// Common flags passed down to build rule
398//
399type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700400 bootClasspathArgs string
401 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700402 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700403 dokkaClasspathArgs string
404 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700405 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700406
Nan Zhanga40da042018-08-01 12:48:00 -0700407 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700408 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700409 postDoclavaCmds string
410
Nan Zhang9c69a122018-08-22 10:22:08 -0700411 metalavaStubsFlags string
412 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800413 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100414 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700415 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700416
Nan Zhang71bbe632018-09-17 14:32:21 -0700417 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700418}
419
420func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
421 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
422 android.InitDefaultableModule(module)
423}
424
Nan Zhang1598a9e2018-09-04 17:14:32 -0700425func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
426 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
427 return true
428 } else if String(apiToCheck.Api_file) != "" {
429 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
430 } else if String(apiToCheck.Removed_api_file) != "" {
431 panic("for " + apiVersionTag + " api_file has to be non-empty!")
432 }
433
434 return false
435}
436
Inseob Kim38449af2019-02-28 14:24:05 +0900437func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
438 api_file := String(apiToCheck.Api_file)
439 removed_api_file := String(apiToCheck.Removed_api_file)
440
441 api_module := android.SrcIsModule(api_file)
442 removed_api_module := android.SrcIsModule(removed_api_file)
443
444 if api_module == "" || removed_api_module == "" {
445 return
446 }
447
448 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
449 return
450 }
451
452 apiToCheck.Api_file = nil
453 apiToCheck.Removed_api_file = nil
454}
455
Nan Zhang1598a9e2018-09-04 17:14:32 -0700456type ApiFilePath interface {
457 ApiFilePath() android.Path
458}
459
460func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
461 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
462 ctx.Build(pctx, android.BuildParams{
463 Rule: updateApi,
464 Description: "Update API",
465 Output: output,
466 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
467 destApiFile, destRemovedApiFile),
468 Args: map[string]string{
469 "destApiFile": destApiFile.String(),
470 "srcApiFile": srcApiFile.String(),
471 "destRemovedApiFile": destRemovedApiFile.String(),
472 "srcRemovedApiFile": srcRemovedApiFile.String(),
473 },
474 })
475}
476
Nan Zhanga40da042018-08-01 12:48:00 -0700477//
478// Javadoc
479//
Nan Zhang581fd212018-01-10 16:06:12 -0800480type Javadoc struct {
481 android.ModuleBase
482 android.DefaultableModuleBase
483
484 properties JavadocProperties
485
486 srcJars android.Paths
487 srcFiles android.Paths
488 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700489 argFiles android.Paths
490
491 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800492
Nan Zhangccff0f72018-03-08 17:26:16 -0800493 docZip android.WritablePath
494 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800495}
496
Colin Cross41955e82019-05-29 14:40:35 -0700497func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
498 switch tag {
499 case "":
500 return android.Paths{j.stubsSrcJar}, nil
501 default:
502 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
503 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800504}
505
Nan Zhang581fd212018-01-10 16:06:12 -0800506func JavadocFactory() android.Module {
507 module := &Javadoc{}
508
509 module.AddProperties(&module.properties)
510
511 InitDroiddocModule(module, android.HostAndDeviceSupported)
512 return module
513}
514
515func JavadocHostFactory() android.Module {
516 module := &Javadoc{}
517
518 module.AddProperties(&module.properties)
519
520 InitDroiddocModule(module, android.HostSupported)
521 return module
522}
523
Colin Cross41955e82019-05-29 14:40:35 -0700524var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800525
Colin Cross83bb3162018-06-25 15:48:06 -0700526func (j *Javadoc) sdkVersion() string {
Jeongik Cha6bd33c12019-06-25 16:26:18 +0900527 return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
Colin Cross83bb3162018-06-25 15:48:06 -0700528}
529
530func (j *Javadoc) minSdkVersion() string {
531 return j.sdkVersion()
532}
533
Dan Willemsen419290a2018-10-31 15:28:47 -0700534func (j *Javadoc) targetSdkVersion() string {
535 return j.sdkVersion()
536}
537
Paul Duffin250e6192019-06-07 10:44:37 +0100538func (j *Javadoc) noFrameworkLibs() bool {
539 return Bool(j.properties.No_framework_libs)
540}
541
Nan Zhang581fd212018-01-10 16:06:12 -0800542func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
543 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100544 sdkDep := decodeSdkDep(ctx, sdkContext(j))
545 if sdkDep.hasStandardLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700546 if sdkDep.useDefaultLibs {
547 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
548 if ctx.Config().TargetOpenJDK9() {
549 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
550 }
Paul Duffin250e6192019-06-07 10:44:37 +0100551 if sdkDep.hasFrameworkLibs() {
Nan Zhang5994b622018-09-21 16:39:51 -0700552 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
553 }
554 } else if sdkDep.useModule {
555 if ctx.Config().TargetOpenJDK9() {
556 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
557 }
558 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700559 }
Nan Zhang581fd212018-01-10 16:06:12 -0800560 }
561 }
562
Colin Cross42d48b72018-08-29 14:10:52 -0700563 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700564 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700565 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700566 }
Nan Zhang581fd212018-01-10 16:06:12 -0800567}
568
Nan Zhangb2b33de2018-02-23 11:18:47 -0800569func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
570 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
571 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900572 // convert foo.bar.baz to foo/bar/baz
573 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
574 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800575 if _, found := whitelistPathPrefixes[prefix]; !found {
576 whitelistPathPrefixes[prefix] = true
577 }
578 }
579 }
580}
581
Nan Zhanga40da042018-08-01 12:48:00 -0700582func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
583 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900584
Colin Cross3047fa22019-04-18 10:56:44 -0700585 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900586
587 return flags
588}
589
590func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700591 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900592
593 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
594 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
595
596 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700597 var deps android.Paths
598
Jiyong Park1e440682018-05-23 18:42:04 +0900599 if aidlPreprocess.Valid() {
600 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700601 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900602 } else {
603 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
604 }
605
606 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
607 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
608 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
609 flags = append(flags, "-I"+src.String())
610 }
611
Colin Cross3047fa22019-04-18 10:56:44 -0700612 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900613}
614
615func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700616 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900617
618 outSrcFiles := make(android.Paths, 0, len(srcFiles))
619
620 for _, srcFile := range srcFiles {
621 switch srcFile.Ext() {
622 case ".aidl":
Colin Cross3047fa22019-04-18 10:56:44 -0700623 javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
Jiyong Park1e440682018-05-23 18:42:04 +0900624 outSrcFiles = append(outSrcFiles, javaFile)
Inseob Kimc0907f12019-02-08 21:00:45 +0900625 case ".sysprop":
626 javaFile := genSysprop(ctx, srcFile)
627 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900628 default:
629 outSrcFiles = append(outSrcFiles, srcFile)
630 }
631 }
632
633 return outSrcFiles
634}
635
Nan Zhang581fd212018-01-10 16:06:12 -0800636func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
637 var deps deps
638
Colin Cross83bb3162018-06-25 15:48:06 -0700639 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800640 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700641 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800642 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700643 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800644 }
645
646 ctx.VisitDirectDeps(func(module android.Module) {
647 otherName := ctx.OtherModuleName(module)
648 tag := ctx.OtherModuleDependencyTag(module)
649
Colin Cross2d24c1b2018-05-23 10:59:18 -0700650 switch tag {
651 case bootClasspathTag:
652 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800653 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700654 } else {
655 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
656 }
657 case libTag:
658 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800659 case SdkLibraryDependency:
660 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700661 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900662 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700663 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800664 checkProducesJars(ctx, dep)
665 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800666 default:
667 ctx.ModuleErrorf("depends on non-java module %q", otherName)
668 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700669 case srcsLibTag:
670 switch dep := module.(type) {
671 case Dependency:
672 srcs := dep.(SrcDependency).CompiledSrcs()
673 whitelistPathPrefixes := make(map[string]bool)
674 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
675 for _, src := range srcs {
676 if _, ok := src.(android.WritablePath); ok { // generated sources
677 deps.srcs = append(deps.srcs, src)
678 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700679 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700680 if strings.HasPrefix(src.Rel(), k) {
681 deps.srcs = append(deps.srcs, src)
682 break
683 }
684 }
685 }
686 }
687 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
688 default:
689 ctx.ModuleErrorf("depends on non-java module %q", otherName)
690 }
Nan Zhang357466b2018-04-17 17:38:36 -0700691 case systemModulesTag:
692 if deps.systemModules != nil {
693 panic("Found two system module dependencies")
694 }
695 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000696 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700697 panic("Missing directory for system module dependency")
698 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000699 deps.systemModules = sm.outputDir
700 deps.systemModulesDeps = sm.outputDeps
Nan Zhang581fd212018-01-10 16:06:12 -0800701 }
702 })
703 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
704 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800705 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700706 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900707 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800708
709 // srcs may depend on some genrule output.
710 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800711 j.srcJars = append(j.srcJars, deps.srcJars...)
712
Nan Zhang581fd212018-01-10 16:06:12 -0800713 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800714 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800715
716 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800717 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800718
Nan Zhang9c69a122018-08-22 10:22:08 -0700719 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800720 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
721 }
722 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800723
Colin Cross8a497952019-03-05 22:25:09 -0800724 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000725 argFilesMap := map[string]string{}
726 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700727
Paul Duffin99e4a502019-02-11 15:38:42 +0000728 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800729 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000730 if _, exists := argFilesMap[label]; !exists {
731 argFilesMap[label] = strings.Join(paths.Strings(), " ")
732 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700733 } else {
734 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000735 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700736 }
737 }
738
739 var err error
740 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
741 if strings.HasPrefix(name, "location ") {
742 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000743 if paths, ok := argFilesMap[label]; ok {
744 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700745 } else {
Paul Duffin99e4a502019-02-11 15:38:42 +0000746 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
747 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700748 }
749 } else if name == "genDir" {
750 return android.PathForModuleGen(ctx).String(), nil
751 }
752 return "", fmt.Errorf("unknown variable '$(%s)'", name)
753 })
754
755 if err != nil {
756 ctx.PropertyErrorf("args", "%s", err.Error())
757 }
758
Nan Zhang581fd212018-01-10 16:06:12 -0800759 return deps
760}
761
762func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
763 j.addDeps(ctx)
764}
765
766func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
767 deps := j.collectDeps(ctx)
768
769 var implicits android.Paths
770 implicits = append(implicits, deps.bootClasspath...)
771 implicits = append(implicits, deps.classpath...)
772
Nan Zhang1598a9e2018-09-04 17:14:32 -0700773 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700774
Colin Cross83bb3162018-06-25 15:48:06 -0700775 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700776 if len(deps.bootClasspath) > 0 {
777 var systemModules classpath
778 if deps.systemModules != nil {
779 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800780 }
Dan Willemsenff60a732019-06-13 16:52:01 +0000781 implicits = append(implicits, deps.systemModulesDeps...)
Colin Cross997262f2018-06-19 22:49:39 -0700782 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
783 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800784 }
785 if len(deps.classpath.Strings()) > 0 {
786 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
787 }
788
789 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700790 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800791
Nan Zhangaf322cc2018-06-19 15:15:38 -0700792 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800793
Nan Zhang1598a9e2018-09-04 17:14:32 -0700794 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
795
Nan Zhang581fd212018-01-10 16:06:12 -0800796 ctx.Build(pctx, android.BuildParams{
797 Rule: javadoc,
798 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800799 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800800 ImplicitOutput: j.docZip,
801 Inputs: j.srcFiles,
802 Implicits: implicits,
803 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700804 "outDir": android.PathForModuleOut(ctx, "out").String(),
805 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
806 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800807 "srcJars": strings.Join(j.srcJars.Strings(), " "),
808 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700809 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800810 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700811 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800812 "docZip": j.docZip.String(),
813 },
814 })
815}
816
Nan Zhanga40da042018-08-01 12:48:00 -0700817//
818// Droiddoc
819//
820type Droiddoc struct {
821 Javadoc
822
823 properties DroiddocProperties
824 apiFile android.WritablePath
825 dexApiFile android.WritablePath
826 privateApiFile android.WritablePath
827 privateDexApiFile android.WritablePath
828 removedApiFile android.WritablePath
829 removedDexApiFile android.WritablePath
830 exactApiFile android.WritablePath
831 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700832 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700833
834 checkCurrentApiTimestamp android.WritablePath
835 updateCurrentApiTimestamp android.WritablePath
836 checkLastReleasedApiTimestamp android.WritablePath
837
Nan Zhanga40da042018-08-01 12:48:00 -0700838 apiFilePath android.Path
839}
840
Nan Zhanga40da042018-08-01 12:48:00 -0700841func DroiddocFactory() android.Module {
842 module := &Droiddoc{}
843
844 module.AddProperties(&module.properties,
845 &module.Javadoc.properties)
846
847 InitDroiddocModule(module, android.HostAndDeviceSupported)
848 return module
849}
850
851func DroiddocHostFactory() android.Module {
852 module := &Droiddoc{}
853
854 module.AddProperties(&module.properties,
855 &module.Javadoc.properties)
856
857 InitDroiddocModule(module, android.HostSupported)
858 return module
859}
860
861func (d *Droiddoc) ApiFilePath() android.Path {
862 return d.apiFilePath
863}
864
Nan Zhang581fd212018-01-10 16:06:12 -0800865func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
866 d.Javadoc.addDeps(ctx)
867
Inseob Kim38449af2019-02-28 14:24:05 +0900868 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
869 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
870 }
871
Nan Zhang79614d12018-04-19 18:03:39 -0700872 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800873 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
874 }
Nan Zhang581fd212018-01-10 16:06:12 -0800875}
876
Nan Zhang66dc2362018-08-14 20:41:04 -0700877func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
878 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700879 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800880
Nan Zhanga40da042018-08-01 12:48:00 -0700881 *implicits = append(*implicits, deps.bootClasspath...)
882 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800883
Nan Zhangc94f9d82018-06-26 10:02:26 -0700884 if len(deps.bootClasspath.Strings()) > 0 {
885 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700886 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700887 }
Nan Zhanga40da042018-08-01 12:48:00 -0700888 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700889 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700890 dokkaClasspath := classpath{}
891 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
892 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
893 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700894
Nan Zhang9c69a122018-08-22 10:22:08 -0700895 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
896 // based stubs generation.
897 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
898 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
899 // the correct package name base path.
900 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
901 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
902 } else {
903 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
904 }
Nan Zhang581fd212018-01-10 16:06:12 -0800905
Nan Zhanga40da042018-08-01 12:48:00 -0700906 return flags, nil
907}
Nan Zhang581fd212018-01-10 16:06:12 -0800908
Nan Zhanga40da042018-08-01 12:48:00 -0700909func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700910 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800911
Nan Zhanga40da042018-08-01 12:48:00 -0700912 *implicits = append(*implicits, jsilver)
913 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700914
Nan Zhang46130972018-06-04 11:28:01 -0700915 var date string
916 if runtime.GOOS == "darwin" {
917 date = `date -r`
918 } else {
919 date = `date -d`
920 }
921
Nan Zhang443fa522018-08-20 20:58:28 -0700922 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
923 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
924 // 1.9 language features.
925 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700926 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800927 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700928 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700929
Nan Zhanga40da042018-08-01 12:48:00 -0700930 if String(d.properties.Custom_template) == "" {
931 // TODO: This is almost always droiddoc-templates-sdk
932 ctx.PropertyErrorf("custom_template", "must specify a template")
933 }
934
935 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700936 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700937 *implicits = append(*implicits, t.deps...)
938 args = args + " -templatedir " + t.dir.String()
939 } else {
940 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
941 }
942 })
943
944 if len(d.properties.Html_dirs) > 0 {
Colin Cross07e51612019-03-05 12:46:40 -0800945 htmlDir := d.properties.Html_dirs[0]
Colin Cross8a497952019-03-05 22:25:09 -0800946 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800947 args = args + " -htmldir " + htmlDir
Nan Zhanga40da042018-08-01 12:48:00 -0700948 }
949
950 if len(d.properties.Html_dirs) > 1 {
Colin Cross07e51612019-03-05 12:46:40 -0800951 htmlDir2 := d.properties.Html_dirs[1]
Colin Cross8a497952019-03-05 22:25:09 -0800952 *implicits = append(*implicits, android.PathsForModuleSrc(ctx, []string{filepath.Join(htmlDir2, "**/*")})...)
Colin Cross07e51612019-03-05 12:46:40 -0800953 args = args + " -htmldir2 " + htmlDir2
Nan Zhanga40da042018-08-01 12:48:00 -0700954 }
955
956 if len(d.properties.Html_dirs) > 2 {
957 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
958 }
959
Colin Cross8a497952019-03-05 22:25:09 -0800960 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Nan Zhanga40da042018-08-01 12:48:00 -0700961 *implicits = append(*implicits, knownTags...)
962
963 for _, kt := range knownTags {
964 args = args + " -knowntags " + kt.String()
965 }
966
967 for _, hdf := range d.properties.Hdf {
968 args = args + " -hdf " + hdf
969 }
970
971 if String(d.properties.Proofread_file) != "" {
972 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
973 args = args + " -proofread " + proofreadFile.String()
974 }
975
976 if String(d.properties.Todo_file) != "" {
977 // tricky part:
978 // we should not compute full path for todo_file through PathForModuleOut().
979 // the non-standard doclet will get the full path relative to "-o".
980 args = args + " -todo " + String(d.properties.Todo_file)
981 }
982
983 if String(d.properties.Resourcesdir) != "" {
984 // TODO: should we add files under resourcesDir to the implicits? It seems that
985 // resourcesDir is one sub dir of htmlDir
986 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
987 args = args + " -resourcesdir " + resourcesDir.String()
988 }
989
990 if String(d.properties.Resourcesoutdir) != "" {
991 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
992 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
993 }
994 return args
995}
996
Nan Zhang1598a9e2018-09-04 17:14:32 -0700997func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
998 implicitOutputs *android.WritablePaths) string {
999 var doclavaFlags string
1000 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1001 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1002 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001003 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1004 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001005 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1006 d.apiFilePath = d.apiFile
1007 }
1008
Nan Zhang1598a9e2018-09-04 17:14:32 -07001009 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1010 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1011 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001012 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1013 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001014 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1015 }
1016
1017 if String(d.properties.Private_api_filename) != "" {
1018 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1019 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001020 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1021 }
1022
1023 if String(d.properties.Dex_api_filename) != "" {
1024 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1025 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1026 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1027 }
1028
1029 if String(d.properties.Private_dex_api_filename) != "" {
1030 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1031 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001032 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1033 }
1034
1035 if String(d.properties.Removed_dex_api_filename) != "" {
1036 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1037 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001038 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1039 }
1040
1041 if String(d.properties.Exact_api_filename) != "" {
1042 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1043 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001044 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1045 }
1046
1047 if String(d.properties.Dex_mapping_filename) != "" {
1048 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1049 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001050 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1051 }
1052
Nan Zhang66dc2362018-08-14 20:41:04 -07001053 if String(d.properties.Proguard_filename) != "" {
1054 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1055 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001056 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1057 }
1058
Nan Zhanga40da042018-08-01 12:48:00 -07001059 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001060 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001061 }
1062
1063 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001064 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001065 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001066
1067 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001068}
1069
1070func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1071 var cmds string
1072 if String(d.properties.Static_doc_index_redirect) != "" {
1073 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1074 "static_doc_index_redirect")
1075 *implicits = append(*implicits, static_doc_index_redirect)
1076 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001077 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001078 }
1079
1080 if String(d.properties.Static_doc_properties) != "" {
1081 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1082 "static_doc_properties")
1083 *implicits = append(*implicits, static_doc_properties)
1084 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001085 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001086 }
1087 return cmds
1088}
1089
Nan Zhang1598a9e2018-09-04 17:14:32 -07001090func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1091 implicitOutputs android.WritablePaths,
1092 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1093 ctx.Build(pctx, android.BuildParams{
1094 Rule: javadoc,
1095 Description: "Doclava",
1096 Output: d.Javadoc.stubsSrcJar,
1097 Inputs: d.Javadoc.srcFiles,
1098 Implicits: implicits,
1099 ImplicitOutputs: implicitOutputs,
1100 Args: map[string]string{
1101 "outDir": android.PathForModuleOut(ctx, "out").String(),
1102 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1103 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1104 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1105 "opts": opts,
1106 "bootclasspathArgs": bootclasspathArgs,
1107 "classpathArgs": classpathArgs,
1108 "sourcepathArgs": sourcepathArgs,
1109 "docZip": d.Javadoc.docZip.String(),
1110 "postDoclavaCmds": postDoclavaCmds,
1111 },
1112 })
1113}
1114
1115func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1116 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1117 ctx.Build(pctx, android.BuildParams{
1118 Rule: apiCheck,
1119 Description: "Doclava Check API",
1120 Output: output,
1121 Inputs: nil,
1122 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1123 checkApiClasspath...),
1124 Args: map[string]string{
1125 "msg": msg,
1126 "classpath": checkApiClasspath.FormJavaClassPath(""),
1127 "opts": opts,
1128 "apiFile": apiFile.String(),
1129 "apiFileToCheck": d.apiFile.String(),
1130 "removedApiFile": removedApiFile.String(),
1131 "removedApiFileToCheck": d.removedApiFile.String(),
1132 },
1133 })
1134}
1135
1136func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1137 classpathArgs, opts string) {
1138 ctx.Build(pctx, android.BuildParams{
1139 Rule: dokka,
1140 Description: "Dokka",
1141 Output: d.Javadoc.stubsSrcJar,
1142 Inputs: d.Javadoc.srcFiles,
1143 Implicits: implicits,
1144 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001145 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1146 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1147 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001148 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1149 "classpathArgs": classpathArgs,
1150 "opts": opts,
1151 "docZip": d.Javadoc.docZip.String(),
1152 },
1153 })
1154}
1155
1156func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1157 deps := d.Javadoc.collectDeps(ctx)
1158
1159 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1160 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1161 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1162 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1163
1164 var implicits android.Paths
1165 implicits = append(implicits, d.Javadoc.srcJars...)
1166 implicits = append(implicits, d.Javadoc.argFiles...)
1167
1168 var implicitOutputs android.WritablePaths
1169 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1170 for _, o := range d.Javadoc.properties.Out {
1171 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1172 }
1173
1174 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1175 if err != nil {
1176 return
1177 }
1178
1179 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1180 if Bool(d.properties.Dokka_enabled) {
1181 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1182 } else {
1183 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1184 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1185 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1186 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1187 flags.postDoclavaCmds)
1188 }
1189
1190 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1191 !ctx.Config().IsPdkBuild() {
1192 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1193 "check_api.current.api_file")
1194 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1195 "check_api.current_removed_api_file")
1196
1197 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1198 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1199 fmt.Sprintf(`\n******************************\n`+
1200 `You have tried to change the API from what has been previously approved.\n\n`+
1201 `To make these errors go away, you have two choices:\n`+
1202 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1203 ` errors above.\n\n`+
1204 ` 2. You can update current.txt by executing the following command:\n`+
1205 ` make %s-update-current-api\n\n`+
1206 ` To submit the revised current.txt to the main Android repository,\n`+
1207 ` you will need approval.\n`+
1208 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1209 d.checkCurrentApiTimestamp)
1210
1211 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1212 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1213 d.updateCurrentApiTimestamp)
1214 }
1215
1216 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1217 !ctx.Config().IsPdkBuild() {
1218 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1219 "check_api.last_released.api_file")
1220 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1221 "check_api.last_released.removed_api_file")
1222
1223 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1224 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1225 `\n******************************\n`+
1226 `You have tried to change the API from what has been previously released in\n`+
1227 `an SDK. Please fix the errors listed above.\n`+
1228 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1229 d.checkLastReleasedApiTimestamp)
1230 }
1231}
1232
1233//
1234// Droidstubs
1235//
1236type Droidstubs struct {
1237 Javadoc
1238
Pete Gillin581d6082018-10-22 15:55:04 +01001239 properties DroidstubsProperties
1240 apiFile android.WritablePath
1241 apiXmlFile android.WritablePath
1242 lastReleasedApiXmlFile android.WritablePath
1243 dexApiFile android.WritablePath
1244 privateApiFile android.WritablePath
1245 privateDexApiFile android.WritablePath
1246 removedApiFile android.WritablePath
1247 removedDexApiFile android.WritablePath
1248 apiMappingFile android.WritablePath
1249 exactApiFile android.WritablePath
1250 proguardFile android.WritablePath
1251 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001252
1253 checkCurrentApiTimestamp android.WritablePath
1254 updateCurrentApiTimestamp android.WritablePath
1255 checkLastReleasedApiTimestamp android.WritablePath
1256
Pete Gillin581d6082018-10-22 15:55:04 +01001257 checkNullabilityWarningsTimestamp android.WritablePath
1258
Nan Zhang1598a9e2018-09-04 17:14:32 -07001259 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001260 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001261
1262 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001263
1264 jdiffDocZip android.WritablePath
1265 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001266}
1267
1268func DroidstubsFactory() android.Module {
1269 module := &Droidstubs{}
1270
1271 module.AddProperties(&module.properties,
1272 &module.Javadoc.properties)
1273
1274 InitDroiddocModule(module, android.HostAndDeviceSupported)
1275 return module
1276}
1277
1278func DroidstubsHostFactory() android.Module {
1279 module := &Droidstubs{}
1280
1281 module.AddProperties(&module.properties,
1282 &module.Javadoc.properties)
1283
1284 InitDroiddocModule(module, android.HostSupported)
1285 return module
1286}
1287
1288func (d *Droidstubs) ApiFilePath() android.Path {
1289 return d.apiFilePath
1290}
1291
1292func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1293 d.Javadoc.addDeps(ctx)
1294
Inseob Kim38449af2019-02-28 14:24:05 +09001295 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1296 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1297 }
1298
Nan Zhang1598a9e2018-09-04 17:14:32 -07001299 if len(d.properties.Merge_annotations_dirs) != 0 {
1300 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1301 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1302 }
1303 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001304
Pete Gillin77167902018-09-19 18:16:26 +01001305 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1306 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1307 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1308 }
1309 }
1310
Nan Zhang9c69a122018-08-22 10:22:08 -07001311 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1312 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1313 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1314 }
1315 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001316}
1317
1318func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1319 deps deps) (droiddocBuilderFlags, error) {
1320 var flags droiddocBuilderFlags
1321
1322 *implicits = append(*implicits, deps.bootClasspath...)
1323 *implicits = append(*implicits, deps.classpath...)
1324
1325 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1326 // since it doesn't support system modules yet.
1327 if len(deps.bootClasspath.Strings()) > 0 {
1328 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1329 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1330 }
1331 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1332
Sundong Ahn56dce442018-10-05 18:41:09 +09001333 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001334 return flags, nil
1335}
1336
1337func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1338 implicitOutputs *android.WritablePaths) string {
1339 var metalavaFlags string
1340 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1341 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1342 String(d.properties.Api_filename) != "" {
1343 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1344 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1345 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1346 d.apiFilePath = d.apiFile
1347 }
1348
1349 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1350 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1351 String(d.properties.Removed_api_filename) != "" {
1352 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1353 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1354 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1355 }
1356
1357 if String(d.properties.Private_api_filename) != "" {
1358 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1359 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1360 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1361 }
1362
1363 if String(d.properties.Dex_api_filename) != "" {
1364 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1365 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1366 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1367 }
1368
1369 if String(d.properties.Private_dex_api_filename) != "" {
1370 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1371 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1372 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1373 }
1374
1375 if String(d.properties.Removed_dex_api_filename) != "" {
1376 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1377 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1378 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1379 }
1380
1381 if String(d.properties.Exact_api_filename) != "" {
1382 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1383 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1384 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1385 }
1386
Nan Zhang9c69a122018-08-22 10:22:08 -07001387 if String(d.properties.Dex_mapping_filename) != "" {
1388 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1389 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1390 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1391 }
1392
Nan Zhang199645c2018-09-19 12:40:06 -07001393 if String(d.properties.Proguard_filename) != "" {
1394 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1395 metalavaFlags += " --proguard " + d.proguardFile.String()
1396 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1397 }
1398
Nan Zhang9c69a122018-08-22 10:22:08 -07001399 if Bool(d.properties.Write_sdk_values) {
1400 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1401 }
1402
Nan Zhang1598a9e2018-09-04 17:14:32 -07001403 if Bool(d.properties.Create_doc_stubs) {
1404 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1405 } else {
1406 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1407 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001408 return metalavaFlags
1409}
1410
1411func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001412 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1413 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001414 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001415 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001416 validatingNullability :=
1417 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1418 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001419 migratingNullability := String(d.properties.Previous_api) != ""
1420 if !(migratingNullability || validatingNullability) {
1421 ctx.PropertyErrorf("previous_api",
1422 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001423 }
Pete Gillina262c052018-09-14 14:25:48 +01001424 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001425 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Pete Gillina262c052018-09-14 14:25:48 +01001426 *implicits = append(*implicits, previousApi)
1427 flags += " --migrate-nullness " + previousApi.String()
1428 }
Pete Gillinc382a562018-11-14 18:45:46 +00001429 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross8a497952019-03-05 22:25:09 -08001430 flags += " --validate-nullability-from-list " + android.PathForModuleSrc(ctx, s).String()
Pete Gillinc382a562018-11-14 18:45:46 +00001431 }
Pete Gillina262c052018-09-14 14:25:48 +01001432 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001433 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1434 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1435 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001436 }
Nan Zhanga40da042018-08-01 12:48:00 -07001437
1438 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1439 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1440
Nan Zhangf4936b02018-08-01 15:00:28 -07001441 flags += " --extract-annotations " + d.annotationsZip.String()
1442
Nan Zhang1598a9e2018-09-04 17:14:32 -07001443 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001444 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001445 "has to be non-empty if annotations was enabled!")
1446 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001447 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1448 if t, ok := m.(*ExportedDroiddocDir); ok {
1449 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001450 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001451 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001452 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001453 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1454 }
1455 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001456 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001457 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001458 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001459 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001460
Nan Zhangdee152b2018-12-26 16:06:37 -08001461 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001462}
1463
1464func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1465 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1466 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001467 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1468 if t, ok := m.(*ExportedDroiddocDir); ok {
1469 *implicits = append(*implicits, t.deps...)
1470 flags += " --merge-inclusion-annotations " + t.dir.String()
1471 } else {
1472 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1473 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1474 }
1475 })
Nan Zhanga40da042018-08-01 12:48:00 -07001476
1477 return flags
1478}
1479
Nan Zhang9c69a122018-08-22 10:22:08 -07001480func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1481 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1482 var flags string
1483 if Bool(d.properties.Api_levels_annotations_enabled) {
1484 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1485 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1486
1487 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1488 ctx.PropertyErrorf("api_levels_annotations_dirs",
1489 "has to be non-empty if api levels annotations was enabled!")
1490 }
1491
1492 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1493 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1494 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1495
1496 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1497 if t, ok := m.(*ExportedDroiddocDir); ok {
1498 var androidJars android.Paths
1499 for _, dep := range t.deps {
1500 if strings.HasSuffix(dep.String(), "android.jar") {
1501 androidJars = append(androidJars, dep)
1502 }
1503 }
1504 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001505 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001506 } else {
1507 ctx.PropertyErrorf("api_levels_annotations_dirs",
1508 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1509 }
1510 })
1511
1512 }
1513
1514 return flags
1515}
1516
Nan Zhang71bbe632018-09-17 14:32:21 -07001517func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1518 implicitOutputs *android.WritablePaths) string {
1519 var flags string
1520 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1521 if d.apiFile.String() == "" {
1522 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1523 }
1524
1525 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1526 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1527
1528 flags = " --api-xml " + d.apiXmlFile.String()
1529
1530 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1531 ctx.PropertyErrorf("check_api.last_released.api_file",
1532 "has to be non-empty if jdiff was enabled!")
1533 }
1534 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1535 "check_api.last_released.api_file")
1536 *implicits = append(*implicits, lastReleasedApi)
1537
1538 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1539 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1540
1541 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1542 d.lastReleasedApiXmlFile.String()
1543 }
1544
1545 return flags
1546}
1547
Nan Zhang1598a9e2018-09-04 17:14:32 -07001548func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1549 implicitOutputs android.WritablePaths, javaVersion,
1550 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001551
Nan Zhang86d2d552018-08-09 15:33:27 -07001552 ctx.Build(pctx, android.BuildParams{
1553 Rule: metalava,
1554 Description: "Metalava",
1555 Output: d.Javadoc.stubsSrcJar,
1556 Inputs: d.Javadoc.srcFiles,
1557 Implicits: implicits,
1558 ImplicitOutputs: implicitOutputs,
1559 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001560 "outDir": android.PathForModuleOut(ctx, "out").String(),
1561 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1562 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1563 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001564 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001565 "bootclasspathArgs": bootclasspathArgs,
1566 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001567 "sourcepathArgs": sourcepathArgs,
1568 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001569 },
1570 })
1571}
1572
Nan Zhang1598a9e2018-09-04 17:14:32 -07001573func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1574 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001575 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001576 output android.WritablePath) {
1577 ctx.Build(pctx, android.BuildParams{
1578 Rule: metalavaApiCheck,
1579 Description: "Metalava Check API",
1580 Output: output,
1581 Inputs: d.Javadoc.srcFiles,
1582 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1583 implicits...),
1584 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001585 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001586 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1587 "javaVersion": javaVersion,
1588 "bootclasspathArgs": bootclasspathArgs,
1589 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001590 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001591 "opts": opts,
1592 "msg": msg,
1593 },
1594 })
1595}
1596
Nan Zhang71bbe632018-09-17 14:32:21 -07001597func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1598 implicitOutputs android.WritablePaths,
1599 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1600 ctx.Build(pctx, android.BuildParams{
1601 Rule: javadoc,
1602 Description: "Jdiff",
1603 Output: d.jdiffStubsSrcJar,
1604 Inputs: d.Javadoc.srcFiles,
1605 Implicits: implicits,
1606 ImplicitOutputs: implicitOutputs,
1607 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001608 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1609 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1610 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001611 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1612 "opts": opts,
1613 "bootclasspathArgs": bootclasspathArgs,
1614 "classpathArgs": classpathArgs,
1615 "sourcepathArgs": sourcepathArgs,
1616 "docZip": d.jdiffDocZip.String(),
1617 },
1618 })
1619}
1620
Nan Zhang1598a9e2018-09-04 17:14:32 -07001621func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001622 deps := d.Javadoc.collectDeps(ctx)
1623
1624 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001625
Nan Zhanga40da042018-08-01 12:48:00 -07001626 var implicits android.Paths
1627 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001628 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001629
1630 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001631 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001632 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1633 }
1634
1635 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001636 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001637 jdiffImplicits := implicits
1638
Nan Zhanga40da042018-08-01 12:48:00 -07001639 if err != nil {
1640 return
1641 }
1642
Nan Zhang1598a9e2018-09-04 17:14:32 -07001643 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001644 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1645 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001646 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001647 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001648 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1649
Nan Zhang1598a9e2018-09-04 17:14:32 -07001650 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1651 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1652 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1653 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1654 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001655 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001656 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1657 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001658 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001659 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001660
Nan Zhang1598a9e2018-09-04 17:14:32 -07001661 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1662 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001663 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1664 "check_api.current.api_file")
1665 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1666 "check_api.current_removed_api_file")
1667
Nan Zhang2760dfc2018-08-24 17:32:54 +00001668 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001669 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1670 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001671 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001672
Nan Zhang1598a9e2018-09-04 17:14:32 -07001673 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001674 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001675 fmt.Sprintf(`\n******************************\n`+
1676 `You have tried to change the API from what has been previously approved.\n\n`+
1677 `To make these errors go away, you have two choices:\n`+
1678 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1679 ` errors above.\n\n`+
1680 ` 2. You can update current.txt by executing the following command:\n`+
1681 ` make %s-update-current-api\n\n`+
1682 ` To submit the revised current.txt to the main Android repository,\n`+
1683 ` you will need approval.\n`+
1684 `******************************\n`, ctx.ModuleName()),
1685 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001686
1687 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001688 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1689 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001690 }
Nan Zhanga40da042018-08-01 12:48:00 -07001691
Nan Zhang1598a9e2018-09-04 17:14:32 -07001692 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1693 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001694 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1695 "check_api.last_released.api_file")
1696 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1697 "check_api.last_released.removed_api_file")
1698
Nan Zhang2760dfc2018-08-24 17:32:54 +00001699 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001700 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1701 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001702 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001703
Nan Zhang1598a9e2018-09-04 17:14:32 -07001704 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001705 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001706 `\n******************************\n`+
1707 `You have tried to change the API from what has been previously released in\n`+
1708 `an SDK. Please fix the errors listed above.\n`+
1709 `******************************\n`,
1710 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001711 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001712
Pete Gillin581d6082018-10-22 15:55:04 +01001713 if String(d.properties.Check_nullability_warnings) != "" {
1714 if d.nullabilityWarningsFile == nil {
1715 ctx.PropertyErrorf("check_nullability_warnings",
1716 "Cannot specify check_nullability_warnings unless validating nullability")
1717 }
1718 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1719 "check_nullability_warnings")
1720 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1721 msg := fmt.Sprintf(`\n******************************\n`+
1722 `The warnings encountered during nullability annotation validation did\n`+
1723 `not match the checked in file of expected warnings. The diffs are shown\n`+
1724 `above. You have two options:\n`+
1725 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1726 ` 2. Update the file of expected warnings by running:\n`+
1727 ` cp %s %s\n`+
1728 ` and submitting the updated file as part of your change.`,
1729 d.nullabilityWarningsFile, checkNullabilityWarnings)
1730 ctx.Build(pctx, android.BuildParams{
1731 Rule: nullabilityWarningsCheck,
1732 Description: "Nullability Warnings Check",
1733 Output: d.checkNullabilityWarningsTimestamp,
1734 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1735 Args: map[string]string{
1736 "expected": checkNullabilityWarnings.String(),
1737 "actual": d.nullabilityWarningsFile.String(),
1738 "msg": msg,
1739 },
1740 })
1741 }
1742
Nan Zhang71bbe632018-09-17 14:32:21 -07001743 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1744
Nan Zhang86b06202018-09-21 17:09:21 -07001745 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1746 // since there's cron job downstream that fetch this .zip file periodically.
1747 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001748 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1749 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1750
1751 var jdiffImplicitOutputs android.WritablePaths
1752 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1753
1754 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1755 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1756
Pete Gillin2b1ea2e2019-06-10 14:20:11 +01001757 opts := " -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
Nan Zhang71bbe632018-09-17 14:32:21 -07001758 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1759 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1760 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1761 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1762 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1763
1764 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1765 flags.sourcepathArgs, opts)
1766 }
Nan Zhang581fd212018-01-10 16:06:12 -08001767}
Dan Willemsencc090972018-02-26 14:33:31 -08001768
Nan Zhanga40da042018-08-01 12:48:00 -07001769//
Nan Zhangf4936b02018-08-01 15:00:28 -07001770// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001771//
Dan Willemsencc090972018-02-26 14:33:31 -08001772var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001773var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001774var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001775var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001776
Nan Zhangf4936b02018-08-01 15:00:28 -07001777type ExportedDroiddocDirProperties struct {
1778 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001779 Path *string
1780}
1781
Nan Zhangf4936b02018-08-01 15:00:28 -07001782type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001783 android.ModuleBase
1784
Nan Zhangf4936b02018-08-01 15:00:28 -07001785 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001786
1787 deps android.Paths
1788 dir android.Path
1789}
1790
Nan Zhangf4936b02018-08-01 15:00:28 -07001791func ExportedDroiddocDirFactory() android.Module {
1792 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001793 module.AddProperties(&module.properties)
1794 android.InitAndroidModule(module)
1795 return module
1796}
1797
Nan Zhangf4936b02018-08-01 15:00:28 -07001798func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001799
Nan Zhangf4936b02018-08-01 15:00:28 -07001800func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001801 path := String(d.properties.Path)
1802 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001803 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001804}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001805
1806//
1807// Defaults
1808//
1809type DocDefaults struct {
1810 android.ModuleBase
1811 android.DefaultsModuleBase
1812}
1813
Nan Zhangb2b33de2018-02-23 11:18:47 -08001814func DocDefaultsFactory() android.Module {
1815 module := &DocDefaults{}
1816
1817 module.AddProperties(
1818 &JavadocProperties{},
1819 &DroiddocProperties{},
1820 )
1821
1822 android.InitDefaultsModule(module)
1823
1824 return module
1825}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001826
1827func StubsDefaultsFactory() android.Module {
1828 module := &DocDefaults{}
1829
1830 module.AddProperties(
1831 &JavadocProperties{},
1832 &DroidstubsProperties{},
1833 )
1834
1835 android.InitDefaultsModule(module)
1836
1837 return module
1838}