blob: bd3b3abc7799fb2bf130a08f434daafe67589e85 [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 ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070075 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
76 `$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 ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070096 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
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:
Colin Cross83bb3162018-06-25 15:48:06 -0700632 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900633 linkType := javaSdk
634 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
635 linkType = javaSystem
636 } else if sdkVersion == "" {
637 linkType = javaPlatform
638 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900639 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700640 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800641 checkProducesJars(ctx, dep)
642 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800643 default:
644 ctx.ModuleErrorf("depends on non-java module %q", otherName)
645 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700646 case srcsLibTag:
647 switch dep := module.(type) {
648 case Dependency:
649 srcs := dep.(SrcDependency).CompiledSrcs()
650 whitelistPathPrefixes := make(map[string]bool)
651 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
652 for _, src := range srcs {
653 if _, ok := src.(android.WritablePath); ok { // generated sources
654 deps.srcs = append(deps.srcs, src)
655 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700656 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700657 if strings.HasPrefix(src.Rel(), k) {
658 deps.srcs = append(deps.srcs, src)
659 break
660 }
661 }
662 }
663 }
664 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
665 default:
666 ctx.ModuleErrorf("depends on non-java module %q", otherName)
667 }
Nan Zhang357466b2018-04-17 17:38:36 -0700668 case systemModulesTag:
669 if deps.systemModules != nil {
670 panic("Found two system module dependencies")
671 }
672 sm := module.(*SystemModules)
673 if sm.outputFile == nil {
674 panic("Missing directory for system module dependency")
675 }
676 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800677 }
678 })
679 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
680 // may contain filegroup or genrule.
681 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700682 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900683 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800684
685 // srcs may depend on some genrule output.
686 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800687 j.srcJars = append(j.srcJars, deps.srcJars...)
688
Nan Zhang581fd212018-01-10 16:06:12 -0800689 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800690 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800691
692 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800693 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800694
Nan Zhang9c69a122018-08-22 10:22:08 -0700695 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800696 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
697 }
698 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800699
Nan Zhang1598a9e2018-09-04 17:14:32 -0700700 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
701 argFilesMap := map[string]android.Path{}
702
703 for _, f := range j.argFiles {
704 if _, exists := argFilesMap[f.Rel()]; !exists {
705 argFilesMap[f.Rel()] = f
706 } else {
707 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
708 f, argFilesMap[f.Rel()], f.Rel())
709 }
710 }
711
712 var err error
713 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
714 if strings.HasPrefix(name, "location ") {
715 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
716 if f, ok := argFilesMap[label]; ok {
717 return f.String(), nil
718 } else {
719 return "", fmt.Errorf("unknown location label %q", label)
720 }
721 } else if name == "genDir" {
722 return android.PathForModuleGen(ctx).String(), nil
723 }
724 return "", fmt.Errorf("unknown variable '$(%s)'", name)
725 })
726
727 if err != nil {
728 ctx.PropertyErrorf("args", "%s", err.Error())
729 }
730
Nan Zhang581fd212018-01-10 16:06:12 -0800731 return deps
732}
733
734func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
735 j.addDeps(ctx)
736}
737
738func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
739 deps := j.collectDeps(ctx)
740
741 var implicits android.Paths
742 implicits = append(implicits, deps.bootClasspath...)
743 implicits = append(implicits, deps.classpath...)
744
Nan Zhang1598a9e2018-09-04 17:14:32 -0700745 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700746
Colin Cross83bb3162018-06-25 15:48:06 -0700747 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700748 if len(deps.bootClasspath) > 0 {
749 var systemModules classpath
750 if deps.systemModules != nil {
751 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800752 }
Colin Cross997262f2018-06-19 22:49:39 -0700753 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
754 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800755 }
756 if len(deps.classpath.Strings()) > 0 {
757 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
758 }
759
760 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700761 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800762
Nan Zhangaf322cc2018-06-19 15:15:38 -0700763 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800764
Nan Zhang1598a9e2018-09-04 17:14:32 -0700765 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
766
Nan Zhang581fd212018-01-10 16:06:12 -0800767 ctx.Build(pctx, android.BuildParams{
768 Rule: javadoc,
769 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800770 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800771 ImplicitOutput: j.docZip,
772 Inputs: j.srcFiles,
773 Implicits: implicits,
774 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700775 "outDir": android.PathForModuleOut(ctx, "out").String(),
776 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
777 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800778 "srcJars": strings.Join(j.srcJars.Strings(), " "),
779 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700780 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800781 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700782 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800783 "docZip": j.docZip.String(),
784 },
785 })
786}
787
Nan Zhanga40da042018-08-01 12:48:00 -0700788//
789// Droiddoc
790//
791type Droiddoc struct {
792 Javadoc
793
794 properties DroiddocProperties
795 apiFile android.WritablePath
796 dexApiFile android.WritablePath
797 privateApiFile android.WritablePath
798 privateDexApiFile android.WritablePath
799 removedApiFile android.WritablePath
800 removedDexApiFile android.WritablePath
801 exactApiFile android.WritablePath
802 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700803 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700804
805 checkCurrentApiTimestamp android.WritablePath
806 updateCurrentApiTimestamp android.WritablePath
807 checkLastReleasedApiTimestamp android.WritablePath
808
Nan Zhanga40da042018-08-01 12:48:00 -0700809 apiFilePath android.Path
810}
811
Nan Zhanga40da042018-08-01 12:48:00 -0700812func DroiddocFactory() android.Module {
813 module := &Droiddoc{}
814
815 module.AddProperties(&module.properties,
816 &module.Javadoc.properties)
817
818 InitDroiddocModule(module, android.HostAndDeviceSupported)
819 return module
820}
821
822func DroiddocHostFactory() android.Module {
823 module := &Droiddoc{}
824
825 module.AddProperties(&module.properties,
826 &module.Javadoc.properties)
827
828 InitDroiddocModule(module, android.HostSupported)
829 return module
830}
831
832func (d *Droiddoc) ApiFilePath() android.Path {
833 return d.apiFilePath
834}
835
Nan Zhang581fd212018-01-10 16:06:12 -0800836func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
837 d.Javadoc.addDeps(ctx)
838
Nan Zhang79614d12018-04-19 18:03:39 -0700839 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800840 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
841 }
842
Nan Zhang581fd212018-01-10 16:06:12 -0800843 // knowntags may contain filegroup or genrule.
844 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700845
Nan Zhange2ba5d42018-07-11 15:16:55 -0700846 if String(d.properties.Static_doc_index_redirect) != "" {
847 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
848 }
849
850 if String(d.properties.Static_doc_properties) != "" {
851 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
852 }
853
Nan Zhang1598a9e2018-09-04 17:14:32 -0700854 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700855 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
856 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
857 }
858
Nan Zhang1598a9e2018-09-04 17:14:32 -0700859 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700860 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
861 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
862 }
Nan Zhang581fd212018-01-10 16:06:12 -0800863}
864
Nan Zhang66dc2362018-08-14 20:41:04 -0700865func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
866 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700867 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800868
Nan Zhanga40da042018-08-01 12:48:00 -0700869 *implicits = append(*implicits, deps.bootClasspath...)
870 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800871
Nan Zhangc94f9d82018-06-26 10:02:26 -0700872 if len(deps.bootClasspath.Strings()) > 0 {
873 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700874 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700875 }
Nan Zhanga40da042018-08-01 12:48:00 -0700876 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700877 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700878 dokkaClasspath := classpath{}
879 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
880 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
881 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700882
Nan Zhang9c69a122018-08-22 10:22:08 -0700883 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
884 // based stubs generation.
885 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
886 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
887 // the correct package name base path.
888 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
889 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
890 } else {
891 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
892 }
Nan Zhang581fd212018-01-10 16:06:12 -0800893
Nan Zhanga40da042018-08-01 12:48:00 -0700894 return flags, nil
895}
Nan Zhang581fd212018-01-10 16:06:12 -0800896
Nan Zhanga40da042018-08-01 12:48:00 -0700897func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700898 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800899
Nan Zhanga40da042018-08-01 12:48:00 -0700900 *implicits = append(*implicits, jsilver)
901 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700902
Nan Zhang46130972018-06-04 11:28:01 -0700903 var date string
904 if runtime.GOOS == "darwin" {
905 date = `date -r`
906 } else {
907 date = `date -d`
908 }
909
Nan Zhang443fa522018-08-20 20:58:28 -0700910 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
911 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
912 // 1.9 language features.
913 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700914 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800915 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700916 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700917
Nan Zhanga40da042018-08-01 12:48:00 -0700918 if String(d.properties.Custom_template) == "" {
919 // TODO: This is almost always droiddoc-templates-sdk
920 ctx.PropertyErrorf("custom_template", "must specify a template")
921 }
922
923 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700924 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700925 *implicits = append(*implicits, t.deps...)
926 args = args + " -templatedir " + t.dir.String()
927 } else {
928 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
929 }
930 })
931
932 if len(d.properties.Html_dirs) > 0 {
933 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
934 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
935 args = args + " -htmldir " + htmlDir.String()
936 }
937
938 if len(d.properties.Html_dirs) > 1 {
939 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
940 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
941 args = args + " -htmldir2 " + htmlDir2.String()
942 }
943
944 if len(d.properties.Html_dirs) > 2 {
945 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
946 }
947
948 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
949 *implicits = append(*implicits, knownTags...)
950
951 for _, kt := range knownTags {
952 args = args + " -knowntags " + kt.String()
953 }
954
955 for _, hdf := range d.properties.Hdf {
956 args = args + " -hdf " + hdf
957 }
958
959 if String(d.properties.Proofread_file) != "" {
960 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
961 args = args + " -proofread " + proofreadFile.String()
962 }
963
964 if String(d.properties.Todo_file) != "" {
965 // tricky part:
966 // we should not compute full path for todo_file through PathForModuleOut().
967 // the non-standard doclet will get the full path relative to "-o".
968 args = args + " -todo " + String(d.properties.Todo_file)
969 }
970
971 if String(d.properties.Resourcesdir) != "" {
972 // TODO: should we add files under resourcesDir to the implicits? It seems that
973 // resourcesDir is one sub dir of htmlDir
974 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
975 args = args + " -resourcesdir " + resourcesDir.String()
976 }
977
978 if String(d.properties.Resourcesoutdir) != "" {
979 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
980 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
981 }
982 return args
983}
984
Nan Zhang1598a9e2018-09-04 17:14:32 -0700985func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
986 implicitOutputs *android.WritablePaths) string {
987 var doclavaFlags string
988 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
989 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
990 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700991 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
992 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700993 *implicitOutputs = append(*implicitOutputs, d.apiFile)
994 d.apiFilePath = d.apiFile
995 }
996
Nan Zhang1598a9e2018-09-04 17:14:32 -0700997 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
998 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
999 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001000 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1001 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001002 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1003 }
1004
1005 if String(d.properties.Private_api_filename) != "" {
1006 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1007 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001008 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1009 }
1010
1011 if String(d.properties.Dex_api_filename) != "" {
1012 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1013 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1014 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1015 }
1016
1017 if String(d.properties.Private_dex_api_filename) != "" {
1018 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1019 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001020 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1021 }
1022
1023 if String(d.properties.Removed_dex_api_filename) != "" {
1024 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1025 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001026 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1027 }
1028
1029 if String(d.properties.Exact_api_filename) != "" {
1030 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1031 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001032 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1033 }
1034
1035 if String(d.properties.Dex_mapping_filename) != "" {
1036 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1037 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001038 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1039 }
1040
Nan Zhang66dc2362018-08-14 20:41:04 -07001041 if String(d.properties.Proguard_filename) != "" {
1042 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1043 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001044 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1045 }
1046
Nan Zhanga40da042018-08-01 12:48:00 -07001047 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001048 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001049 }
1050
1051 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001052 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001053 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001054
1055 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001056}
1057
1058func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1059 var cmds string
1060 if String(d.properties.Static_doc_index_redirect) != "" {
1061 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1062 "static_doc_index_redirect")
1063 *implicits = append(*implicits, static_doc_index_redirect)
1064 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001065 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001066 }
1067
1068 if String(d.properties.Static_doc_properties) != "" {
1069 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1070 "static_doc_properties")
1071 *implicits = append(*implicits, static_doc_properties)
1072 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001073 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001074 }
1075 return cmds
1076}
1077
Nan Zhang1598a9e2018-09-04 17:14:32 -07001078func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1079 implicitOutputs android.WritablePaths,
1080 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1081 ctx.Build(pctx, android.BuildParams{
1082 Rule: javadoc,
1083 Description: "Doclava",
1084 Output: d.Javadoc.stubsSrcJar,
1085 Inputs: d.Javadoc.srcFiles,
1086 Implicits: implicits,
1087 ImplicitOutputs: implicitOutputs,
1088 Args: map[string]string{
1089 "outDir": android.PathForModuleOut(ctx, "out").String(),
1090 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1091 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1092 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1093 "opts": opts,
1094 "bootclasspathArgs": bootclasspathArgs,
1095 "classpathArgs": classpathArgs,
1096 "sourcepathArgs": sourcepathArgs,
1097 "docZip": d.Javadoc.docZip.String(),
1098 "postDoclavaCmds": postDoclavaCmds,
1099 },
1100 })
1101}
1102
1103func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1104 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1105 ctx.Build(pctx, android.BuildParams{
1106 Rule: apiCheck,
1107 Description: "Doclava Check API",
1108 Output: output,
1109 Inputs: nil,
1110 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1111 checkApiClasspath...),
1112 Args: map[string]string{
1113 "msg": msg,
1114 "classpath": checkApiClasspath.FormJavaClassPath(""),
1115 "opts": opts,
1116 "apiFile": apiFile.String(),
1117 "apiFileToCheck": d.apiFile.String(),
1118 "removedApiFile": removedApiFile.String(),
1119 "removedApiFileToCheck": d.removedApiFile.String(),
1120 },
1121 })
1122}
1123
1124func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1125 classpathArgs, opts string) {
1126 ctx.Build(pctx, android.BuildParams{
1127 Rule: dokka,
1128 Description: "Dokka",
1129 Output: d.Javadoc.stubsSrcJar,
1130 Inputs: d.Javadoc.srcFiles,
1131 Implicits: implicits,
1132 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001133 "outDir": android.PathForModuleOut(ctx, "dokka-out").String(),
1134 "srcJarDir": android.PathForModuleOut(ctx, "dokka-srcjars").String(),
1135 "stubsDir": android.PathForModuleOut(ctx, "dokka-stubsDir").String(),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001136 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1137 "classpathArgs": classpathArgs,
1138 "opts": opts,
1139 "docZip": d.Javadoc.docZip.String(),
1140 },
1141 })
1142}
1143
1144func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1145 deps := d.Javadoc.collectDeps(ctx)
1146
1147 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1148 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1149 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1150 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1151
1152 var implicits android.Paths
1153 implicits = append(implicits, d.Javadoc.srcJars...)
1154 implicits = append(implicits, d.Javadoc.argFiles...)
1155
1156 var implicitOutputs android.WritablePaths
1157 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1158 for _, o := range d.Javadoc.properties.Out {
1159 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1160 }
1161
1162 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1163 if err != nil {
1164 return
1165 }
1166
1167 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1168 if Bool(d.properties.Dokka_enabled) {
1169 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1170 } else {
1171 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1172 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1173 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1174 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1175 flags.postDoclavaCmds)
1176 }
1177
1178 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1179 !ctx.Config().IsPdkBuild() {
1180 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1181 "check_api.current.api_file")
1182 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1183 "check_api.current_removed_api_file")
1184
1185 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1186 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1187 fmt.Sprintf(`\n******************************\n`+
1188 `You have tried to change the API from what has been previously approved.\n\n`+
1189 `To make these errors go away, you have two choices:\n`+
1190 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1191 ` errors above.\n\n`+
1192 ` 2. You can update current.txt by executing the following command:\n`+
1193 ` make %s-update-current-api\n\n`+
1194 ` To submit the revised current.txt to the main Android repository,\n`+
1195 ` you will need approval.\n`+
1196 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1197 d.checkCurrentApiTimestamp)
1198
1199 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1200 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1201 d.updateCurrentApiTimestamp)
1202 }
1203
1204 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1205 !ctx.Config().IsPdkBuild() {
1206 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1207 "check_api.last_released.api_file")
1208 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1209 "check_api.last_released.removed_api_file")
1210
1211 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1212 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1213 `\n******************************\n`+
1214 `You have tried to change the API from what has been previously released in\n`+
1215 `an SDK. Please fix the errors listed above.\n`+
1216 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1217 d.checkLastReleasedApiTimestamp)
1218 }
1219}
1220
1221//
1222// Droidstubs
1223//
1224type Droidstubs struct {
1225 Javadoc
1226
Pete Gillin581d6082018-10-22 15:55:04 +01001227 properties DroidstubsProperties
1228 apiFile android.WritablePath
1229 apiXmlFile android.WritablePath
1230 lastReleasedApiXmlFile android.WritablePath
1231 dexApiFile android.WritablePath
1232 privateApiFile android.WritablePath
1233 privateDexApiFile android.WritablePath
1234 removedApiFile android.WritablePath
1235 removedDexApiFile android.WritablePath
1236 apiMappingFile android.WritablePath
1237 exactApiFile android.WritablePath
1238 proguardFile android.WritablePath
1239 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001240
1241 checkCurrentApiTimestamp android.WritablePath
1242 updateCurrentApiTimestamp android.WritablePath
1243 checkLastReleasedApiTimestamp android.WritablePath
1244
Pete Gillin581d6082018-10-22 15:55:04 +01001245 checkNullabilityWarningsTimestamp android.WritablePath
1246
Nan Zhang1598a9e2018-09-04 17:14:32 -07001247 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001248 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001249
1250 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001251
1252 jdiffDocZip android.WritablePath
1253 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001254}
1255
1256func DroidstubsFactory() android.Module {
1257 module := &Droidstubs{}
1258
1259 module.AddProperties(&module.properties,
1260 &module.Javadoc.properties)
1261
1262 InitDroiddocModule(module, android.HostAndDeviceSupported)
1263 return module
1264}
1265
1266func DroidstubsHostFactory() android.Module {
1267 module := &Droidstubs{}
1268
1269 module.AddProperties(&module.properties,
1270 &module.Javadoc.properties)
1271
1272 InitDroiddocModule(module, android.HostSupported)
1273 return module
1274}
1275
1276func (d *Droidstubs) ApiFilePath() android.Path {
1277 return d.apiFilePath
1278}
1279
1280func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1281 d.Javadoc.addDeps(ctx)
1282
1283 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1284 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1285 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1286 }
1287
1288 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1289 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1290 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1291 }
1292
1293 if String(d.properties.Previous_api) != "" {
1294 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1295 }
1296
1297 if len(d.properties.Merge_annotations_dirs) != 0 {
1298 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1299 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1300 }
1301 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001302
Pete Gillin77167902018-09-19 18:16:26 +01001303 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1304 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1305 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1306 }
1307 }
1308
Pete Gillinc382a562018-11-14 18:45:46 +00001309 if String(d.properties.Validate_nullability_from_list) != "" {
1310 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1311 }
Pete Gillin581d6082018-10-22 15:55:04 +01001312 if String(d.properties.Check_nullability_warnings) != "" {
1313 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1314 }
1315
Nan Zhang9c69a122018-08-22 10:22:08 -07001316 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1317 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1318 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1319 }
1320 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001321}
1322
1323func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1324 deps deps) (droiddocBuilderFlags, error) {
1325 var flags droiddocBuilderFlags
1326
1327 *implicits = append(*implicits, deps.bootClasspath...)
1328 *implicits = append(*implicits, deps.classpath...)
1329
1330 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1331 // since it doesn't support system modules yet.
1332 if len(deps.bootClasspath.Strings()) > 0 {
1333 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1334 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1335 }
1336 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1337
Sundong Ahn56dce442018-10-05 18:41:09 +09001338 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001339 return flags, nil
1340}
1341
1342func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1343 implicitOutputs *android.WritablePaths) string {
1344 var metalavaFlags string
1345 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1346 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1347 String(d.properties.Api_filename) != "" {
1348 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1349 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1350 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1351 d.apiFilePath = d.apiFile
1352 }
1353
1354 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1355 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1356 String(d.properties.Removed_api_filename) != "" {
1357 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1358 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1359 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1360 }
1361
1362 if String(d.properties.Private_api_filename) != "" {
1363 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1364 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1365 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1366 }
1367
1368 if String(d.properties.Dex_api_filename) != "" {
1369 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1370 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1371 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1372 }
1373
1374 if String(d.properties.Private_dex_api_filename) != "" {
1375 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1376 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1377 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1378 }
1379
1380 if String(d.properties.Removed_dex_api_filename) != "" {
1381 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1382 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1383 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1384 }
1385
1386 if String(d.properties.Exact_api_filename) != "" {
1387 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1388 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1389 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1390 }
1391
Nan Zhang9c69a122018-08-22 10:22:08 -07001392 if String(d.properties.Dex_mapping_filename) != "" {
1393 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1394 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1395 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1396 }
1397
Nan Zhang199645c2018-09-19 12:40:06 -07001398 if String(d.properties.Proguard_filename) != "" {
1399 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1400 metalavaFlags += " --proguard " + d.proguardFile.String()
1401 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1402 }
1403
Nan Zhang9c69a122018-08-22 10:22:08 -07001404 if Bool(d.properties.Write_sdk_values) {
1405 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1406 }
1407
Nan Zhang1598a9e2018-09-04 17:14:32 -07001408 if Bool(d.properties.Create_doc_stubs) {
1409 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1410 } else {
1411 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1412 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001413 return metalavaFlags
1414}
1415
1416func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
Nan Zhangdee152b2018-12-26 16:06:37 -08001417 implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) {
1418 var flags, mergeAnnoDirFlags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001419 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001420 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001421 validatingNullability :=
1422 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1423 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001424 migratingNullability := String(d.properties.Previous_api) != ""
1425 if !(migratingNullability || validatingNullability) {
1426 ctx.PropertyErrorf("previous_api",
1427 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001428 }
Pete Gillina262c052018-09-14 14:25:48 +01001429 if migratingNullability {
1430 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1431 *implicits = append(*implicits, previousApi)
1432 flags += " --migrate-nullness " + previousApi.String()
1433 }
Pete Gillinc382a562018-11-14 18:45:46 +00001434 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1435 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1436 }
Pete Gillina262c052018-09-14 14:25:48 +01001437 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001438 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1439 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1440 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001441 }
Nan Zhanga40da042018-08-01 12:48:00 -07001442
1443 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1444 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1445
Nan Zhangf4936b02018-08-01 15:00:28 -07001446 flags += " --extract-annotations " + d.annotationsZip.String()
1447
Nan Zhang1598a9e2018-09-04 17:14:32 -07001448 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001449 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001450 "has to be non-empty if annotations was enabled!")
1451 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001452 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1453 if t, ok := m.(*ExportedDroiddocDir); ok {
1454 *implicits = append(*implicits, t.deps...)
Nan Zhangdee152b2018-12-26 16:06:37 -08001455 mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001456 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001457 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001458 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1459 }
1460 })
Nan Zhangdee152b2018-12-26 16:06:37 -08001461 flags += mergeAnnoDirFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001462 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001463 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001464 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001465
Nan Zhangdee152b2018-12-26 16:06:37 -08001466 return flags, mergeAnnoDirFlags
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001467}
1468
1469func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1470 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1471 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001472 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1473 if t, ok := m.(*ExportedDroiddocDir); ok {
1474 *implicits = append(*implicits, t.deps...)
1475 flags += " --merge-inclusion-annotations " + t.dir.String()
1476 } else {
1477 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1478 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1479 }
1480 })
Nan Zhanga40da042018-08-01 12:48:00 -07001481
1482 return flags
1483}
1484
Nan Zhang9c69a122018-08-22 10:22:08 -07001485func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1486 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1487 var flags string
1488 if Bool(d.properties.Api_levels_annotations_enabled) {
1489 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1490 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1491
1492 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1493 ctx.PropertyErrorf("api_levels_annotations_dirs",
1494 "has to be non-empty if api levels annotations was enabled!")
1495 }
1496
1497 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1498 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1499 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1500
1501 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1502 if t, ok := m.(*ExportedDroiddocDir); ok {
1503 var androidJars android.Paths
1504 for _, dep := range t.deps {
1505 if strings.HasSuffix(dep.String(), "android.jar") {
1506 androidJars = append(androidJars, dep)
1507 }
1508 }
1509 *implicits = append(*implicits, androidJars...)
1510 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1511 } else {
1512 ctx.PropertyErrorf("api_levels_annotations_dirs",
1513 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1514 }
1515 })
1516
1517 }
1518
1519 return flags
1520}
1521
Nan Zhang71bbe632018-09-17 14:32:21 -07001522func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1523 implicitOutputs *android.WritablePaths) string {
1524 var flags string
1525 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1526 if d.apiFile.String() == "" {
1527 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1528 }
1529
1530 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1531 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1532
1533 flags = " --api-xml " + d.apiXmlFile.String()
1534
1535 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1536 ctx.PropertyErrorf("check_api.last_released.api_file",
1537 "has to be non-empty if jdiff was enabled!")
1538 }
1539 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1540 "check_api.last_released.api_file")
1541 *implicits = append(*implicits, lastReleasedApi)
1542
1543 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1544 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1545
1546 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1547 d.lastReleasedApiXmlFile.String()
1548 }
1549
1550 return flags
1551}
1552
Nan Zhang1598a9e2018-09-04 17:14:32 -07001553func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1554 implicitOutputs android.WritablePaths, javaVersion,
1555 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001556
Nan Zhang86d2d552018-08-09 15:33:27 -07001557 ctx.Build(pctx, android.BuildParams{
1558 Rule: metalava,
1559 Description: "Metalava",
1560 Output: d.Javadoc.stubsSrcJar,
1561 Inputs: d.Javadoc.srcFiles,
1562 Implicits: implicits,
1563 ImplicitOutputs: implicitOutputs,
1564 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001565 "outDir": android.PathForModuleOut(ctx, "out").String(),
1566 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1567 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1568 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001569 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001570 "bootclasspathArgs": bootclasspathArgs,
1571 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001572 "sourcepathArgs": sourcepathArgs,
1573 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001574 },
1575 })
1576}
1577
Nan Zhang1598a9e2018-09-04 17:14:32 -07001578func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1579 apiFile, removedApiFile android.Path, implicits android.Paths,
1580 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001581 output android.WritablePath) {
1582 ctx.Build(pctx, android.BuildParams{
1583 Rule: metalavaApiCheck,
1584 Description: "Metalava Check API",
1585 Output: output,
1586 Inputs: d.Javadoc.srcFiles,
1587 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1588 implicits...),
1589 Args: map[string]string{
Nan Zhang3ffc3522018-11-29 10:42:47 -08001590 "srcJarDir": android.PathForModuleOut(ctx, "apicheck-srcjars").String(),
Nan Zhang2760dfc2018-08-24 17:32:54 +00001591 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1592 "javaVersion": javaVersion,
1593 "bootclasspathArgs": bootclasspathArgs,
1594 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001595 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001596 "opts": opts,
1597 "msg": msg,
1598 },
1599 })
1600}
1601
Nan Zhang71bbe632018-09-17 14:32:21 -07001602func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1603 implicitOutputs android.WritablePaths,
1604 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1605 ctx.Build(pctx, android.BuildParams{
1606 Rule: javadoc,
1607 Description: "Jdiff",
1608 Output: d.jdiffStubsSrcJar,
1609 Inputs: d.Javadoc.srcFiles,
1610 Implicits: implicits,
1611 ImplicitOutputs: implicitOutputs,
1612 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001613 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1614 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1615 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001616 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1617 "opts": opts,
1618 "bootclasspathArgs": bootclasspathArgs,
1619 "classpathArgs": classpathArgs,
1620 "sourcepathArgs": sourcepathArgs,
1621 "docZip": d.jdiffDocZip.String(),
1622 },
1623 })
1624}
1625
Nan Zhang1598a9e2018-09-04 17:14:32 -07001626func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001627 deps := d.Javadoc.collectDeps(ctx)
1628
1629 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001630
Nan Zhanga40da042018-08-01 12:48:00 -07001631 var implicits android.Paths
1632 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001633 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001634
1635 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001636 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001637 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1638 }
1639
1640 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001641 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001642 jdiffImplicits := implicits
1643
Nan Zhanga40da042018-08-01 12:48:00 -07001644 if err != nil {
1645 return
1646 }
1647
Nan Zhang1598a9e2018-09-04 17:14:32 -07001648 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
Nan Zhangdee152b2018-12-26 16:06:37 -08001649 flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags =
1650 d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001651 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001652 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001653 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1654
Nan Zhang1598a9e2018-09-04 17:14:32 -07001655 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1656 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1657 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1658 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1659 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001660 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001661 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1662 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001663 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001664 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001665
Nan Zhang1598a9e2018-09-04 17:14:32 -07001666 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1667 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001668 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1669 "check_api.current.api_file")
1670 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1671 "check_api.current_removed_api_file")
1672
Nan Zhang2760dfc2018-08-24 17:32:54 +00001673 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001674 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1675 " --check-compatibility:removed:current " + removedApiFile.String() +
Nan Zhangdee152b2018-12-26 16:06:37 -08001676 flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001677
Nan Zhang1598a9e2018-09-04 17:14:32 -07001678 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1679 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1680 fmt.Sprintf(`\n******************************\n`+
1681 `You have tried to change the API from what has been previously approved.\n\n`+
1682 `To make these errors go away, you have two choices:\n`+
1683 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1684 ` errors above.\n\n`+
1685 ` 2. You can update current.txt by executing the following command:\n`+
1686 ` make %s-update-current-api\n\n`+
1687 ` To submit the revised current.txt to the main Android repository,\n`+
1688 ` you will need approval.\n`+
1689 `******************************\n`, ctx.ModuleName()),
1690 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001691
1692 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001693 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1694 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001695 }
Nan Zhanga40da042018-08-01 12:48:00 -07001696
Nan Zhang1598a9e2018-09-04 17:14:32 -07001697 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1698 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001699 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1700 "check_api.last_released.api_file")
1701 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1702 "check_api.last_released.removed_api_file")
1703
Nan Zhang2760dfc2018-08-24 17:32:54 +00001704 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001705 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1706 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
Nan Zhangdee152b2018-12-26 16:06:37 -08001707 removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001708
Nan Zhang1598a9e2018-09-04 17:14:32 -07001709 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1710 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1711 `\n******************************\n`+
1712 `You have tried to change the API from what has been previously released in\n`+
1713 `an SDK. Please fix the errors listed above.\n`+
1714 `******************************\n`,
1715 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001716 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001717
Pete Gillin581d6082018-10-22 15:55:04 +01001718 if String(d.properties.Check_nullability_warnings) != "" {
1719 if d.nullabilityWarningsFile == nil {
1720 ctx.PropertyErrorf("check_nullability_warnings",
1721 "Cannot specify check_nullability_warnings unless validating nullability")
1722 }
1723 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1724 "check_nullability_warnings")
1725 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1726 msg := fmt.Sprintf(`\n******************************\n`+
1727 `The warnings encountered during nullability annotation validation did\n`+
1728 `not match the checked in file of expected warnings. The diffs are shown\n`+
1729 `above. You have two options:\n`+
1730 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1731 ` 2. Update the file of expected warnings by running:\n`+
1732 ` cp %s %s\n`+
1733 ` and submitting the updated file as part of your change.`,
1734 d.nullabilityWarningsFile, checkNullabilityWarnings)
1735 ctx.Build(pctx, android.BuildParams{
1736 Rule: nullabilityWarningsCheck,
1737 Description: "Nullability Warnings Check",
1738 Output: d.checkNullabilityWarningsTimestamp,
1739 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1740 Args: map[string]string{
1741 "expected": checkNullabilityWarnings.String(),
1742 "actual": d.nullabilityWarningsFile.String(),
1743 "msg": msg,
1744 },
1745 })
1746 }
1747
Nan Zhang71bbe632018-09-17 14:32:21 -07001748 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1749
Nan Zhang86b06202018-09-21 17:09:21 -07001750 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1751 // since there's cron job downstream that fetch this .zip file periodically.
1752 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001753 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1754 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1755
1756 var jdiffImplicitOutputs android.WritablePaths
1757 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1758
1759 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1760 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1761
1762 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1763 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1764 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1765 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1766 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1767 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1768
1769 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1770 flags.sourcepathArgs, opts)
1771 }
Nan Zhang581fd212018-01-10 16:06:12 -08001772}
Dan Willemsencc090972018-02-26 14:33:31 -08001773
Nan Zhanga40da042018-08-01 12:48:00 -07001774//
Nan Zhangf4936b02018-08-01 15:00:28 -07001775// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001776//
Dan Willemsencc090972018-02-26 14:33:31 -08001777var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001778var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001779var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001780var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001781
Nan Zhangf4936b02018-08-01 15:00:28 -07001782type ExportedDroiddocDirProperties struct {
1783 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001784 Path *string
1785}
1786
Nan Zhangf4936b02018-08-01 15:00:28 -07001787type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001788 android.ModuleBase
1789
Nan Zhangf4936b02018-08-01 15:00:28 -07001790 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001791
1792 deps android.Paths
1793 dir android.Path
1794}
1795
Nan Zhangf4936b02018-08-01 15:00:28 -07001796func ExportedDroiddocDirFactory() android.Module {
1797 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001798 module.AddProperties(&module.properties)
1799 android.InitAndroidModule(module)
1800 return module
1801}
1802
Nan Zhangf4936b02018-08-01 15:00:28 -07001803func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001804
Nan Zhangf4936b02018-08-01 15:00:28 -07001805func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001806 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1807 d.dir = path
1808 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1809}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001810
1811//
1812// Defaults
1813//
1814type DocDefaults struct {
1815 android.ModuleBase
1816 android.DefaultsModuleBase
1817}
1818
1819func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1820}
1821
1822func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1823}
1824
1825func DocDefaultsFactory() android.Module {
1826 module := &DocDefaults{}
1827
1828 module.AddProperties(
1829 &JavadocProperties{},
1830 &DroiddocProperties{},
1831 )
1832
1833 android.InitDefaultsModule(module)
1834
1835 return module
1836}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001837
1838func StubsDefaultsFactory() android.Module {
1839 module := &DocDefaults{}
1840
1841 module.AddProperties(
1842 &JavadocProperties{},
1843 &DroidstubsProperties{},
1844 )
1845
1846 android.InitDefaultsModule(module)
1847
1848 return module
1849}