blob: ef9100988790f6c255ef0ad7a46fdd860f3538a0 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "android/soong/android"
19 "android/soong/java/config"
20 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080021 "path/filepath"
Nan Zhang46130972018-06-04 11:28:01 -070022 "runtime"
Nan Zhang581fd212018-01-10 16:06:12 -080023 "strings"
24
25 "github.com/google/blueprint"
26)
27
28var (
29 javadoc = pctx.AndroidStaticRule("javadoc",
30 blueprint.RuleParams{
31 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070032 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang40b41b42018-10-02 16:11:17 -070033 `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070034 `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` +
Nan Zhang581fd212018-01-10 16:06:12 -080035 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Nan Zhange2ba5d42018-07-11 15:16:55 -070037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`,
Nan Zhang581fd212018-01-10 16:06:12 -080038 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070039 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080040 "${config.JavadocCmd}",
41 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 },
Nan Zhang40b41b42018-10-02 16:11:17 -070043 CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
44 Rspfile: "$out.rsp",
45 RspfileContent: "$in",
46 Restat: true,
Nan Zhang581fd212018-01-10 16:06:12 -080047 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070048 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang1598a9e2018-09-04 17:14:32 -070049 "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070050
51 apiCheck = pctx.AndroidStaticRule("apiCheck",
52 blueprint.RuleParams{
53 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
54 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090055 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070056 CommandDeps: []string{
57 "${config.ApiCheckCmd}",
58 },
59 },
60 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
61
62 updateApi = pctx.AndroidStaticRule("updateApi",
63 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070064 Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` +
Nan Zhang61819ce2018-05-04 18:49:16 -070065 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
66 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070067 "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile")
Nan Zhang79614d12018-04-19 18:03:39 -070068
69 metalava = pctx.AndroidStaticRule("metalava",
70 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070071 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
72 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070073 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070074 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -080075 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070076 `$opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070077 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
78 CommandDeps: []string{
79 "${config.ZipSyncCmd}",
80 "${config.JavaCmd}",
81 "${config.MetalavaJar}",
Nan Zhang79614d12018-04-19 18:03:39 -070082 "${config.SoongZipCmd}",
83 },
84 Rspfile: "$out.rsp",
85 RspfileContent: "$in",
86 Restat: true,
87 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070088 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
89 "classpathArgs", "sourcepathArgs", "opts")
Nan Zhang2760dfc2018-08-24 17:32:54 +000090
91 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
92 blueprint.RuleParams{
93 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
94 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
95 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Tor Norbye76c875a2018-12-26 20:34:29 -080096 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet --format=v2 ` +
Nan Zhang2760dfc2018-08-24 17:32:54 +000097 `$opts && touch $out ) || ` +
98 `( echo -e "$msg" ; exit 38 )`,
99 CommandDeps: []string{
100 "${config.ZipSyncCmd}",
101 "${config.JavaCmd}",
102 "${config.MetalavaJar}",
103 },
104 Rspfile: "$out.rsp",
105 RspfileContent: "$in",
106 },
Nan Zhang1598a9e2018-09-04 17:14:32 -0700107 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg")
108
Pete Gillin581d6082018-10-22 15:55:04 +0100109 nullabilityWarningsCheck = pctx.AndroidStaticRule("nullabilityWarningsCheck",
110 blueprint.RuleParams{
111 Command: `( diff $expected $actual && touch $out ) || ( echo -e "$msg" ; exit 38 )`,
112 },
113 "expected", "actual", "msg")
114
Nan Zhang1598a9e2018-09-04 17:14:32 -0700115 dokka = pctx.AndroidStaticRule("dokka",
116 blueprint.RuleParams{
117 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
118 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
119 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
120 `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` +
121 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
122 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
123 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
124 CommandDeps: []string{
125 "${config.ZipSyncCmd}",
126 "${config.DokkaJar}",
127 "${config.MetalavaJar}",
128 "${config.SoongZipCmd}",
129 },
130 Restat: true,
131 },
132 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800133)
134
135func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800136 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700137 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800138
Nan Zhang581fd212018-01-10 16:06:12 -0800139 android.RegisterModuleType("droiddoc", DroiddocFactory)
140 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700141 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800142 android.RegisterModuleType("javadoc", JavadocFactory)
143 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700144
145 android.RegisterModuleType("droidstubs", DroidstubsFactory)
146 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800147}
148
Colin Crossa1ce2a02018-06-20 15:19:39 -0700149var (
150 srcsLibTag = dependencyTag{name: "sources from javalib"}
151)
152
Nan Zhang581fd212018-01-10 16:06:12 -0800153type JavadocProperties struct {
154 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
155 // or .aidl files.
156 Srcs []string `android:"arch_variant"`
157
158 // list of directories rooted at the Android.bp file that will
159 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800160 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800161
162 // list of source files that should not be used to build the Java module.
163 // This is most useful in the arch/multilib variants to remove non-common files
164 // filegroup or genrule can be included within this property.
165 Exclude_srcs []string `android:"arch_variant"`
166
Nan Zhangb2b33de2018-02-23 11:18:47 -0800167 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800168 Libs []string `android:"arch_variant"`
169
Nan Zhang5994b622018-09-21 16:39:51 -0700170 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
171 // ext, and framework for device targets)
172 No_standard_libs *bool
173
Nan Zhange66c7272018-03-06 12:59:27 -0800174 // don't build against the framework libraries (legacy-test, core-junit,
175 // ext, and framework for device targets)
176 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.
205 Arg_files []string
206
207 // user customized droiddoc args.
208 // Available variables for substitution:
209 //
210 // $(location <label>): the path to the arg_files with name <label>
211 Args *string
212
213 // names of the output files used in args that will be generated
214 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800215}
216
Nan Zhang61819ce2018-05-04 18:49:16 -0700217type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900218 // path to the API txt file that the new API extracted from source code is checked
219 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700220 Api_file *string
221
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900222 // path to the API txt file that the new @removed API extractd from source code is
223 // checked against. The path can be local to the module or from other module (via
224 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700225 Removed_api_file *string
226
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900227 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700228 Args *string
229}
230
Nan Zhang581fd212018-01-10 16:06:12 -0800231type DroiddocProperties struct {
232 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800233 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800234
Nan Zhanga40da042018-08-01 12:48:00 -0700235 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800237
238 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800239 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800240
241 // proofread file contains all of the text content of the javadocs concatenated into one file,
242 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800243 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800244
245 // a todo file lists the program elements that are missing documentation.
246 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800247 Todo_file *string
248
249 // directory under current module source that provide additional resources (images).
250 Resourcesdir *string
251
252 // resources output directory under out/soong/.intermediates.
253 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800254
Nan Zhange2ba5d42018-07-11 15:16:55 -0700255 // if set to true, collect the values used by the Dev tools and
256 // write them in files packaged with the SDK. Defaults to false.
257 Write_sdk_values *bool
258
259 // index.html under current module will be copied to docs out dir, if not null.
260 Static_doc_index_redirect *string
261
262 // source.properties under current module will be copied to docs out dir, if not null.
263 Static_doc_properties *string
264
Nan Zhang581fd212018-01-10 16:06:12 -0800265 // a list of files under current module source dir which contains known tags in Java sources.
266 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800267 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700268
269 // the tag name used to distinguish if the API files belong to public/system/test.
270 Api_tag_name *string
271
272 // the generated public API filename by Doclava.
273 Api_filename *string
274
David Brazdilfbe4cc32018-05-31 13:56:46 +0100275 // the generated public Dex API filename by Doclava.
276 Dex_api_filename *string
277
Nan Zhang28c68b92018-03-13 16:17:01 -0700278 // the generated private API filename by Doclava.
279 Private_api_filename *string
280
281 // the generated private Dex API filename by Doclava.
282 Private_dex_api_filename *string
283
284 // the generated removed API filename by Doclava.
285 Removed_api_filename *string
286
David Brazdilaac0c3c2018-04-24 16:23:29 +0100287 // the generated removed Dex API filename by Doclava.
288 Removed_dex_api_filename *string
289
Mathew Inwood76c3de12018-06-22 15:28:11 +0100290 // mapping of dex signatures to source file and line number. This is a temporary property and
291 // will be deleted; you probably shouldn't be using it.
292 Dex_mapping_filename *string
293
Nan Zhang28c68b92018-03-13 16:17:01 -0700294 // the generated exact API filename by Doclava.
295 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700296
Nan Zhang66dc2362018-08-14 20:41:04 -0700297 // the generated proguard filename by Doclava.
298 Proguard_filename *string
299
Nan Zhang853f4202018-04-12 16:55:56 -0700300 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
301 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700302
303 Check_api struct {
304 Last_released ApiToCheck
305
306 Current ApiToCheck
307 }
Nan Zhang79614d12018-04-19 18:03:39 -0700308
Nan Zhang1598a9e2018-09-04 17:14:32 -0700309 // if set to true, generate docs through Dokka instead of Doclava.
310 Dokka_enabled *bool
311}
312
313type DroidstubsProperties struct {
314 // the tag name used to distinguish if the API files belong to public/system/test.
315 Api_tag_name *string
316
Nan Zhang199645c2018-09-19 12:40:06 -0700317 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700318 Api_filename *string
319
Nan Zhang199645c2018-09-19 12:40:06 -0700320 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700321 Dex_api_filename *string
322
Nan Zhang199645c2018-09-19 12:40:06 -0700323 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700324 Private_api_filename *string
325
Nan Zhang199645c2018-09-19 12:40:06 -0700326 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700327 Private_dex_api_filename *string
328
Nan Zhang199645c2018-09-19 12:40:06 -0700329 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700330 Removed_api_filename *string
331
Nan Zhang199645c2018-09-19 12:40:06 -0700332 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700333 Removed_dex_api_filename *string
334
Nan Zhang9c69a122018-08-22 10:22:08 -0700335 // mapping of dex signatures to source file and line number. This is a temporary property and
336 // will be deleted; you probably shouldn't be using it.
337 Dex_mapping_filename *string
338
Nan Zhang199645c2018-09-19 12:40:06 -0700339 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700340 Exact_api_filename *string
341
Nan Zhang199645c2018-09-19 12:40:06 -0700342 // the generated proguard filename by Metalava.
343 Proguard_filename *string
344
Nan Zhang1598a9e2018-09-04 17:14:32 -0700345 Check_api struct {
346 Last_released ApiToCheck
347
348 Current ApiToCheck
349 }
Nan Zhang79614d12018-04-19 18:03:39 -0700350
351 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700352 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700353
354 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700355 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700356
Pete Gillin77167902018-09-19 18:16:26 +0100357 // 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 -0700358 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700359
Pete Gillin77167902018-09-19 18:16:26 +0100360 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
361 Merge_inclusion_annotations_dirs []string
362
Pete Gillinc382a562018-11-14 18:45:46 +0000363 // a file containing a list of classes to do nullability validation for.
364 Validate_nullability_from_list *string
365
Pete Gillin581d6082018-10-22 15:55:04 +0100366 // a file containing expected warnings produced by validation of nullability annotations.
367 Check_nullability_warnings *string
368
Nan Zhang1598a9e2018-09-04 17:14:32 -0700369 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
370 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700371
372 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
373 Api_levels_annotations_enabled *bool
374
375 // the dirs which Metalava extracts API levels annotations from.
376 Api_levels_annotations_dirs []string
377
378 // if set to true, collect the values used by the Dev tools and
379 // write them in files packaged with the SDK. Defaults to false.
380 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700381
382 // If set to true, .xml based public API file will be also generated, and
383 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
384 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800385}
386
Nan Zhanga40da042018-08-01 12:48:00 -0700387//
388// Common flags passed down to build rule
389//
390type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700391 bootClasspathArgs string
392 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700393 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700394 dokkaClasspathArgs string
395 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700396
Nan Zhanga40da042018-08-01 12:48:00 -0700397 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700398 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700399 postDoclavaCmds string
400
Nan Zhang9c69a122018-08-22 10:22:08 -0700401 metalavaStubsFlags string
402 metalavaAnnotationsFlags string
Nan Zhangdee152b2018-12-26 16:06:37 -0800403 metalavaMergeAnnoDirFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100404 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700405 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700406
Nan Zhang71bbe632018-09-17 14:32:21 -0700407 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700408}
409
410func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
411 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
412 android.InitDefaultableModule(module)
413}
414
Nan Zhang1598a9e2018-09-04 17:14:32 -0700415func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
416 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
417 return true
418 } else if String(apiToCheck.Api_file) != "" {
419 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
420 } else if String(apiToCheck.Removed_api_file) != "" {
421 panic("for " + apiVersionTag + " api_file has to be non-empty!")
422 }
423
424 return false
425}
426
427type ApiFilePath interface {
428 ApiFilePath() android.Path
429}
430
431func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
432 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
433 ctx.Build(pctx, android.BuildParams{
434 Rule: updateApi,
435 Description: "Update API",
436 Output: output,
437 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
438 destApiFile, destRemovedApiFile),
439 Args: map[string]string{
440 "destApiFile": destApiFile.String(),
441 "srcApiFile": srcApiFile.String(),
442 "destRemovedApiFile": destRemovedApiFile.String(),
443 "srcRemovedApiFile": srcRemovedApiFile.String(),
444 },
445 })
446}
447
Nan Zhanga40da042018-08-01 12:48:00 -0700448//
449// Javadoc
450//
Nan Zhang581fd212018-01-10 16:06:12 -0800451type Javadoc struct {
452 android.ModuleBase
453 android.DefaultableModuleBase
454
455 properties JavadocProperties
456
457 srcJars android.Paths
458 srcFiles android.Paths
459 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700460 argFiles android.Paths
461
462 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800463
Nan Zhangccff0f72018-03-08 17:26:16 -0800464 docZip android.WritablePath
465 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800466}
467
Nan Zhangb2b33de2018-02-23 11:18:47 -0800468func (j *Javadoc) Srcs() android.Paths {
469 return android.Paths{j.stubsSrcJar}
470}
471
Nan Zhang581fd212018-01-10 16:06:12 -0800472func JavadocFactory() android.Module {
473 module := &Javadoc{}
474
475 module.AddProperties(&module.properties)
476
477 InitDroiddocModule(module, android.HostAndDeviceSupported)
478 return module
479}
480
481func JavadocHostFactory() android.Module {
482 module := &Javadoc{}
483
484 module.AddProperties(&module.properties)
485
486 InitDroiddocModule(module, android.HostSupported)
487 return module
488}
489
Nan Zhanga40da042018-08-01 12:48:00 -0700490var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800491
Colin Cross83bb3162018-06-25 15:48:06 -0700492func (j *Javadoc) sdkVersion() string {
493 return String(j.properties.Sdk_version)
494}
495
496func (j *Javadoc) minSdkVersion() string {
497 return j.sdkVersion()
498}
499
Dan Willemsen419290a2018-10-31 15:28:47 -0700500func (j *Javadoc) targetSdkVersion() string {
501 return j.sdkVersion()
502}
503
Nan Zhang581fd212018-01-10 16:06:12 -0800504func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
505 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700506 if !Bool(j.properties.No_standard_libs) {
507 sdkDep := decodeSdkDep(ctx, sdkContext(j))
508 if sdkDep.useDefaultLibs {
509 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
510 if ctx.Config().TargetOpenJDK9() {
511 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
512 }
513 if !Bool(j.properties.No_framework_libs) {
514 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
515 }
516 } else if sdkDep.useModule {
517 if ctx.Config().TargetOpenJDK9() {
518 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
519 }
520 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700521 }
Nan Zhang581fd212018-01-10 16:06:12 -0800522 }
523 }
524
Colin Cross42d48b72018-08-29 14:10:52 -0700525 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700526 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700527 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700528 }
Nan Zhang581fd212018-01-10 16:06:12 -0800529
530 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
531
532 // exclude_srcs may contain filegroup or genrule.
533 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700534
535 // arg_files may contains filegroup or genrule.
536 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800537}
538
Nan Zhangb2b33de2018-02-23 11:18:47 -0800539func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
540 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
541 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900542 // convert foo.bar.baz to foo/bar/baz
543 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
544 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800545 if _, found := whitelistPathPrefixes[prefix]; !found {
546 whitelistPathPrefixes[prefix] = true
547 }
548 }
549 }
550}
551
Nan Zhanga40da042018-08-01 12:48:00 -0700552func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
553 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900554
555 // aidl flags.
556 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
557 if len(aidlFlags) > 0 {
558 // optimization.
559 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
560 flags.aidlFlags = "$aidlFlags"
561 }
562
563 return flags
564}
565
566func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
567 aidlIncludeDirs android.Paths) []string {
568
569 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
570 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
571
572 var flags []string
573 if aidlPreprocess.Valid() {
574 flags = append(flags, "-p"+aidlPreprocess.String())
575 } else {
576 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
577 }
578
579 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
580 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
581 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
582 flags = append(flags, "-I"+src.String())
583 }
584
585 return flags
586}
587
588func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700589 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900590
591 outSrcFiles := make(android.Paths, 0, len(srcFiles))
592
593 for _, srcFile := range srcFiles {
594 switch srcFile.Ext() {
595 case ".aidl":
596 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
597 outSrcFiles = append(outSrcFiles, javaFile)
598 default:
599 outSrcFiles = append(outSrcFiles, srcFile)
600 }
601 }
602
603 return outSrcFiles
604}
605
Nan Zhang581fd212018-01-10 16:06:12 -0800606func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
607 var deps deps
608
Colin Cross83bb3162018-06-25 15:48:06 -0700609 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800610 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700611 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800612 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700613 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800614 }
615
616 ctx.VisitDirectDeps(func(module android.Module) {
617 otherName := ctx.OtherModuleName(module)
618 tag := ctx.OtherModuleDependencyTag(module)
619
Colin Cross2d24c1b2018-05-23 10:59:18 -0700620 switch tag {
621 case bootClasspathTag:
622 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800623 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700624 } else {
625 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
626 }
627 case libTag:
628 switch dep := module.(type) {
629 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900630 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700631 case SdkLibraryDependency:
Sundong Ahn054b19a2018-10-19 13:46:09 +0900632 deps.classpath = append(deps.classpath, dep.ImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700633 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800634 checkProducesJars(ctx, dep)
635 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800636 default:
637 ctx.ModuleErrorf("depends on non-java module %q", otherName)
638 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700639 case srcsLibTag:
640 switch dep := module.(type) {
641 case Dependency:
642 srcs := dep.(SrcDependency).CompiledSrcs()
643 whitelistPathPrefixes := make(map[string]bool)
644 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
645 for _, src := range srcs {
646 if _, ok := src.(android.WritablePath); ok { // generated sources
647 deps.srcs = append(deps.srcs, src)
648 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700649 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700650 if strings.HasPrefix(src.Rel(), k) {
651 deps.srcs = append(deps.srcs, src)
652 break
653 }
654 }
655 }
656 }
657 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
658 default:
659 ctx.ModuleErrorf("depends on non-java module %q", otherName)
660 }
Nan Zhang357466b2018-04-17 17:38:36 -0700661 case systemModulesTag:
662 if deps.systemModules != nil {
663 panic("Found two system module dependencies")
664 }
665 sm := module.(*SystemModules)
666 if sm.outputFile == nil {
667 panic("Missing directory for system module dependency")
668 }
669 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800670 }
671 })
672 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
673 // may contain filegroup or genrule.
674 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700675 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900676 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800677
678 // srcs may depend on some genrule output.
679 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800680 j.srcJars = append(j.srcJars, deps.srcJars...)
681
Nan Zhang581fd212018-01-10 16:06:12 -0800682 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800683 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800684
685 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800686 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800687
Nan Zhang9c69a122018-08-22 10:22:08 -0700688 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800689 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
690 }
691 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800692
Nan Zhang1598a9e2018-09-04 17:14:32 -0700693 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
694 argFilesMap := map[string]android.Path{}
695
696 for _, f := range j.argFiles {
697 if _, exists := argFilesMap[f.Rel()]; !exists {
698 argFilesMap[f.Rel()] = f
699 } else {
700 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
701 f, argFilesMap[f.Rel()], f.Rel())
702 }
703 }
704
705 var err error
706 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
707 if strings.HasPrefix(name, "location ") {
708 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
709 if f, ok := argFilesMap[label]; ok {
710 return f.String(), nil
711 } else {
712 return "", fmt.Errorf("unknown location label %q", label)
713 }
714 } else if name == "genDir" {
715 return android.PathForModuleGen(ctx).String(), nil
716 }
717 return "", fmt.Errorf("unknown variable '$(%s)'", name)
718 })
719
720 if err != nil {
721 ctx.PropertyErrorf("args", "%s", err.Error())
722 }
723
Nan Zhang581fd212018-01-10 16:06:12 -0800724 return deps
725}
726
727func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
728 j.addDeps(ctx)
729}
730
731func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
732 deps := j.collectDeps(ctx)
733
734 var implicits android.Paths
735 implicits = append(implicits, deps.bootClasspath...)
736 implicits = append(implicits, deps.classpath...)
737
Nan Zhang1598a9e2018-09-04 17:14:32 -0700738 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700739
Colin Cross83bb3162018-06-25 15:48:06 -0700740 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700741 if len(deps.bootClasspath) > 0 {
742 var systemModules classpath
743 if deps.systemModules != nil {
744 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800745 }
Colin Cross997262f2018-06-19 22:49:39 -0700746 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
747 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800748 }
749 if len(deps.classpath.Strings()) > 0 {
750 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
751 }
752
753 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700754 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800755
Nan Zhangaf322cc2018-06-19 15:15:38 -0700756 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800757
Nan Zhang1598a9e2018-09-04 17:14:32 -0700758 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
759
Nan Zhang581fd212018-01-10 16:06:12 -0800760 ctx.Build(pctx, android.BuildParams{
761 Rule: javadoc,
762 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800763 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800764 ImplicitOutput: j.docZip,
765 Inputs: j.srcFiles,
766 Implicits: implicits,
767 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700768 "outDir": android.PathForModuleOut(ctx, "out").String(),
769 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
770 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800771 "srcJars": strings.Join(j.srcJars.Strings(), " "),
772 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700773 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800774 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700775 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800776 "docZip": j.docZip.String(),
777 },
778 })
779}
780
Nan Zhanga40da042018-08-01 12:48:00 -0700781//
782// Droiddoc
783//
784type Droiddoc struct {
785 Javadoc
786
787 properties DroiddocProperties
788 apiFile android.WritablePath
789 dexApiFile android.WritablePath
790 privateApiFile android.WritablePath
791 privateDexApiFile android.WritablePath
792 removedApiFile android.WritablePath
793 removedDexApiFile android.WritablePath
794 exactApiFile android.WritablePath
795 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700796 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700797
798 checkCurrentApiTimestamp android.WritablePath
799 updateCurrentApiTimestamp android.WritablePath
800 checkLastReleasedApiTimestamp android.WritablePath
801
Nan Zhanga40da042018-08-01 12:48:00 -0700802 apiFilePath android.Path
803}
804
Nan Zhanga40da042018-08-01 12:48:00 -0700805func DroiddocFactory() android.Module {
806 module := &Droiddoc{}
807
808 module.AddProperties(&module.properties,
809 &module.Javadoc.properties)
810
811 InitDroiddocModule(module, android.HostAndDeviceSupported)
812 return module
813}
814
815func DroiddocHostFactory() android.Module {
816 module := &Droiddoc{}
817
818 module.AddProperties(&module.properties,
819 &module.Javadoc.properties)
820
821 InitDroiddocModule(module, android.HostSupported)
822 return module
823}
824
825func (d *Droiddoc) ApiFilePath() android.Path {
826 return d.apiFilePath
827}
828
Nan Zhang581fd212018-01-10 16:06:12 -0800829func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
830 d.Javadoc.addDeps(ctx)
831
Nan Zhang79614d12018-04-19 18:03:39 -0700832 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800833 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
834 }
835
Nan Zhang581fd212018-01-10 16:06:12 -0800836 // knowntags may contain filegroup or genrule.
837 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700838
Nan Zhange2ba5d42018-07-11 15:16:55 -0700839 if String(d.properties.Static_doc_index_redirect) != "" {
840 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
841 }
842
843 if String(d.properties.Static_doc_properties) != "" {
844 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
845 }
846
Nan Zhang1598a9e2018-09-04 17:14:32 -0700847 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700848 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
849 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
850 }
851
Nan Zhang1598a9e2018-09-04 17:14:32 -0700852 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700853 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
854 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
855 }
Nan Zhang581fd212018-01-10 16:06:12 -0800856}
857
Nan Zhang66dc2362018-08-14 20:41:04 -0700858func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
859 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700860 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800861
Nan Zhanga40da042018-08-01 12:48:00 -0700862 *implicits = append(*implicits, deps.bootClasspath...)
863 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800864
Nan Zhangc94f9d82018-06-26 10:02:26 -0700865 if len(deps.bootClasspath.Strings()) > 0 {
866 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700867 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700868 }
Nan Zhanga40da042018-08-01 12:48:00 -0700869 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700870 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700871 dokkaClasspath := classpath{}
872 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
873 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
874 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700875
Nan Zhang9c69a122018-08-22 10:22:08 -0700876 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
877 // based stubs generation.
878 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
879 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
880 // the correct package name base path.
881 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
882 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
883 } else {
884 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
885 }
Nan Zhang581fd212018-01-10 16:06:12 -0800886
Nan Zhanga40da042018-08-01 12:48:00 -0700887 return flags, nil
888}
Nan Zhang581fd212018-01-10 16:06:12 -0800889
Nan Zhanga40da042018-08-01 12:48:00 -0700890func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700891 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800892
Nan Zhanga40da042018-08-01 12:48:00 -0700893 *implicits = append(*implicits, jsilver)
894 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700895
Nan Zhang46130972018-06-04 11:28:01 -0700896 var date string
897 if runtime.GOOS == "darwin" {
898 date = `date -r`
899 } else {
900 date = `date -d`
901 }
902
Nan Zhang443fa522018-08-20 20:58:28 -0700903 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
904 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
905 // 1.9 language features.
906 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700907 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800908 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700909 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700910
Nan Zhanga40da042018-08-01 12:48:00 -0700911 if String(d.properties.Custom_template) == "" {
912 // TODO: This is almost always droiddoc-templates-sdk
913 ctx.PropertyErrorf("custom_template", "must specify a template")
914 }
915
916 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700917 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700918 *implicits = append(*implicits, t.deps...)
919 args = args + " -templatedir " + t.dir.String()
920 } else {
921 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
922 }
923 })
924
925 if len(d.properties.Html_dirs) > 0 {
926 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
927 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
928 args = args + " -htmldir " + htmlDir.String()
929 }
930
931 if len(d.properties.Html_dirs) > 1 {
932 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
933 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
934 args = args + " -htmldir2 " + htmlDir2.String()
935 }
936
937 if len(d.properties.Html_dirs) > 2 {
938 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
939 }
940
941 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
942 *implicits = append(*implicits, knownTags...)
943
944 for _, kt := range knownTags {
945 args = args + " -knowntags " + kt.String()
946 }
947
948 for _, hdf := range d.properties.Hdf {
949 args = args + " -hdf " + hdf
950 }
951
952 if String(d.properties.Proofread_file) != "" {
953 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
954 args = args + " -proofread " + proofreadFile.String()
955 }
956
957 if String(d.properties.Todo_file) != "" {
958 // tricky part:
959 // we should not compute full path for todo_file through PathForModuleOut().
960 // the non-standard doclet will get the full path relative to "-o".
961 args = args + " -todo " + String(d.properties.Todo_file)
962 }
963
964 if String(d.properties.Resourcesdir) != "" {
965 // TODO: should we add files under resourcesDir to the implicits? It seems that
966 // resourcesDir is one sub dir of htmlDir
967 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
968 args = args + " -resourcesdir " + resourcesDir.String()
969 }
970
971 if String(d.properties.Resourcesoutdir) != "" {
972 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
973 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
974 }
975 return args
976}
977
Nan Zhang1598a9e2018-09-04 17:14:32 -0700978func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
979 implicitOutputs *android.WritablePaths) string {
980 var doclavaFlags string
981 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
982 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
983 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700984 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
985 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700986 *implicitOutputs = append(*implicitOutputs, d.apiFile)
987 d.apiFilePath = d.apiFile
988 }
989
Nan Zhang1598a9e2018-09-04 17:14:32 -0700990 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
991 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
992 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700993 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
994 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700995 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
996 }
997
998 if String(d.properties.Private_api_filename) != "" {
999 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1000 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001001 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1002 }
1003
1004 if String(d.properties.Dex_api_filename) != "" {
1005 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1006 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1007 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1008 }
1009
1010 if String(d.properties.Private_dex_api_filename) != "" {
1011 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1012 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001013 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1014 }
1015
1016 if String(d.properties.Removed_dex_api_filename) != "" {
1017 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1018 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001019 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1020 }
1021
1022 if String(d.properties.Exact_api_filename) != "" {
1023 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1024 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001025 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1026 }
1027
1028 if String(d.properties.Dex_mapping_filename) != "" {
1029 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1030 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001031 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1032 }
1033
Nan Zhang66dc2362018-08-14 20:41:04 -07001034 if String(d.properties.Proguard_filename) != "" {
1035 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1036 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001037 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1038 }
1039
Nan Zhanga40da042018-08-01 12:48:00 -07001040 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001041 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001042 }
1043
1044 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001045 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001046 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001047
1048 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001049}
1050
1051func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1052 var cmds string
1053 if String(d.properties.Static_doc_index_redirect) != "" {
1054 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1055 "static_doc_index_redirect")
1056 *implicits = append(*implicits, static_doc_index_redirect)
1057 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001058 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001059 }
1060
1061 if String(d.properties.Static_doc_properties) != "" {
1062 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1063 "static_doc_properties")
1064 *implicits = append(*implicits, static_doc_properties)
1065 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001066 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001067 }
1068 return cmds
1069}
1070
Nan Zhang1598a9e2018-09-04 17:14:32 -07001071func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1072 implicitOutputs android.WritablePaths,
1073 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1074 ctx.Build(pctx, android.BuildParams{
1075 Rule: javadoc,
1076 Description: "Doclava",
1077 Output: d.Javadoc.stubsSrcJar,
1078 Inputs: d.Javadoc.srcFiles,
1079 Implicits: implicits,
1080 ImplicitOutputs: implicitOutputs,
1081 Args: map[string]string{
1082 "outDir": android.PathForModuleOut(ctx, "out").String(),
1083 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1084 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1085 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1086 "opts": opts,
1087 "bootclasspathArgs": bootclasspathArgs,
1088 "classpathArgs": classpathArgs,
1089 "sourcepathArgs": sourcepathArgs,
1090 "docZip": d.Javadoc.docZip.String(),
1091 "postDoclavaCmds": postDoclavaCmds,
1092 },
1093 })
1094}
1095
1096func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1097 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1098 ctx.Build(pctx, android.BuildParams{
1099 Rule: apiCheck,
1100 Description: "Doclava Check API",
1101 Output: output,
1102 Inputs: nil,
1103 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1104 checkApiClasspath...),
1105 Args: map[string]string{
1106 "msg": msg,
1107 "classpath": checkApiClasspath.FormJavaClassPath(""),
1108 "opts": opts,
1109 "apiFile": apiFile.String(),
1110 "apiFileToCheck": d.apiFile.String(),
1111 "removedApiFile": removedApiFile.String(),
1112 "removedApiFileToCheck": d.removedApiFile.String(),
1113 },
1114 })
1115}
1116
1117func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1118 classpathArgs, opts string) {
1119 ctx.Build(pctx, android.BuildParams{
1120 Rule: dokka,
1121 Description: "Dokka",
1122 Output: d.Javadoc.stubsSrcJar,
1123 Inputs: d.Javadoc.srcFiles,
1124 Implicits: implicits,
1125 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001126 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1127 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1128 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001129 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1130 "classpathArgs": classpathArgs,
1131 "opts": opts,
1132 "docZip": d.Javadoc.docZip.String(),
1133 },
1134 })
1135}
1136
1137func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1138 deps := d.Javadoc.collectDeps(ctx)
1139
1140 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1141 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1142 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1143 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1144
1145 var implicits android.Paths
1146 implicits = append(implicits, d.Javadoc.srcJars...)
1147 implicits = append(implicits, d.Javadoc.argFiles...)
1148
1149 var implicitOutputs android.WritablePaths
1150 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1151 for _, o := range d.Javadoc.properties.Out {
1152 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1153 }
1154
1155 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1156 if err != nil {
1157 return
1158 }
1159
1160 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1161 if Bool(d.properties.Dokka_enabled) {
1162 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1163 } else {
1164 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1165 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1166 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1167 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1168 flags.postDoclavaCmds)
1169 }
1170
1171 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1172 !ctx.Config().IsPdkBuild() {
1173 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1174 "check_api.current.api_file")
1175 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1176 "check_api.current_removed_api_file")
1177
1178 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1179 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1180 fmt.Sprintf(`\n******************************\n`+
1181 `You have tried to change the API from what has been previously approved.\n\n`+
1182 `To make these errors go away, you have two choices:\n`+
1183 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1184 ` errors above.\n\n`+
1185 ` 2. You can update current.txt by executing the following command:\n`+
1186 ` make %s-update-current-api\n\n`+
1187 ` To submit the revised current.txt to the main Android repository,\n`+
1188 ` you will need approval.\n`+
1189 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1190 d.checkCurrentApiTimestamp)
1191
1192 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1193 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1194 d.updateCurrentApiTimestamp)
1195 }
1196
1197 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1198 !ctx.Config().IsPdkBuild() {
1199 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1200 "check_api.last_released.api_file")
1201 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1202 "check_api.last_released.removed_api_file")
1203
1204 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1205 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1206 `\n******************************\n`+
1207 `You have tried to change the API from what has been previously released in\n`+
1208 `an SDK. Please fix the errors listed above.\n`+
1209 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1210 d.checkLastReleasedApiTimestamp)
1211 }
1212}
1213
1214//
1215// Droidstubs
1216//
1217type Droidstubs struct {
1218 Javadoc
1219
Pete Gillin581d6082018-10-22 15:55:04 +01001220 properties DroidstubsProperties
1221 apiFile android.WritablePath
1222 apiXmlFile android.WritablePath
1223 lastReleasedApiXmlFile android.WritablePath
1224 dexApiFile android.WritablePath
1225 privateApiFile android.WritablePath
1226 privateDexApiFile android.WritablePath
1227 removedApiFile android.WritablePath
1228 removedDexApiFile android.WritablePath
1229 apiMappingFile android.WritablePath
1230 exactApiFile android.WritablePath
1231 proguardFile android.WritablePath
1232 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001233
1234 checkCurrentApiTimestamp android.WritablePath
1235 updateCurrentApiTimestamp android.WritablePath
1236 checkLastReleasedApiTimestamp android.WritablePath
1237
Pete Gillin581d6082018-10-22 15:55:04 +01001238 checkNullabilityWarningsTimestamp android.WritablePath
1239
Nan Zhang1598a9e2018-09-04 17:14:32 -07001240 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001241 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001242
1243 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001244
1245 jdiffDocZip android.WritablePath
1246 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001247}
1248
1249func DroidstubsFactory() android.Module {
1250 module := &Droidstubs{}
1251
1252 module.AddProperties(&module.properties,
1253 &module.Javadoc.properties)
1254
1255 InitDroiddocModule(module, android.HostAndDeviceSupported)
1256 return module
1257}
1258
1259func DroidstubsHostFactory() android.Module {
1260 module := &Droidstubs{}
1261
1262 module.AddProperties(&module.properties,
1263 &module.Javadoc.properties)
1264
1265 InitDroiddocModule(module, android.HostSupported)
1266 return module
1267}
1268
1269func (d *Droidstubs) ApiFilePath() android.Path {
1270 return d.apiFilePath
1271}
1272
1273func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1274 d.Javadoc.addDeps(ctx)
1275
1276 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1277 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1278 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1279 }
1280
1281 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1282 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1283 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1284 }
1285
1286 if String(d.properties.Previous_api) != "" {
1287 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1288 }
1289
1290 if len(d.properties.Merge_annotations_dirs) != 0 {
1291 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1292 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1293 }
1294 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001295
Pete Gillin77167902018-09-19 18:16:26 +01001296 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1297 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1298 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1299 }
1300 }
1301
Pete Gillinc382a562018-11-14 18:45:46 +00001302 if String(d.properties.Validate_nullability_from_list) != "" {
1303 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1304 }
Pete Gillin581d6082018-10-22 15:55:04 +01001305 if String(d.properties.Check_nullability_warnings) != "" {
1306 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1307 }
1308
Nan Zhang9c69a122018-08-22 10:22:08 -07001309 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1310 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1311 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1312 }
1313 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001314}
1315
1316func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1317 deps deps) (droiddocBuilderFlags, error) {
1318 var flags droiddocBuilderFlags
1319
1320 *implicits = append(*implicits, deps.bootClasspath...)
1321 *implicits = append(*implicits, deps.classpath...)
1322
1323 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1324 // since it doesn't support system modules yet.
1325 if len(deps.bootClasspath.Strings()) > 0 {
1326 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1327 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1328 }
1329 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1330
Sundong Ahn56dce442018-10-05 18:41:09 +09001331 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001332 return flags, nil
1333}
1334
1335func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1336 implicitOutputs *android.WritablePaths) string {
1337 var metalavaFlags string
1338 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1339 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1340 String(d.properties.Api_filename) != "" {
1341 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1342 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1343 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1344 d.apiFilePath = d.apiFile
1345 }
1346
1347 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1348 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1349 String(d.properties.Removed_api_filename) != "" {
1350 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1351 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1352 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1353 }
1354
1355 if String(d.properties.Private_api_filename) != "" {
1356 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1357 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1358 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1359 }
1360
1361 if String(d.properties.Dex_api_filename) != "" {
1362 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1363 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1364 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1365 }
1366
1367 if String(d.properties.Private_dex_api_filename) != "" {
1368 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1369 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1370 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1371 }
1372
1373 if String(d.properties.Removed_dex_api_filename) != "" {
1374 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1375 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1376 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1377 }
1378
1379 if String(d.properties.Exact_api_filename) != "" {
1380 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1381 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1382 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1383 }
1384
Nan Zhang9c69a122018-08-22 10:22:08 -07001385 if String(d.properties.Dex_mapping_filename) != "" {
1386 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1387 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1388 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1389 }
1390
Nan Zhang199645c2018-09-19 12:40:06 -07001391 if String(d.properties.Proguard_filename) != "" {
1392 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1393 metalavaFlags += " --proguard " + d.proguardFile.String()
1394 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1395 }
1396
Nan Zhang9c69a122018-08-22 10:22:08 -07001397 if Bool(d.properties.Write_sdk_values) {
1398 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1399 }
1400
Nan Zhang1598a9e2018-09-04 17:14:32 -07001401 if Bool(d.properties.Create_doc_stubs) {
1402 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1403 } else {
1404 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1405 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001406 return metalavaFlags
1407}
1408
1409func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001410 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1411 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001412 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001413 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001414 validatingNullability :=
1415 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1416 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001417 migratingNullability := String(d.properties.Previous_api) != ""
1418 if !(migratingNullability || validatingNullability) {
1419 ctx.PropertyErrorf("previous_api",
1420 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001421 }
Pete Gillina262c052018-09-14 14:25:48 +01001422 if migratingNullability {
1423 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1424 *implicits = append(*implicits, previousApi)
1425 flags += " --migrate-nullness " + previousApi.String()
1426 }
Pete Gillinc382a562018-11-14 18:45:46 +00001427 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1428 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1429 }
Pete Gillina262c052018-09-14 14:25:48 +01001430 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001431 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1432 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1433 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001434 }
Nan Zhanga40da042018-08-01 12:48:00 -07001435
1436 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1437 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1438
Nan Zhangf4936b02018-08-01 15:00:28 -07001439 flags += " --extract-annotations " + d.annotationsZip.String()
1440
Nan Zhang1598a9e2018-09-04 17:14:32 -07001441 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001442 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001443 "has to be non-empty if annotations was enabled!")
1444 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001445 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1446 if t, ok := m.(*ExportedDroiddocDir); ok {
1447 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001448 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001449 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001450 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001451 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1452 }
1453 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001454 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001455 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001456 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001457 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001458
Nan Zhangdee152b2018-12-26 16:06:37 -08001459 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001460}
1461
1462func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1463 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1464 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001465 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1466 if t, ok := m.(*ExportedDroiddocDir); ok {
1467 *implicits = append(*implicits, t.deps...)
1468 flags += " --merge-inclusion-annotations " + t.dir.String()
1469 } else {
1470 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1471 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1472 }
1473 })
Nan Zhanga40da042018-08-01 12:48:00 -07001474
1475 return flags
1476}
1477
Nan Zhang9c69a122018-08-22 10:22:08 -07001478func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1479 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1480 var flags string
1481 if Bool(d.properties.Api_levels_annotations_enabled) {
1482 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1483 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1484
1485 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1486 ctx.PropertyErrorf("api_levels_annotations_dirs",
1487 "has to be non-empty if api levels annotations was enabled!")
1488 }
1489
1490 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1491 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1492 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1493
1494 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1495 if t, ok := m.(*ExportedDroiddocDir); ok {
1496 var androidJars android.Paths
1497 for _, dep := range t.deps {
1498 if strings.HasSuffix(dep.String(), "android.jar") {
1499 androidJars = append(androidJars, dep)
1500 }
1501 }
1502 *implicits = append(*implicits, androidJars...)
Tor Norbyeebcdfed2019-01-24 11:05:46 -08001503 flags += " --android-jar-pattern " + t.dir.String() + "/%/public/android.jar "
Nan Zhang9c69a122018-08-22 10:22:08 -07001504 } else {
1505 ctx.PropertyErrorf("api_levels_annotations_dirs",
1506 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1507 }
1508 })
1509
1510 }
1511
1512 return flags
1513}
1514
Nan Zhang71bbe632018-09-17 14:32:21 -07001515func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1516 implicitOutputs *android.WritablePaths) string {
1517 var flags string
1518 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1519 if d.apiFile.String() == "" {
1520 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1521 }
1522
1523 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1524 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1525
1526 flags = " --api-xml " + d.apiXmlFile.String()
1527
1528 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1529 ctx.PropertyErrorf("check_api.last_released.api_file",
1530 "has to be non-empty if jdiff was enabled!")
1531 }
1532 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1533 "check_api.last_released.api_file")
1534 *implicits = append(*implicits, lastReleasedApi)
1535
1536 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1537 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1538
1539 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1540 d.lastReleasedApiXmlFile.String()
1541 }
1542
1543 return flags
1544}
1545
Nan Zhang1598a9e2018-09-04 17:14:32 -07001546func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1547 implicitOutputs android.WritablePaths, javaVersion,
1548 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001549
Nan Zhang86d2d552018-08-09 15:33:27 -07001550 ctx.Build(pctx, android.BuildParams{
1551 Rule: metalava,
1552 Description: "Metalava",
1553 Output: d.Javadoc.stubsSrcJar,
1554 Inputs: d.Javadoc.srcFiles,
1555 Implicits: implicits,
1556 ImplicitOutputs: implicitOutputs,
1557 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001558 "outDir": android.PathForModuleOut(ctx, "out").String(),
1559 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1560 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1561 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001562 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001563 "bootclasspathArgs": bootclasspathArgs,
1564 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001565 "sourcepathArgs": sourcepathArgs,
1566 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001567 },
1568 })
1569}
1570
Nan Zhang1598a9e2018-09-04 17:14:32 -07001571func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1572 apiFile, removedApiFile android.Path, implicits android.Paths,
Colin Cross39c16792019-01-24 16:32:44 -08001573 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, subdir, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001574 output android.WritablePath) {
1575 ctx.Build(pctx, android.BuildParams{
1576 Rule: metalavaApiCheck,
1577 Description: "Metalava Check API",
1578 Output: output,
1579 Inputs: d.Javadoc.srcFiles,
1580 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1581 implicits...),
1582 Args: map[string]string{
Colin Cross39c16792019-01-24 16:32:44 -08001583 "srcJarDir": android.PathForModuleOut(ctx, subdir, "srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001584 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1585 "javaVersion": javaVersion,
1586 "bootclasspathArgs": bootclasspathArgs,
1587 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001588 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001589 "opts": opts,
1590 "msg": msg,
1591 },
1592 })
1593}
1594
Nan Zhang71bbe632018-09-17 14:32:21 -07001595func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1596 implicitOutputs android.WritablePaths,
1597 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1598 ctx.Build(pctx, android.BuildParams{
1599 Rule: javadoc,
1600 Description: "Jdiff",
1601 Output: d.jdiffStubsSrcJar,
1602 Inputs: d.Javadoc.srcFiles,
1603 Implicits: implicits,
1604 ImplicitOutputs: implicitOutputs,
1605 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001606 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1607 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1608 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001609 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1610 "opts": opts,
1611 "bootclasspathArgs": bootclasspathArgs,
1612 "classpathArgs": classpathArgs,
1613 "sourcepathArgs": sourcepathArgs,
1614 "docZip": d.jdiffDocZip.String(),
1615 },
1616 })
1617}
1618
Nan Zhang1598a9e2018-09-04 17:14:32 -07001619func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001620 deps := d.Javadoc.collectDeps(ctx)
1621
1622 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001623
Nan Zhanga40da042018-08-01 12:48:00 -07001624 var implicits android.Paths
1625 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001626 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001627
1628 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001629 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001630 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1631 }
1632
1633 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001634 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001635 jdiffImplicits := implicits
1636
Nan Zhanga40da042018-08-01 12:48:00 -07001637 if err != nil {
1638 return
1639 }
1640
Nan Zhang1598a9e2018-09-04 17:14:32 -07001641 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001642 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1643 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001644 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001645 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001646 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1647
Nan Zhang1598a9e2018-09-04 17:14:32 -07001648 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1649 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1650 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1651 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1652 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001653 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001654 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1655 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001656 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001657 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001658
Nan Zhang1598a9e2018-09-04 17:14:32 -07001659 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1660 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001661 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1662 "check_api.current.api_file")
1663 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1664 "check_api.current_removed_api_file")
1665
Nan Zhang2760dfc2018-08-24 17:32:54 +00001666 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001667 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1668 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001669 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001670
Nan Zhang1598a9e2018-09-04 17:14:32 -07001671 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001672 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "current-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001673 fmt.Sprintf(`\n******************************\n`+
1674 `You have tried to change the API from what has been previously approved.\n\n`+
1675 `To make these errors go away, you have two choices:\n`+
1676 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1677 ` errors above.\n\n`+
1678 ` 2. You can update current.txt by executing the following command:\n`+
1679 ` make %s-update-current-api\n\n`+
1680 ` To submit the revised current.txt to the main Android repository,\n`+
1681 ` you will need approval.\n`+
1682 `******************************\n`, ctx.ModuleName()),
1683 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001684
1685 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001686 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1687 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001688 }
Nan Zhanga40da042018-08-01 12:48:00 -07001689
Nan Zhang1598a9e2018-09-04 17:14:32 -07001690 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1691 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001692 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1693 "check_api.last_released.api_file")
1694 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1695 "check_api.last_released.removed_api_file")
1696
Nan Zhang2760dfc2018-08-24 17:32:54 +00001697 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001698 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1699 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001700 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001701
Nan Zhang1598a9e2018-09-04 17:14:32 -07001702 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
Colin Cross39c16792019-01-24 16:32:44 -08001703 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, "last-apicheck",
Nan Zhang1598a9e2018-09-04 17:14:32 -07001704 `\n******************************\n`+
1705 `You have tried to change the API from what has been previously released in\n`+
1706 `an SDK. Please fix the errors listed above.\n`+
1707 `******************************\n`,
1708 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001709 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001710
Pete Gillin581d6082018-10-22 15:55:04 +01001711 if String(d.properties.Check_nullability_warnings) != "" {
1712 if d.nullabilityWarningsFile == nil {
1713 ctx.PropertyErrorf("check_nullability_warnings",
1714 "Cannot specify check_nullability_warnings unless validating nullability")
1715 }
1716 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1717 "check_nullability_warnings")
1718 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1719 msg := fmt.Sprintf(`\n******************************\n`+
1720 `The warnings encountered during nullability annotation validation did\n`+
1721 `not match the checked in file of expected warnings. The diffs are shown\n`+
1722 `above. You have two options:\n`+
1723 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1724 ` 2. Update the file of expected warnings by running:\n`+
1725 ` cp %s %s\n`+
1726 ` and submitting the updated file as part of your change.`,
1727 d.nullabilityWarningsFile, checkNullabilityWarnings)
1728 ctx.Build(pctx, android.BuildParams{
1729 Rule: nullabilityWarningsCheck,
1730 Description: "Nullability Warnings Check",
1731 Output: d.checkNullabilityWarningsTimestamp,
1732 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1733 Args: map[string]string{
1734 "expected": checkNullabilityWarnings.String(),
1735 "actual": d.nullabilityWarningsFile.String(),
1736 "msg": msg,
1737 },
1738 })
1739 }
1740
Nan Zhang71bbe632018-09-17 14:32:21 -07001741 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1742
Nan Zhang86b06202018-09-21 17:09:21 -07001743 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1744 // since there's cron job downstream that fetch this .zip file periodically.
1745 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001746 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1747 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1748
1749 var jdiffImplicitOutputs android.WritablePaths
1750 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1751
1752 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1753 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1754
1755 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1756 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1757 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1758 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1759 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1760 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1761
1762 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1763 flags.sourcepathArgs, opts)
1764 }
Nan Zhang581fd212018-01-10 16:06:12 -08001765}
Dan Willemsencc090972018-02-26 14:33:31 -08001766
Nan Zhanga40da042018-08-01 12:48:00 -07001767//
Nan Zhangf4936b02018-08-01 15:00:28 -07001768// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001769//
Dan Willemsencc090972018-02-26 14:33:31 -08001770var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001771var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001772var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001773var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001774
Nan Zhangf4936b02018-08-01 15:00:28 -07001775type ExportedDroiddocDirProperties struct {
1776 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001777 Path *string
1778}
1779
Nan Zhangf4936b02018-08-01 15:00:28 -07001780type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001781 android.ModuleBase
1782
Nan Zhangf4936b02018-08-01 15:00:28 -07001783 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001784
1785 deps android.Paths
1786 dir android.Path
1787}
1788
Nan Zhangf4936b02018-08-01 15:00:28 -07001789func ExportedDroiddocDirFactory() android.Module {
1790 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001791 module.AddProperties(&module.properties)
1792 android.InitAndroidModule(module)
1793 return module
1794}
1795
Nan Zhangf4936b02018-08-01 15:00:28 -07001796func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001797
Nan Zhangf4936b02018-08-01 15:00:28 -07001798func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001799 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1800 d.dir = path
1801 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1802}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001803
1804//
1805// Defaults
1806//
1807type DocDefaults struct {
1808 android.ModuleBase
1809 android.DefaultsModuleBase
1810}
1811
1812func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1813}
1814
1815func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1816}
1817
1818func DocDefaultsFactory() android.Module {
1819 module := &DocDefaults{}
1820
1821 module.AddProperties(
1822 &JavadocProperties{},
1823 &DroiddocProperties{},
1824 )
1825
1826 android.InitDefaultsModule(module)
1827
1828 return module
1829}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001830
1831func StubsDefaultsFactory() android.Module {
1832 module := &DocDefaults{}
1833
1834 module.AddProperties(
1835 &JavadocProperties{},
1836 &DroidstubsProperties{},
1837 )
1838
1839 android.InitDefaultsModule(module)
1840
1841 return module
1842}