blob: 0c4877a822165074f1ccf1dca26167558e94b1ec [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
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100403 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700404 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700405
Nan Zhang71bbe632018-09-17 14:32:21 -0700406 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700407}
408
409func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
410 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
411 android.InitDefaultableModule(module)
412}
413
Nan Zhang1598a9e2018-09-04 17:14:32 -0700414func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
415 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
416 return true
417 } else if String(apiToCheck.Api_file) != "" {
418 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
419 } else if String(apiToCheck.Removed_api_file) != "" {
420 panic("for " + apiVersionTag + " api_file has to be non-empty!")
421 }
422
423 return false
424}
425
426type ApiFilePath interface {
427 ApiFilePath() android.Path
428}
429
430func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
431 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
432 ctx.Build(pctx, android.BuildParams{
433 Rule: updateApi,
434 Description: "Update API",
435 Output: output,
436 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
437 destApiFile, destRemovedApiFile),
438 Args: map[string]string{
439 "destApiFile": destApiFile.String(),
440 "srcApiFile": srcApiFile.String(),
441 "destRemovedApiFile": destRemovedApiFile.String(),
442 "srcRemovedApiFile": srcRemovedApiFile.String(),
443 },
444 })
445}
446
Nan Zhanga40da042018-08-01 12:48:00 -0700447//
448// Javadoc
449//
Nan Zhang581fd212018-01-10 16:06:12 -0800450type Javadoc struct {
451 android.ModuleBase
452 android.DefaultableModuleBase
453
454 properties JavadocProperties
455
456 srcJars android.Paths
457 srcFiles android.Paths
458 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700459 argFiles android.Paths
460
461 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800462
Nan Zhangccff0f72018-03-08 17:26:16 -0800463 docZip android.WritablePath
464 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800465}
466
Nan Zhangb2b33de2018-02-23 11:18:47 -0800467func (j *Javadoc) Srcs() android.Paths {
468 return android.Paths{j.stubsSrcJar}
469}
470
Nan Zhang581fd212018-01-10 16:06:12 -0800471func JavadocFactory() android.Module {
472 module := &Javadoc{}
473
474 module.AddProperties(&module.properties)
475
476 InitDroiddocModule(module, android.HostAndDeviceSupported)
477 return module
478}
479
480func JavadocHostFactory() android.Module {
481 module := &Javadoc{}
482
483 module.AddProperties(&module.properties)
484
485 InitDroiddocModule(module, android.HostSupported)
486 return module
487}
488
Nan Zhanga40da042018-08-01 12:48:00 -0700489var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800490
Colin Cross83bb3162018-06-25 15:48:06 -0700491func (j *Javadoc) sdkVersion() string {
492 return String(j.properties.Sdk_version)
493}
494
495func (j *Javadoc) minSdkVersion() string {
496 return j.sdkVersion()
497}
498
Dan Willemsen419290a2018-10-31 15:28:47 -0700499func (j *Javadoc) targetSdkVersion() string {
500 return j.sdkVersion()
501}
502
Nan Zhang581fd212018-01-10 16:06:12 -0800503func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
504 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700505 if !Bool(j.properties.No_standard_libs) {
506 sdkDep := decodeSdkDep(ctx, sdkContext(j))
507 if sdkDep.useDefaultLibs {
508 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
509 if ctx.Config().TargetOpenJDK9() {
510 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
511 }
512 if !Bool(j.properties.No_framework_libs) {
513 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
514 }
515 } else if sdkDep.useModule {
516 if ctx.Config().TargetOpenJDK9() {
517 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
518 }
519 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700520 }
Nan Zhang581fd212018-01-10 16:06:12 -0800521 }
522 }
523
Colin Cross42d48b72018-08-29 14:10:52 -0700524 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700525 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700526 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700527 }
Nan Zhang581fd212018-01-10 16:06:12 -0800528
529 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
530
531 // exclude_srcs may contain filegroup or genrule.
532 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700533
534 // arg_files may contains filegroup or genrule.
535 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800536}
537
Nan Zhangb2b33de2018-02-23 11:18:47 -0800538func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
539 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
540 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900541 // convert foo.bar.baz to foo/bar/baz
542 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
543 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800544 if _, found := whitelistPathPrefixes[prefix]; !found {
545 whitelistPathPrefixes[prefix] = true
546 }
547 }
548 }
549}
550
Nan Zhanga40da042018-08-01 12:48:00 -0700551func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
552 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900553
554 // aidl flags.
555 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
556 if len(aidlFlags) > 0 {
557 // optimization.
558 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
559 flags.aidlFlags = "$aidlFlags"
560 }
561
562 return flags
563}
564
565func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
566 aidlIncludeDirs android.Paths) []string {
567
568 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
569 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
570
571 var flags []string
572 if aidlPreprocess.Valid() {
573 flags = append(flags, "-p"+aidlPreprocess.String())
574 } else {
575 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
576 }
577
578 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
579 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
580 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
581 flags = append(flags, "-I"+src.String())
582 }
583
584 return flags
585}
586
587func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700588 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900589
590 outSrcFiles := make(android.Paths, 0, len(srcFiles))
591
592 for _, srcFile := range srcFiles {
593 switch srcFile.Ext() {
594 case ".aidl":
595 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
596 outSrcFiles = append(outSrcFiles, javaFile)
597 default:
598 outSrcFiles = append(outSrcFiles, srcFile)
599 }
600 }
601
602 return outSrcFiles
603}
604
Nan Zhang581fd212018-01-10 16:06:12 -0800605func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
606 var deps deps
607
Colin Cross83bb3162018-06-25 15:48:06 -0700608 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800609 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700610 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800611 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700612 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800613 }
614
615 ctx.VisitDirectDeps(func(module android.Module) {
616 otherName := ctx.OtherModuleName(module)
617 tag := ctx.OtherModuleDependencyTag(module)
618
Colin Cross2d24c1b2018-05-23 10:59:18 -0700619 switch tag {
620 case bootClasspathTag:
621 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800622 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700623 } else {
624 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
625 }
626 case libTag:
627 switch dep := module.(type) {
628 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800629 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700630 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700631 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900632 linkType := javaSdk
633 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
634 linkType = javaSystem
635 } else if sdkVersion == "" {
636 linkType = javaPlatform
637 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900638 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700639 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800640 checkProducesJars(ctx, dep)
641 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800642 default:
643 ctx.ModuleErrorf("depends on non-java module %q", otherName)
644 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700645 case srcsLibTag:
646 switch dep := module.(type) {
647 case Dependency:
648 srcs := dep.(SrcDependency).CompiledSrcs()
649 whitelistPathPrefixes := make(map[string]bool)
650 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
651 for _, src := range srcs {
652 if _, ok := src.(android.WritablePath); ok { // generated sources
653 deps.srcs = append(deps.srcs, src)
654 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700655 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700656 if strings.HasPrefix(src.Rel(), k) {
657 deps.srcs = append(deps.srcs, src)
658 break
659 }
660 }
661 }
662 }
663 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
664 default:
665 ctx.ModuleErrorf("depends on non-java module %q", otherName)
666 }
Nan Zhang357466b2018-04-17 17:38:36 -0700667 case systemModulesTag:
668 if deps.systemModules != nil {
669 panic("Found two system module dependencies")
670 }
671 sm := module.(*SystemModules)
672 if sm.outputFile == nil {
673 panic("Missing directory for system module dependency")
674 }
675 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800676 }
677 })
678 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
679 // may contain filegroup or genrule.
680 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700681 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900682 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800683
684 // srcs may depend on some genrule output.
685 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800686 j.srcJars = append(j.srcJars, deps.srcJars...)
687
Nan Zhang581fd212018-01-10 16:06:12 -0800688 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800689 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800690
691 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800692 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800693
Nan Zhang9c69a122018-08-22 10:22:08 -0700694 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800695 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
696 }
697 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800698
Nan Zhang1598a9e2018-09-04 17:14:32 -0700699 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
700 argFilesMap := map[string]android.Path{}
701
702 for _, f := range j.argFiles {
703 if _, exists := argFilesMap[f.Rel()]; !exists {
704 argFilesMap[f.Rel()] = f
705 } else {
706 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
707 f, argFilesMap[f.Rel()], f.Rel())
708 }
709 }
710
711 var err error
712 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
713 if strings.HasPrefix(name, "location ") {
714 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
715 if f, ok := argFilesMap[label]; ok {
716 return f.String(), nil
717 } else {
718 return "", fmt.Errorf("unknown location label %q", label)
719 }
720 } else if name == "genDir" {
721 return android.PathForModuleGen(ctx).String(), nil
722 }
723 return "", fmt.Errorf("unknown variable '$(%s)'", name)
724 })
725
726 if err != nil {
727 ctx.PropertyErrorf("args", "%s", err.Error())
728 }
729
Nan Zhang581fd212018-01-10 16:06:12 -0800730 return deps
731}
732
733func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
734 j.addDeps(ctx)
735}
736
737func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
738 deps := j.collectDeps(ctx)
739
740 var implicits android.Paths
741 implicits = append(implicits, deps.bootClasspath...)
742 implicits = append(implicits, deps.classpath...)
743
Nan Zhang1598a9e2018-09-04 17:14:32 -0700744 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700745
Colin Cross83bb3162018-06-25 15:48:06 -0700746 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700747 if len(deps.bootClasspath) > 0 {
748 var systemModules classpath
749 if deps.systemModules != nil {
750 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800751 }
Colin Cross997262f2018-06-19 22:49:39 -0700752 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
753 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800754 }
755 if len(deps.classpath.Strings()) > 0 {
756 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
757 }
758
759 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700760 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800761
Nan Zhangaf322cc2018-06-19 15:15:38 -0700762 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800763
Nan Zhang1598a9e2018-09-04 17:14:32 -0700764 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
765
Nan Zhang581fd212018-01-10 16:06:12 -0800766 ctx.Build(pctx, android.BuildParams{
767 Rule: javadoc,
768 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800769 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800770 ImplicitOutput: j.docZip,
771 Inputs: j.srcFiles,
772 Implicits: implicits,
773 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700774 "outDir": android.PathForModuleOut(ctx, "out").String(),
775 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
776 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800777 "srcJars": strings.Join(j.srcJars.Strings(), " "),
778 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700779 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800780 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700781 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800782 "docZip": j.docZip.String(),
783 },
784 })
785}
786
Nan Zhanga40da042018-08-01 12:48:00 -0700787//
788// Droiddoc
789//
790type Droiddoc struct {
791 Javadoc
792
793 properties DroiddocProperties
794 apiFile android.WritablePath
795 dexApiFile android.WritablePath
796 privateApiFile android.WritablePath
797 privateDexApiFile android.WritablePath
798 removedApiFile android.WritablePath
799 removedDexApiFile android.WritablePath
800 exactApiFile android.WritablePath
801 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700802 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700803
804 checkCurrentApiTimestamp android.WritablePath
805 updateCurrentApiTimestamp android.WritablePath
806 checkLastReleasedApiTimestamp android.WritablePath
807
Nan Zhanga40da042018-08-01 12:48:00 -0700808 apiFilePath android.Path
809}
810
Nan Zhanga40da042018-08-01 12:48:00 -0700811func DroiddocFactory() android.Module {
812 module := &Droiddoc{}
813
814 module.AddProperties(&module.properties,
815 &module.Javadoc.properties)
816
817 InitDroiddocModule(module, android.HostAndDeviceSupported)
818 return module
819}
820
821func DroiddocHostFactory() android.Module {
822 module := &Droiddoc{}
823
824 module.AddProperties(&module.properties,
825 &module.Javadoc.properties)
826
827 InitDroiddocModule(module, android.HostSupported)
828 return module
829}
830
831func (d *Droiddoc) ApiFilePath() android.Path {
832 return d.apiFilePath
833}
834
Nan Zhang581fd212018-01-10 16:06:12 -0800835func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
836 d.Javadoc.addDeps(ctx)
837
Nan Zhang79614d12018-04-19 18:03:39 -0700838 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800839 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
840 }
841
Nan Zhang581fd212018-01-10 16:06:12 -0800842 // knowntags may contain filegroup or genrule.
843 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700844
Nan Zhange2ba5d42018-07-11 15:16:55 -0700845 if String(d.properties.Static_doc_index_redirect) != "" {
846 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
847 }
848
849 if String(d.properties.Static_doc_properties) != "" {
850 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
851 }
852
Nan Zhang1598a9e2018-09-04 17:14:32 -0700853 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700854 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
855 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
856 }
857
Nan Zhang1598a9e2018-09-04 17:14:32 -0700858 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700859 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
860 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
861 }
Nan Zhang581fd212018-01-10 16:06:12 -0800862}
863
Nan Zhang66dc2362018-08-14 20:41:04 -0700864func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
865 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700866 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800867
Nan Zhanga40da042018-08-01 12:48:00 -0700868 *implicits = append(*implicits, deps.bootClasspath...)
869 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800870
Nan Zhangc94f9d82018-06-26 10:02:26 -0700871 if len(deps.bootClasspath.Strings()) > 0 {
872 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700873 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700874 }
Nan Zhanga40da042018-08-01 12:48:00 -0700875 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700876 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700877 dokkaClasspath := classpath{}
878 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
879 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
880 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700881
Nan Zhang9c69a122018-08-22 10:22:08 -0700882 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
883 // based stubs generation.
884 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
885 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
886 // the correct package name base path.
887 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
888 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
889 } else {
890 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
891 }
Nan Zhang581fd212018-01-10 16:06:12 -0800892
Nan Zhanga40da042018-08-01 12:48:00 -0700893 return flags, nil
894}
Nan Zhang581fd212018-01-10 16:06:12 -0800895
Nan Zhanga40da042018-08-01 12:48:00 -0700896func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700897 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800898
Nan Zhanga40da042018-08-01 12:48:00 -0700899 *implicits = append(*implicits, jsilver)
900 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700901
Nan Zhang46130972018-06-04 11:28:01 -0700902 var date string
903 if runtime.GOOS == "darwin" {
904 date = `date -r`
905 } else {
906 date = `date -d`
907 }
908
Nan Zhang443fa522018-08-20 20:58:28 -0700909 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
910 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
911 // 1.9 language features.
912 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700913 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800914 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700915 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700916
Nan Zhanga40da042018-08-01 12:48:00 -0700917 if String(d.properties.Custom_template) == "" {
918 // TODO: This is almost always droiddoc-templates-sdk
919 ctx.PropertyErrorf("custom_template", "must specify a template")
920 }
921
922 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700923 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700924 *implicits = append(*implicits, t.deps...)
925 args = args + " -templatedir " + t.dir.String()
926 } else {
927 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
928 }
929 })
930
931 if len(d.properties.Html_dirs) > 0 {
932 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
933 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
934 args = args + " -htmldir " + htmlDir.String()
935 }
936
937 if len(d.properties.Html_dirs) > 1 {
938 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
939 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
940 args = args + " -htmldir2 " + htmlDir2.String()
941 }
942
943 if len(d.properties.Html_dirs) > 2 {
944 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
945 }
946
947 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
948 *implicits = append(*implicits, knownTags...)
949
950 for _, kt := range knownTags {
951 args = args + " -knowntags " + kt.String()
952 }
953
954 for _, hdf := range d.properties.Hdf {
955 args = args + " -hdf " + hdf
956 }
957
958 if String(d.properties.Proofread_file) != "" {
959 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
960 args = args + " -proofread " + proofreadFile.String()
961 }
962
963 if String(d.properties.Todo_file) != "" {
964 // tricky part:
965 // we should not compute full path for todo_file through PathForModuleOut().
966 // the non-standard doclet will get the full path relative to "-o".
967 args = args + " -todo " + String(d.properties.Todo_file)
968 }
969
970 if String(d.properties.Resourcesdir) != "" {
971 // TODO: should we add files under resourcesDir to the implicits? It seems that
972 // resourcesDir is one sub dir of htmlDir
973 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
974 args = args + " -resourcesdir " + resourcesDir.String()
975 }
976
977 if String(d.properties.Resourcesoutdir) != "" {
978 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
979 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
980 }
981 return args
982}
983
Nan Zhang1598a9e2018-09-04 17:14:32 -0700984func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
985 implicitOutputs *android.WritablePaths) string {
986 var doclavaFlags string
987 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
988 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
989 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700990 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
991 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700992 *implicitOutputs = append(*implicitOutputs, d.apiFile)
993 d.apiFilePath = d.apiFile
994 }
995
Nan Zhang1598a9e2018-09-04 17:14:32 -0700996 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
997 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
998 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700999 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1000 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001001 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1002 }
1003
1004 if String(d.properties.Private_api_filename) != "" {
1005 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1006 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001007 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1008 }
1009
1010 if String(d.properties.Dex_api_filename) != "" {
1011 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1012 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1013 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1014 }
1015
1016 if String(d.properties.Private_dex_api_filename) != "" {
1017 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1018 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001019 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1020 }
1021
1022 if String(d.properties.Removed_dex_api_filename) != "" {
1023 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1024 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001025 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1026 }
1027
1028 if String(d.properties.Exact_api_filename) != "" {
1029 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1030 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001031 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1032 }
1033
1034 if String(d.properties.Dex_mapping_filename) != "" {
1035 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1036 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001037 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1038 }
1039
Nan Zhang66dc2362018-08-14 20:41:04 -07001040 if String(d.properties.Proguard_filename) != "" {
1041 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1042 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001043 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1044 }
1045
Nan Zhanga40da042018-08-01 12:48:00 -07001046 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001047 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001048 }
1049
1050 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001051 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001052 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001053
1054 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001055}
1056
1057func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1058 var cmds string
1059 if String(d.properties.Static_doc_index_redirect) != "" {
1060 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1061 "static_doc_index_redirect")
1062 *implicits = append(*implicits, static_doc_index_redirect)
1063 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001064 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001065 }
1066
1067 if String(d.properties.Static_doc_properties) != "" {
1068 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1069 "static_doc_properties")
1070 *implicits = append(*implicits, static_doc_properties)
1071 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001072 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001073 }
1074 return cmds
1075}
1076
Nan Zhang1598a9e2018-09-04 17:14:32 -07001077func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1078 implicitOutputs android.WritablePaths,
1079 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1080 ctx.Build(pctx, android.BuildParams{
1081 Rule: javadoc,
1082 Description: "Doclava",
1083 Output: d.Javadoc.stubsSrcJar,
1084 Inputs: d.Javadoc.srcFiles,
1085 Implicits: implicits,
1086 ImplicitOutputs: implicitOutputs,
1087 Args: map[string]string{
1088 "outDir": android.PathForModuleOut(ctx, "out").String(),
1089 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1090 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1091 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1092 "opts": opts,
1093 "bootclasspathArgs": bootclasspathArgs,
1094 "classpathArgs": classpathArgs,
1095 "sourcepathArgs": sourcepathArgs,
1096 "docZip": d.Javadoc.docZip.String(),
1097 "postDoclavaCmds": postDoclavaCmds,
1098 },
1099 })
1100}
1101
1102func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1103 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1104 ctx.Build(pctx, android.BuildParams{
1105 Rule: apiCheck,
1106 Description: "Doclava Check API",
1107 Output: output,
1108 Inputs: nil,
1109 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1110 checkApiClasspath...),
1111 Args: map[string]string{
1112 "msg": msg,
1113 "classpath": checkApiClasspath.FormJavaClassPath(""),
1114 "opts": opts,
1115 "apiFile": apiFile.String(),
1116 "apiFileToCheck": d.apiFile.String(),
1117 "removedApiFile": removedApiFile.String(),
1118 "removedApiFileToCheck": d.removedApiFile.String(),
1119 },
1120 })
1121}
1122
1123func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1124 classpathArgs, opts string) {
1125 ctx.Build(pctx, android.BuildParams{
1126 Rule: dokka,
1127 Description: "Dokka",
1128 Output: d.Javadoc.stubsSrcJar,
1129 Inputs: d.Javadoc.srcFiles,
1130 Implicits: implicits,
1131 Args: map[string]string{
1132 "outDir": android.PathForModuleOut(ctx, "out").String(),
1133 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1134 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1135 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1136 "classpathArgs": classpathArgs,
1137 "opts": opts,
1138 "docZip": d.Javadoc.docZip.String(),
1139 },
1140 })
1141}
1142
1143func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1144 deps := d.Javadoc.collectDeps(ctx)
1145
1146 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1147 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1148 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1149 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1150
1151 var implicits android.Paths
1152 implicits = append(implicits, d.Javadoc.srcJars...)
1153 implicits = append(implicits, d.Javadoc.argFiles...)
1154
1155 var implicitOutputs android.WritablePaths
1156 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1157 for _, o := range d.Javadoc.properties.Out {
1158 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1159 }
1160
1161 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1162 if err != nil {
1163 return
1164 }
1165
1166 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1167 if Bool(d.properties.Dokka_enabled) {
1168 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1169 } else {
1170 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1171 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1172 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1173 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1174 flags.postDoclavaCmds)
1175 }
1176
1177 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1178 !ctx.Config().IsPdkBuild() {
1179 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1180 "check_api.current.api_file")
1181 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1182 "check_api.current_removed_api_file")
1183
1184 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1185 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1186 fmt.Sprintf(`\n******************************\n`+
1187 `You have tried to change the API from what has been previously approved.\n\n`+
1188 `To make these errors go away, you have two choices:\n`+
1189 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1190 ` errors above.\n\n`+
1191 ` 2. You can update current.txt by executing the following command:\n`+
1192 ` make %s-update-current-api\n\n`+
1193 ` To submit the revised current.txt to the main Android repository,\n`+
1194 ` you will need approval.\n`+
1195 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1196 d.checkCurrentApiTimestamp)
1197
1198 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1199 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1200 d.updateCurrentApiTimestamp)
1201 }
1202
1203 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1204 !ctx.Config().IsPdkBuild() {
1205 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1206 "check_api.last_released.api_file")
1207 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1208 "check_api.last_released.removed_api_file")
1209
1210 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1211 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1212 `\n******************************\n`+
1213 `You have tried to change the API from what has been previously released in\n`+
1214 `an SDK. Please fix the errors listed above.\n`+
1215 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1216 d.checkLastReleasedApiTimestamp)
1217 }
1218}
1219
1220//
1221// Droidstubs
1222//
1223type Droidstubs struct {
1224 Javadoc
1225
Pete Gillin581d6082018-10-22 15:55:04 +01001226 properties DroidstubsProperties
1227 apiFile android.WritablePath
1228 apiXmlFile android.WritablePath
1229 lastReleasedApiXmlFile android.WritablePath
1230 dexApiFile android.WritablePath
1231 privateApiFile android.WritablePath
1232 privateDexApiFile android.WritablePath
1233 removedApiFile android.WritablePath
1234 removedDexApiFile android.WritablePath
1235 apiMappingFile android.WritablePath
1236 exactApiFile android.WritablePath
1237 proguardFile android.WritablePath
1238 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001239
1240 checkCurrentApiTimestamp android.WritablePath
1241 updateCurrentApiTimestamp android.WritablePath
1242 checkLastReleasedApiTimestamp android.WritablePath
1243
Pete Gillin581d6082018-10-22 15:55:04 +01001244 checkNullabilityWarningsTimestamp android.WritablePath
1245
Nan Zhang1598a9e2018-09-04 17:14:32 -07001246 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001247 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001248
1249 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001250
1251 jdiffDocZip android.WritablePath
1252 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253}
1254
1255func DroidstubsFactory() android.Module {
1256 module := &Droidstubs{}
1257
1258 module.AddProperties(&module.properties,
1259 &module.Javadoc.properties)
1260
1261 InitDroiddocModule(module, android.HostAndDeviceSupported)
1262 return module
1263}
1264
1265func DroidstubsHostFactory() android.Module {
1266 module := &Droidstubs{}
1267
1268 module.AddProperties(&module.properties,
1269 &module.Javadoc.properties)
1270
1271 InitDroiddocModule(module, android.HostSupported)
1272 return module
1273}
1274
1275func (d *Droidstubs) ApiFilePath() android.Path {
1276 return d.apiFilePath
1277}
1278
1279func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1280 d.Javadoc.addDeps(ctx)
1281
1282 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1283 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1284 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1285 }
1286
1287 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1288 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1289 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1290 }
1291
1292 if String(d.properties.Previous_api) != "" {
1293 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1294 }
1295
1296 if len(d.properties.Merge_annotations_dirs) != 0 {
1297 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1298 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1299 }
1300 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001301
Pete Gillin77167902018-09-19 18:16:26 +01001302 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1303 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1304 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1305 }
1306 }
1307
Pete Gillinc382a562018-11-14 18:45:46 +00001308 if String(d.properties.Validate_nullability_from_list) != "" {
1309 android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list)
1310 }
Pete Gillin581d6082018-10-22 15:55:04 +01001311 if String(d.properties.Check_nullability_warnings) != "" {
1312 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1313 }
1314
Nan Zhang9c69a122018-08-22 10:22:08 -07001315 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1316 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1317 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1318 }
1319 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001320}
1321
1322func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1323 deps deps) (droiddocBuilderFlags, error) {
1324 var flags droiddocBuilderFlags
1325
1326 *implicits = append(*implicits, deps.bootClasspath...)
1327 *implicits = append(*implicits, deps.classpath...)
1328
1329 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1330 // since it doesn't support system modules yet.
1331 if len(deps.bootClasspath.Strings()) > 0 {
1332 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1333 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1334 }
1335 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1336
Sundong Ahn56dce442018-10-05 18:41:09 +09001337 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001338 return flags, nil
1339}
1340
1341func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1342 implicitOutputs *android.WritablePaths) string {
1343 var metalavaFlags string
1344 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1345 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1346 String(d.properties.Api_filename) != "" {
1347 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1348 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1349 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1350 d.apiFilePath = d.apiFile
1351 }
1352
1353 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1354 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1355 String(d.properties.Removed_api_filename) != "" {
1356 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1357 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1358 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1359 }
1360
1361 if String(d.properties.Private_api_filename) != "" {
1362 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1363 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1364 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1365 }
1366
1367 if String(d.properties.Dex_api_filename) != "" {
1368 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1369 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1370 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1371 }
1372
1373 if String(d.properties.Private_dex_api_filename) != "" {
1374 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1375 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1376 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1377 }
1378
1379 if String(d.properties.Removed_dex_api_filename) != "" {
1380 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1381 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1382 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1383 }
1384
1385 if String(d.properties.Exact_api_filename) != "" {
1386 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1387 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1388 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1389 }
1390
Nan Zhang9c69a122018-08-22 10:22:08 -07001391 if String(d.properties.Dex_mapping_filename) != "" {
1392 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1393 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1394 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1395 }
1396
Nan Zhang199645c2018-09-19 12:40:06 -07001397 if String(d.properties.Proguard_filename) != "" {
1398 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1399 metalavaFlags += " --proguard " + d.proguardFile.String()
1400 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1401 }
1402
Nan Zhang9c69a122018-08-22 10:22:08 -07001403 if Bool(d.properties.Write_sdk_values) {
1404 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1405 }
1406
Nan Zhang1598a9e2018-09-04 17:14:32 -07001407 if Bool(d.properties.Create_doc_stubs) {
1408 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1409 } else {
1410 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1411 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001412 return metalavaFlags
1413}
1414
1415func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1416 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001417 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001418 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001419 flags += " --include-annotations"
Pete Gillinc382a562018-11-14 18:45:46 +00001420 validatingNullability :=
1421 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1422 String(d.properties.Validate_nullability_from_list) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001423 migratingNullability := String(d.properties.Previous_api) != ""
1424 if !(migratingNullability || validatingNullability) {
1425 ctx.PropertyErrorf("previous_api",
1426 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001427 }
Pete Gillina262c052018-09-14 14:25:48 +01001428 if migratingNullability {
1429 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1430 *implicits = append(*implicits, previousApi)
1431 flags += " --migrate-nullness " + previousApi.String()
1432 }
Pete Gillinc382a562018-11-14 18:45:46 +00001433 if s := String(d.properties.Validate_nullability_from_list); s != "" {
1434 flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String()
1435 }
Pete Gillina262c052018-09-14 14:25:48 +01001436 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001437 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1438 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1439 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001440 }
Nan Zhanga40da042018-08-01 12:48:00 -07001441
1442 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1443 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1444
Nan Zhangf4936b02018-08-01 15:00:28 -07001445 flags += " --extract-annotations " + d.annotationsZip.String()
1446
Nan Zhang1598a9e2018-09-04 17:14:32 -07001447 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001448 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001449 "has to be non-empty if annotations was enabled!")
1450 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001451 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1452 if t, ok := m.(*ExportedDroiddocDir); ok {
1453 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001454 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001455 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001456 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001457 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1458 }
1459 })
Nan Zhanga40da042018-08-01 12:48:00 -07001460 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001461 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001462 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001463
1464 return flags
1465}
1466
1467func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1468 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1469 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001470 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1471 if t, ok := m.(*ExportedDroiddocDir); ok {
1472 *implicits = append(*implicits, t.deps...)
1473 flags += " --merge-inclusion-annotations " + t.dir.String()
1474 } else {
1475 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1476 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1477 }
1478 })
Nan Zhanga40da042018-08-01 12:48:00 -07001479
1480 return flags
1481}
1482
Nan Zhang9c69a122018-08-22 10:22:08 -07001483func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1484 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1485 var flags string
1486 if Bool(d.properties.Api_levels_annotations_enabled) {
1487 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1488 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1489
1490 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1491 ctx.PropertyErrorf("api_levels_annotations_dirs",
1492 "has to be non-empty if api levels annotations was enabled!")
1493 }
1494
1495 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1496 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1497 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1498
1499 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1500 if t, ok := m.(*ExportedDroiddocDir); ok {
1501 var androidJars android.Paths
1502 for _, dep := range t.deps {
1503 if strings.HasSuffix(dep.String(), "android.jar") {
1504 androidJars = append(androidJars, dep)
1505 }
1506 }
1507 *implicits = append(*implicits, androidJars...)
1508 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1509 } else {
1510 ctx.PropertyErrorf("api_levels_annotations_dirs",
1511 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1512 }
1513 })
1514
1515 }
1516
1517 return flags
1518}
1519
Nan Zhang71bbe632018-09-17 14:32:21 -07001520func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1521 implicitOutputs *android.WritablePaths) string {
1522 var flags string
1523 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1524 if d.apiFile.String() == "" {
1525 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1526 }
1527
1528 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1529 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1530
1531 flags = " --api-xml " + d.apiXmlFile.String()
1532
1533 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1534 ctx.PropertyErrorf("check_api.last_released.api_file",
1535 "has to be non-empty if jdiff was enabled!")
1536 }
1537 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1538 "check_api.last_released.api_file")
1539 *implicits = append(*implicits, lastReleasedApi)
1540
1541 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1542 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1543
1544 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1545 d.lastReleasedApiXmlFile.String()
1546 }
1547
1548 return flags
1549}
1550
Nan Zhang1598a9e2018-09-04 17:14:32 -07001551func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1552 implicitOutputs android.WritablePaths, javaVersion,
1553 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001554
Nan Zhang86d2d552018-08-09 15:33:27 -07001555 ctx.Build(pctx, android.BuildParams{
1556 Rule: metalava,
1557 Description: "Metalava",
1558 Output: d.Javadoc.stubsSrcJar,
1559 Inputs: d.Javadoc.srcFiles,
1560 Implicits: implicits,
1561 ImplicitOutputs: implicitOutputs,
1562 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001563 "outDir": android.PathForModuleOut(ctx, "out").String(),
1564 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1565 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1566 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001567 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001568 "bootclasspathArgs": bootclasspathArgs,
1569 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001570 "sourcepathArgs": sourcepathArgs,
1571 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001572 },
1573 })
1574}
1575
Nan Zhang1598a9e2018-09-04 17:14:32 -07001576func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1577 apiFile, removedApiFile android.Path, implicits android.Paths,
1578 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001579 output android.WritablePath) {
1580 ctx.Build(pctx, android.BuildParams{
1581 Rule: metalavaApiCheck,
1582 Description: "Metalava Check API",
1583 Output: output,
1584 Inputs: d.Javadoc.srcFiles,
1585 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1586 implicits...),
1587 Args: map[string]string{
1588 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1589 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1590 "javaVersion": javaVersion,
1591 "bootclasspathArgs": bootclasspathArgs,
1592 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001593 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001594 "opts": opts,
1595 "msg": msg,
1596 },
1597 })
1598}
1599
Nan Zhang71bbe632018-09-17 14:32:21 -07001600func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1601 implicitOutputs android.WritablePaths,
1602 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1603 ctx.Build(pctx, android.BuildParams{
1604 Rule: javadoc,
1605 Description: "Jdiff",
1606 Output: d.jdiffStubsSrcJar,
1607 Inputs: d.Javadoc.srcFiles,
1608 Implicits: implicits,
1609 ImplicitOutputs: implicitOutputs,
1610 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001611 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1612 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1613 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001614 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1615 "opts": opts,
1616 "bootclasspathArgs": bootclasspathArgs,
1617 "classpathArgs": classpathArgs,
1618 "sourcepathArgs": sourcepathArgs,
1619 "docZip": d.jdiffDocZip.String(),
1620 },
1621 })
1622}
1623
Nan Zhang1598a9e2018-09-04 17:14:32 -07001624func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001625 deps := d.Javadoc.collectDeps(ctx)
1626
1627 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001628
Nan Zhanga40da042018-08-01 12:48:00 -07001629 var implicits android.Paths
1630 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001631 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001632
1633 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001634 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001635 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1636 }
1637
1638 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001639 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001640 jdiffImplicits := implicits
1641
Nan Zhanga40da042018-08-01 12:48:00 -07001642 if err != nil {
1643 return
1644 }
1645
Nan Zhang1598a9e2018-09-04 17:14:32 -07001646 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1647 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001648 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001649 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001650 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1651
Nan Zhang1598a9e2018-09-04 17:14:32 -07001652 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1653 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1654 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1655 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1656 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001657 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001658 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1659 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001660 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001661 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001662
Nan Zhang1598a9e2018-09-04 17:14:32 -07001663 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1664 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001665 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1666 "check_api.current.api_file")
1667 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1668 "check_api.current_removed_api_file")
1669
Nan Zhang2760dfc2018-08-24 17:32:54 +00001670 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001671 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1672 " --check-compatibility:removed:current " + removedApiFile.String() +
1673 flags.metalavaInclusionAnnotationsFlags
Nan Zhang2760dfc2018-08-24 17:32:54 +00001674
Nan Zhang1598a9e2018-09-04 17:14:32 -07001675 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1676 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1677 fmt.Sprintf(`\n******************************\n`+
1678 `You have tried to change the API from what has been previously approved.\n\n`+
1679 `To make these errors go away, you have two choices:\n`+
1680 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1681 ` errors above.\n\n`+
1682 ` 2. You can update current.txt by executing the following command:\n`+
1683 ` make %s-update-current-api\n\n`+
1684 ` To submit the revised current.txt to the main Android repository,\n`+
1685 ` you will need approval.\n`+
1686 `******************************\n`, ctx.ModuleName()),
1687 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001688
1689 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001690 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1691 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001692 }
Nan Zhanga40da042018-08-01 12:48:00 -07001693
Nan Zhang1598a9e2018-09-04 17:14:32 -07001694 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1695 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001696 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1697 "check_api.last_released.api_file")
1698 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1699 "check_api.last_released.removed_api_file")
1700
Nan Zhang2760dfc2018-08-24 17:32:54 +00001701 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001702 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1703 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
1704 removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001705
Nan Zhang1598a9e2018-09-04 17:14:32 -07001706 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1707 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1708 `\n******************************\n`+
1709 `You have tried to change the API from what has been previously released in\n`+
1710 `an SDK. Please fix the errors listed above.\n`+
1711 `******************************\n`,
1712 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001713 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001714
Pete Gillin581d6082018-10-22 15:55:04 +01001715 if String(d.properties.Check_nullability_warnings) != "" {
1716 if d.nullabilityWarningsFile == nil {
1717 ctx.PropertyErrorf("check_nullability_warnings",
1718 "Cannot specify check_nullability_warnings unless validating nullability")
1719 }
1720 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1721 "check_nullability_warnings")
1722 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1723 msg := fmt.Sprintf(`\n******************************\n`+
1724 `The warnings encountered during nullability annotation validation did\n`+
1725 `not match the checked in file of expected warnings. The diffs are shown\n`+
1726 `above. You have two options:\n`+
1727 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1728 ` 2. Update the file of expected warnings by running:\n`+
1729 ` cp %s %s\n`+
1730 ` and submitting the updated file as part of your change.`,
1731 d.nullabilityWarningsFile, checkNullabilityWarnings)
1732 ctx.Build(pctx, android.BuildParams{
1733 Rule: nullabilityWarningsCheck,
1734 Description: "Nullability Warnings Check",
1735 Output: d.checkNullabilityWarningsTimestamp,
1736 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1737 Args: map[string]string{
1738 "expected": checkNullabilityWarnings.String(),
1739 "actual": d.nullabilityWarningsFile.String(),
1740 "msg": msg,
1741 },
1742 })
1743 }
1744
Nan Zhang71bbe632018-09-17 14:32:21 -07001745 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1746
Nan Zhang86b06202018-09-21 17:09:21 -07001747 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1748 // since there's cron job downstream that fetch this .zip file periodically.
1749 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001750 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1751 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1752
1753 var jdiffImplicitOutputs android.WritablePaths
1754 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1755
1756 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1757 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1758
1759 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1760 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1761 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1762 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1763 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1764 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1765
1766 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1767 flags.sourcepathArgs, opts)
1768 }
Nan Zhang581fd212018-01-10 16:06:12 -08001769}
Dan Willemsencc090972018-02-26 14:33:31 -08001770
Nan Zhanga40da042018-08-01 12:48:00 -07001771//
Nan Zhangf4936b02018-08-01 15:00:28 -07001772// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001773//
Dan Willemsencc090972018-02-26 14:33:31 -08001774var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001775var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001776var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001777var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001778
Nan Zhangf4936b02018-08-01 15:00:28 -07001779type ExportedDroiddocDirProperties struct {
1780 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001781 Path *string
1782}
1783
Nan Zhangf4936b02018-08-01 15:00:28 -07001784type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001785 android.ModuleBase
1786
Nan Zhangf4936b02018-08-01 15:00:28 -07001787 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001788
1789 deps android.Paths
1790 dir android.Path
1791}
1792
Nan Zhangf4936b02018-08-01 15:00:28 -07001793func ExportedDroiddocDirFactory() android.Module {
1794 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001795 module.AddProperties(&module.properties)
1796 android.InitAndroidModule(module)
1797 return module
1798}
1799
Nan Zhangf4936b02018-08-01 15:00:28 -07001800func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001801
Nan Zhangf4936b02018-08-01 15:00:28 -07001802func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001803 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1804 d.dir = path
1805 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1806}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001807
1808//
1809// Defaults
1810//
1811type DocDefaults struct {
1812 android.ModuleBase
1813 android.DefaultsModuleBase
1814}
1815
1816func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1817}
1818
1819func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1820}
1821
1822func DocDefaultsFactory() android.Module {
1823 module := &DocDefaults{}
1824
1825 module.AddProperties(
1826 &JavadocProperties{},
1827 &DroiddocProperties{},
1828 )
1829
1830 android.InitDefaultsModule(module)
1831
1832 return module
1833}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001834
1835func StubsDefaultsFactory() android.Module {
1836 module := &DocDefaults{}
1837
1838 module.AddProperties(
1839 &JavadocProperties{},
1840 &DroidstubsProperties{},
1841 )
1842
1843 android.InitDefaultsModule(module)
1844
1845 return module
1846}