blob: 9dadb30e589fec0c1c9f728fb44b21002e55f781 [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 Gillin581d6082018-10-22 15:55:04 +0100363 // a file containing expected warnings produced by validation of nullability annotations.
364 Check_nullability_warnings *string
365
Nan Zhang1598a9e2018-09-04 17:14:32 -0700366 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
367 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700368
369 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
370 Api_levels_annotations_enabled *bool
371
372 // the dirs which Metalava extracts API levels annotations from.
373 Api_levels_annotations_dirs []string
374
375 // if set to true, collect the values used by the Dev tools and
376 // write them in files packaged with the SDK. Defaults to false.
377 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700378
379 // If set to true, .xml based public API file will be also generated, and
380 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
381 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800382}
383
Nan Zhanga40da042018-08-01 12:48:00 -0700384//
385// Common flags passed down to build rule
386//
387type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700388 bootClasspathArgs string
389 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700390 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700391 dokkaClasspathArgs string
392 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700393
Nan Zhanga40da042018-08-01 12:48:00 -0700394 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700395 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700396 postDoclavaCmds string
397
Nan Zhang9c69a122018-08-22 10:22:08 -0700398 metalavaStubsFlags string
399 metalavaAnnotationsFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100400 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700401 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700402
Nan Zhang71bbe632018-09-17 14:32:21 -0700403 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700404}
405
406func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
407 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
408 android.InitDefaultableModule(module)
409}
410
Nan Zhang1598a9e2018-09-04 17:14:32 -0700411func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
412 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
413 return true
414 } else if String(apiToCheck.Api_file) != "" {
415 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
416 } else if String(apiToCheck.Removed_api_file) != "" {
417 panic("for " + apiVersionTag + " api_file has to be non-empty!")
418 }
419
420 return false
421}
422
423type ApiFilePath interface {
424 ApiFilePath() android.Path
425}
426
427func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
428 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
429 ctx.Build(pctx, android.BuildParams{
430 Rule: updateApi,
431 Description: "Update API",
432 Output: output,
433 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
434 destApiFile, destRemovedApiFile),
435 Args: map[string]string{
436 "destApiFile": destApiFile.String(),
437 "srcApiFile": srcApiFile.String(),
438 "destRemovedApiFile": destRemovedApiFile.String(),
439 "srcRemovedApiFile": srcRemovedApiFile.String(),
440 },
441 })
442}
443
Nan Zhanga40da042018-08-01 12:48:00 -0700444//
445// Javadoc
446//
Nan Zhang581fd212018-01-10 16:06:12 -0800447type Javadoc struct {
448 android.ModuleBase
449 android.DefaultableModuleBase
450
451 properties JavadocProperties
452
453 srcJars android.Paths
454 srcFiles android.Paths
455 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700456 argFiles android.Paths
457
458 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800459
Nan Zhangccff0f72018-03-08 17:26:16 -0800460 docZip android.WritablePath
461 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800462}
463
Nan Zhangb2b33de2018-02-23 11:18:47 -0800464func (j *Javadoc) Srcs() android.Paths {
465 return android.Paths{j.stubsSrcJar}
466}
467
Nan Zhang581fd212018-01-10 16:06:12 -0800468func JavadocFactory() android.Module {
469 module := &Javadoc{}
470
471 module.AddProperties(&module.properties)
472
473 InitDroiddocModule(module, android.HostAndDeviceSupported)
474 return module
475}
476
477func JavadocHostFactory() android.Module {
478 module := &Javadoc{}
479
480 module.AddProperties(&module.properties)
481
482 InitDroiddocModule(module, android.HostSupported)
483 return module
484}
485
Nan Zhanga40da042018-08-01 12:48:00 -0700486var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800487
Colin Cross83bb3162018-06-25 15:48:06 -0700488func (j *Javadoc) sdkVersion() string {
489 return String(j.properties.Sdk_version)
490}
491
492func (j *Javadoc) minSdkVersion() string {
493 return j.sdkVersion()
494}
495
Dan Willemsen419290a2018-10-31 15:28:47 -0700496func (j *Javadoc) targetSdkVersion() string {
497 return j.sdkVersion()
498}
499
Nan Zhang581fd212018-01-10 16:06:12 -0800500func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
501 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700502 if !Bool(j.properties.No_standard_libs) {
503 sdkDep := decodeSdkDep(ctx, sdkContext(j))
504 if sdkDep.useDefaultLibs {
505 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
506 if ctx.Config().TargetOpenJDK9() {
507 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
508 }
509 if !Bool(j.properties.No_framework_libs) {
510 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
511 }
512 } else if sdkDep.useModule {
513 if ctx.Config().TargetOpenJDK9() {
514 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
515 }
516 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700517 }
Nan Zhang581fd212018-01-10 16:06:12 -0800518 }
519 }
520
Colin Cross42d48b72018-08-29 14:10:52 -0700521 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700522 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700523 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700524 }
Nan Zhang581fd212018-01-10 16:06:12 -0800525
526 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
527
528 // exclude_srcs may contain filegroup or genrule.
529 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700530
531 // arg_files may contains filegroup or genrule.
532 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800533}
534
Nan Zhangb2b33de2018-02-23 11:18:47 -0800535func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
536 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
537 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900538 // convert foo.bar.baz to foo/bar/baz
539 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
540 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800541 if _, found := whitelistPathPrefixes[prefix]; !found {
542 whitelistPathPrefixes[prefix] = true
543 }
544 }
545 }
546}
547
Nan Zhanga40da042018-08-01 12:48:00 -0700548func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
549 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900550
551 // aidl flags.
552 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
553 if len(aidlFlags) > 0 {
554 // optimization.
555 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
556 flags.aidlFlags = "$aidlFlags"
557 }
558
559 return flags
560}
561
562func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
563 aidlIncludeDirs android.Paths) []string {
564
565 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
566 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
567
568 var flags []string
569 if aidlPreprocess.Valid() {
570 flags = append(flags, "-p"+aidlPreprocess.String())
571 } else {
572 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
573 }
574
575 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
576 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
577 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
578 flags = append(flags, "-I"+src.String())
579 }
580
581 return flags
582}
583
584func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700585 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900586
587 outSrcFiles := make(android.Paths, 0, len(srcFiles))
588
589 for _, srcFile := range srcFiles {
590 switch srcFile.Ext() {
591 case ".aidl":
592 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
593 outSrcFiles = append(outSrcFiles, javaFile)
594 default:
595 outSrcFiles = append(outSrcFiles, srcFile)
596 }
597 }
598
599 return outSrcFiles
600}
601
Nan Zhang581fd212018-01-10 16:06:12 -0800602func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
603 var deps deps
604
Colin Cross83bb3162018-06-25 15:48:06 -0700605 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800606 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700607 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800608 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700609 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800610 }
611
612 ctx.VisitDirectDeps(func(module android.Module) {
613 otherName := ctx.OtherModuleName(module)
614 tag := ctx.OtherModuleDependencyTag(module)
615
Colin Cross2d24c1b2018-05-23 10:59:18 -0700616 switch tag {
617 case bootClasspathTag:
618 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800619 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700620 } else {
621 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
622 }
623 case libTag:
624 switch dep := module.(type) {
625 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800626 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700627 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700628 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900629 linkType := javaSdk
630 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
631 linkType = javaSystem
632 } else if sdkVersion == "" {
633 linkType = javaPlatform
634 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900635 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700636 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800637 checkProducesJars(ctx, dep)
638 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800639 default:
640 ctx.ModuleErrorf("depends on non-java module %q", otherName)
641 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700642 case srcsLibTag:
643 switch dep := module.(type) {
644 case Dependency:
645 srcs := dep.(SrcDependency).CompiledSrcs()
646 whitelistPathPrefixes := make(map[string]bool)
647 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
648 for _, src := range srcs {
649 if _, ok := src.(android.WritablePath); ok { // generated sources
650 deps.srcs = append(deps.srcs, src)
651 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700652 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700653 if strings.HasPrefix(src.Rel(), k) {
654 deps.srcs = append(deps.srcs, src)
655 break
656 }
657 }
658 }
659 }
660 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
661 default:
662 ctx.ModuleErrorf("depends on non-java module %q", otherName)
663 }
Nan Zhang357466b2018-04-17 17:38:36 -0700664 case systemModulesTag:
665 if deps.systemModules != nil {
666 panic("Found two system module dependencies")
667 }
668 sm := module.(*SystemModules)
669 if sm.outputFile == nil {
670 panic("Missing directory for system module dependency")
671 }
672 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800673 }
674 })
675 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
676 // may contain filegroup or genrule.
677 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700678 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900679 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800680
681 // srcs may depend on some genrule output.
682 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800683 j.srcJars = append(j.srcJars, deps.srcJars...)
684
Nan Zhang581fd212018-01-10 16:06:12 -0800685 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800686 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800687
688 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800689 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800690
Nan Zhang9c69a122018-08-22 10:22:08 -0700691 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800692 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
693 }
694 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800695
Nan Zhang1598a9e2018-09-04 17:14:32 -0700696 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
697 argFilesMap := map[string]android.Path{}
698
699 for _, f := range j.argFiles {
700 if _, exists := argFilesMap[f.Rel()]; !exists {
701 argFilesMap[f.Rel()] = f
702 } else {
703 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
704 f, argFilesMap[f.Rel()], f.Rel())
705 }
706 }
707
708 var err error
709 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
710 if strings.HasPrefix(name, "location ") {
711 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
712 if f, ok := argFilesMap[label]; ok {
713 return f.String(), nil
714 } else {
715 return "", fmt.Errorf("unknown location label %q", label)
716 }
717 } else if name == "genDir" {
718 return android.PathForModuleGen(ctx).String(), nil
719 }
720 return "", fmt.Errorf("unknown variable '$(%s)'", name)
721 })
722
723 if err != nil {
724 ctx.PropertyErrorf("args", "%s", err.Error())
725 }
726
Nan Zhang581fd212018-01-10 16:06:12 -0800727 return deps
728}
729
730func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
731 j.addDeps(ctx)
732}
733
734func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
735 deps := j.collectDeps(ctx)
736
737 var implicits android.Paths
738 implicits = append(implicits, deps.bootClasspath...)
739 implicits = append(implicits, deps.classpath...)
740
Nan Zhang1598a9e2018-09-04 17:14:32 -0700741 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700742
Colin Cross83bb3162018-06-25 15:48:06 -0700743 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700744 if len(deps.bootClasspath) > 0 {
745 var systemModules classpath
746 if deps.systemModules != nil {
747 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800748 }
Colin Cross997262f2018-06-19 22:49:39 -0700749 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
750 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800751 }
752 if len(deps.classpath.Strings()) > 0 {
753 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
754 }
755
756 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700757 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800758
Nan Zhangaf322cc2018-06-19 15:15:38 -0700759 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800760
Nan Zhang1598a9e2018-09-04 17:14:32 -0700761 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
762
Nan Zhang581fd212018-01-10 16:06:12 -0800763 ctx.Build(pctx, android.BuildParams{
764 Rule: javadoc,
765 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800766 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800767 ImplicitOutput: j.docZip,
768 Inputs: j.srcFiles,
769 Implicits: implicits,
770 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700771 "outDir": android.PathForModuleOut(ctx, "out").String(),
772 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
773 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800774 "srcJars": strings.Join(j.srcJars.Strings(), " "),
775 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700776 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800777 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700778 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800779 "docZip": j.docZip.String(),
780 },
781 })
782}
783
Nan Zhanga40da042018-08-01 12:48:00 -0700784//
785// Droiddoc
786//
787type Droiddoc struct {
788 Javadoc
789
790 properties DroiddocProperties
791 apiFile android.WritablePath
792 dexApiFile android.WritablePath
793 privateApiFile android.WritablePath
794 privateDexApiFile android.WritablePath
795 removedApiFile android.WritablePath
796 removedDexApiFile android.WritablePath
797 exactApiFile android.WritablePath
798 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700799 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700800
801 checkCurrentApiTimestamp android.WritablePath
802 updateCurrentApiTimestamp android.WritablePath
803 checkLastReleasedApiTimestamp android.WritablePath
804
Nan Zhanga40da042018-08-01 12:48:00 -0700805 apiFilePath android.Path
806}
807
Nan Zhanga40da042018-08-01 12:48:00 -0700808func DroiddocFactory() android.Module {
809 module := &Droiddoc{}
810
811 module.AddProperties(&module.properties,
812 &module.Javadoc.properties)
813
814 InitDroiddocModule(module, android.HostAndDeviceSupported)
815 return module
816}
817
818func DroiddocHostFactory() android.Module {
819 module := &Droiddoc{}
820
821 module.AddProperties(&module.properties,
822 &module.Javadoc.properties)
823
824 InitDroiddocModule(module, android.HostSupported)
825 return module
826}
827
828func (d *Droiddoc) ApiFilePath() android.Path {
829 return d.apiFilePath
830}
831
Nan Zhang581fd212018-01-10 16:06:12 -0800832func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
833 d.Javadoc.addDeps(ctx)
834
Nan Zhang79614d12018-04-19 18:03:39 -0700835 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800836 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
837 }
838
Nan Zhang581fd212018-01-10 16:06:12 -0800839 // knowntags may contain filegroup or genrule.
840 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700841
Nan Zhange2ba5d42018-07-11 15:16:55 -0700842 if String(d.properties.Static_doc_index_redirect) != "" {
843 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
844 }
845
846 if String(d.properties.Static_doc_properties) != "" {
847 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
848 }
849
Nan Zhang1598a9e2018-09-04 17:14:32 -0700850 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700851 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
852 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
853 }
854
Nan Zhang1598a9e2018-09-04 17:14:32 -0700855 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700856 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
857 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
858 }
Nan Zhang581fd212018-01-10 16:06:12 -0800859}
860
Nan Zhang66dc2362018-08-14 20:41:04 -0700861func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
862 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700863 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800864
Nan Zhanga40da042018-08-01 12:48:00 -0700865 *implicits = append(*implicits, deps.bootClasspath...)
866 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800867
Nan Zhangc94f9d82018-06-26 10:02:26 -0700868 if len(deps.bootClasspath.Strings()) > 0 {
869 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700870 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700871 }
Nan Zhanga40da042018-08-01 12:48:00 -0700872 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700873 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700874 dokkaClasspath := classpath{}
875 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
876 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
877 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700878
Nan Zhang9c69a122018-08-22 10:22:08 -0700879 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
880 // based stubs generation.
881 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
882 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
883 // the correct package name base path.
884 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
885 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
886 } else {
887 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
888 }
Nan Zhang581fd212018-01-10 16:06:12 -0800889
Nan Zhanga40da042018-08-01 12:48:00 -0700890 return flags, nil
891}
Nan Zhang581fd212018-01-10 16:06:12 -0800892
Nan Zhanga40da042018-08-01 12:48:00 -0700893func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700894 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800895
Nan Zhanga40da042018-08-01 12:48:00 -0700896 *implicits = append(*implicits, jsilver)
897 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700898
Nan Zhang46130972018-06-04 11:28:01 -0700899 var date string
900 if runtime.GOOS == "darwin" {
901 date = `date -r`
902 } else {
903 date = `date -d`
904 }
905
Nan Zhang443fa522018-08-20 20:58:28 -0700906 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
907 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
908 // 1.9 language features.
909 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700910 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800911 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700912 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700913
Nan Zhanga40da042018-08-01 12:48:00 -0700914 if String(d.properties.Custom_template) == "" {
915 // TODO: This is almost always droiddoc-templates-sdk
916 ctx.PropertyErrorf("custom_template", "must specify a template")
917 }
918
919 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700920 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700921 *implicits = append(*implicits, t.deps...)
922 args = args + " -templatedir " + t.dir.String()
923 } else {
924 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
925 }
926 })
927
928 if len(d.properties.Html_dirs) > 0 {
929 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
930 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
931 args = args + " -htmldir " + htmlDir.String()
932 }
933
934 if len(d.properties.Html_dirs) > 1 {
935 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
936 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
937 args = args + " -htmldir2 " + htmlDir2.String()
938 }
939
940 if len(d.properties.Html_dirs) > 2 {
941 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
942 }
943
944 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
945 *implicits = append(*implicits, knownTags...)
946
947 for _, kt := range knownTags {
948 args = args + " -knowntags " + kt.String()
949 }
950
951 for _, hdf := range d.properties.Hdf {
952 args = args + " -hdf " + hdf
953 }
954
955 if String(d.properties.Proofread_file) != "" {
956 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
957 args = args + " -proofread " + proofreadFile.String()
958 }
959
960 if String(d.properties.Todo_file) != "" {
961 // tricky part:
962 // we should not compute full path for todo_file through PathForModuleOut().
963 // the non-standard doclet will get the full path relative to "-o".
964 args = args + " -todo " + String(d.properties.Todo_file)
965 }
966
967 if String(d.properties.Resourcesdir) != "" {
968 // TODO: should we add files under resourcesDir to the implicits? It seems that
969 // resourcesDir is one sub dir of htmlDir
970 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
971 args = args + " -resourcesdir " + resourcesDir.String()
972 }
973
974 if String(d.properties.Resourcesoutdir) != "" {
975 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
976 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
977 }
978 return args
979}
980
Nan Zhang1598a9e2018-09-04 17:14:32 -0700981func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
982 implicitOutputs *android.WritablePaths) string {
983 var doclavaFlags string
984 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
985 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
986 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700987 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
988 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700989 *implicitOutputs = append(*implicitOutputs, d.apiFile)
990 d.apiFilePath = d.apiFile
991 }
992
Nan Zhang1598a9e2018-09-04 17:14:32 -0700993 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
994 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
995 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700996 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
997 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700998 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
999 }
1000
1001 if String(d.properties.Private_api_filename) != "" {
1002 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1003 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001004 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1005 }
1006
1007 if String(d.properties.Dex_api_filename) != "" {
1008 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1009 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1010 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1011 }
1012
1013 if String(d.properties.Private_dex_api_filename) != "" {
1014 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1015 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001016 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1017 }
1018
1019 if String(d.properties.Removed_dex_api_filename) != "" {
1020 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1021 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001022 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1023 }
1024
1025 if String(d.properties.Exact_api_filename) != "" {
1026 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1027 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001028 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1029 }
1030
1031 if String(d.properties.Dex_mapping_filename) != "" {
1032 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1033 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001034 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1035 }
1036
Nan Zhang66dc2362018-08-14 20:41:04 -07001037 if String(d.properties.Proguard_filename) != "" {
1038 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1039 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001040 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1041 }
1042
Nan Zhanga40da042018-08-01 12:48:00 -07001043 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001044 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001045 }
1046
1047 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001048 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001049 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001050
1051 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001052}
1053
1054func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1055 var cmds string
1056 if String(d.properties.Static_doc_index_redirect) != "" {
1057 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1058 "static_doc_index_redirect")
1059 *implicits = append(*implicits, static_doc_index_redirect)
1060 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001061 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001062 }
1063
1064 if String(d.properties.Static_doc_properties) != "" {
1065 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1066 "static_doc_properties")
1067 *implicits = append(*implicits, static_doc_properties)
1068 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001069 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001070 }
1071 return cmds
1072}
1073
Nan Zhang1598a9e2018-09-04 17:14:32 -07001074func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1075 implicitOutputs android.WritablePaths,
1076 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1077 ctx.Build(pctx, android.BuildParams{
1078 Rule: javadoc,
1079 Description: "Doclava",
1080 Output: d.Javadoc.stubsSrcJar,
1081 Inputs: d.Javadoc.srcFiles,
1082 Implicits: implicits,
1083 ImplicitOutputs: implicitOutputs,
1084 Args: map[string]string{
1085 "outDir": android.PathForModuleOut(ctx, "out").String(),
1086 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1087 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1088 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1089 "opts": opts,
1090 "bootclasspathArgs": bootclasspathArgs,
1091 "classpathArgs": classpathArgs,
1092 "sourcepathArgs": sourcepathArgs,
1093 "docZip": d.Javadoc.docZip.String(),
1094 "postDoclavaCmds": postDoclavaCmds,
1095 },
1096 })
1097}
1098
1099func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1100 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1101 ctx.Build(pctx, android.BuildParams{
1102 Rule: apiCheck,
1103 Description: "Doclava Check API",
1104 Output: output,
1105 Inputs: nil,
1106 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1107 checkApiClasspath...),
1108 Args: map[string]string{
1109 "msg": msg,
1110 "classpath": checkApiClasspath.FormJavaClassPath(""),
1111 "opts": opts,
1112 "apiFile": apiFile.String(),
1113 "apiFileToCheck": d.apiFile.String(),
1114 "removedApiFile": removedApiFile.String(),
1115 "removedApiFileToCheck": d.removedApiFile.String(),
1116 },
1117 })
1118}
1119
1120func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1121 classpathArgs, opts string) {
1122 ctx.Build(pctx, android.BuildParams{
1123 Rule: dokka,
1124 Description: "Dokka",
1125 Output: d.Javadoc.stubsSrcJar,
1126 Inputs: d.Javadoc.srcFiles,
1127 Implicits: implicits,
1128 Args: map[string]string{
1129 "outDir": android.PathForModuleOut(ctx, "out").String(),
1130 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1131 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1132 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1133 "classpathArgs": classpathArgs,
1134 "opts": opts,
1135 "docZip": d.Javadoc.docZip.String(),
1136 },
1137 })
1138}
1139
1140func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1141 deps := d.Javadoc.collectDeps(ctx)
1142
1143 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1144 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1145 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1146 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1147
1148 var implicits android.Paths
1149 implicits = append(implicits, d.Javadoc.srcJars...)
1150 implicits = append(implicits, d.Javadoc.argFiles...)
1151
1152 var implicitOutputs android.WritablePaths
1153 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1154 for _, o := range d.Javadoc.properties.Out {
1155 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1156 }
1157
1158 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1159 if err != nil {
1160 return
1161 }
1162
1163 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1164 if Bool(d.properties.Dokka_enabled) {
1165 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1166 } else {
1167 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1168 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1169 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1170 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1171 flags.postDoclavaCmds)
1172 }
1173
1174 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1175 !ctx.Config().IsPdkBuild() {
1176 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1177 "check_api.current.api_file")
1178 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1179 "check_api.current_removed_api_file")
1180
1181 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1182 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1183 fmt.Sprintf(`\n******************************\n`+
1184 `You have tried to change the API from what has been previously approved.\n\n`+
1185 `To make these errors go away, you have two choices:\n`+
1186 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1187 ` errors above.\n\n`+
1188 ` 2. You can update current.txt by executing the following command:\n`+
1189 ` make %s-update-current-api\n\n`+
1190 ` To submit the revised current.txt to the main Android repository,\n`+
1191 ` you will need approval.\n`+
1192 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1193 d.checkCurrentApiTimestamp)
1194
1195 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1196 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1197 d.updateCurrentApiTimestamp)
1198 }
1199
1200 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1201 !ctx.Config().IsPdkBuild() {
1202 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1203 "check_api.last_released.api_file")
1204 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1205 "check_api.last_released.removed_api_file")
1206
1207 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1208 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1209 `\n******************************\n`+
1210 `You have tried to change the API from what has been previously released in\n`+
1211 `an SDK. Please fix the errors listed above.\n`+
1212 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1213 d.checkLastReleasedApiTimestamp)
1214 }
1215}
1216
1217//
1218// Droidstubs
1219//
1220type Droidstubs struct {
1221 Javadoc
1222
Pete Gillin581d6082018-10-22 15:55:04 +01001223 properties DroidstubsProperties
1224 apiFile android.WritablePath
1225 apiXmlFile android.WritablePath
1226 lastReleasedApiXmlFile android.WritablePath
1227 dexApiFile android.WritablePath
1228 privateApiFile android.WritablePath
1229 privateDexApiFile android.WritablePath
1230 removedApiFile android.WritablePath
1231 removedDexApiFile android.WritablePath
1232 apiMappingFile android.WritablePath
1233 exactApiFile android.WritablePath
1234 proguardFile android.WritablePath
1235 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001236
1237 checkCurrentApiTimestamp android.WritablePath
1238 updateCurrentApiTimestamp android.WritablePath
1239 checkLastReleasedApiTimestamp android.WritablePath
1240
Pete Gillin581d6082018-10-22 15:55:04 +01001241 checkNullabilityWarningsTimestamp android.WritablePath
1242
Nan Zhang1598a9e2018-09-04 17:14:32 -07001243 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001244 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001245
1246 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001247
1248 jdiffDocZip android.WritablePath
1249 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001250}
1251
1252func DroidstubsFactory() android.Module {
1253 module := &Droidstubs{}
1254
1255 module.AddProperties(&module.properties,
1256 &module.Javadoc.properties)
1257
1258 InitDroiddocModule(module, android.HostAndDeviceSupported)
1259 return module
1260}
1261
1262func DroidstubsHostFactory() android.Module {
1263 module := &Droidstubs{}
1264
1265 module.AddProperties(&module.properties,
1266 &module.Javadoc.properties)
1267
1268 InitDroiddocModule(module, android.HostSupported)
1269 return module
1270}
1271
1272func (d *Droidstubs) ApiFilePath() android.Path {
1273 return d.apiFilePath
1274}
1275
1276func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1277 d.Javadoc.addDeps(ctx)
1278
1279 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1280 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1281 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1282 }
1283
1284 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1285 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1286 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1287 }
1288
1289 if String(d.properties.Previous_api) != "" {
1290 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1291 }
1292
1293 if len(d.properties.Merge_annotations_dirs) != 0 {
1294 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1295 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1296 }
1297 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001298
Pete Gillin77167902018-09-19 18:16:26 +01001299 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1300 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1301 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1302 }
1303 }
1304
Pete Gillin581d6082018-10-22 15:55:04 +01001305 if String(d.properties.Check_nullability_warnings) != "" {
1306 android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings)
1307 }
1308
Nan Zhang9c69a122018-08-22 10:22:08 -07001309 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1310 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1311 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1312 }
1313 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001314}
1315
1316func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1317 deps deps) (droiddocBuilderFlags, error) {
1318 var flags droiddocBuilderFlags
1319
1320 *implicits = append(*implicits, deps.bootClasspath...)
1321 *implicits = append(*implicits, deps.classpath...)
1322
1323 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1324 // since it doesn't support system modules yet.
1325 if len(deps.bootClasspath.Strings()) > 0 {
1326 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1327 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1328 }
1329 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1330
Sundong Ahn56dce442018-10-05 18:41:09 +09001331 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001332 return flags, nil
1333}
1334
1335func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1336 implicitOutputs *android.WritablePaths) string {
1337 var metalavaFlags string
1338 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1339 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1340 String(d.properties.Api_filename) != "" {
1341 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1342 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1343 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1344 d.apiFilePath = d.apiFile
1345 }
1346
1347 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1348 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1349 String(d.properties.Removed_api_filename) != "" {
1350 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1351 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1352 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1353 }
1354
1355 if String(d.properties.Private_api_filename) != "" {
1356 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1357 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1358 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1359 }
1360
1361 if String(d.properties.Dex_api_filename) != "" {
1362 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1363 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1364 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1365 }
1366
1367 if String(d.properties.Private_dex_api_filename) != "" {
1368 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1369 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1370 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1371 }
1372
1373 if String(d.properties.Removed_dex_api_filename) != "" {
1374 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1375 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1376 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1377 }
1378
1379 if String(d.properties.Exact_api_filename) != "" {
1380 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1381 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1382 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1383 }
1384
Nan Zhang9c69a122018-08-22 10:22:08 -07001385 if String(d.properties.Dex_mapping_filename) != "" {
1386 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1387 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1388 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1389 }
1390
Nan Zhang199645c2018-09-19 12:40:06 -07001391 if String(d.properties.Proguard_filename) != "" {
1392 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1393 metalavaFlags += " --proguard " + d.proguardFile.String()
1394 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1395 }
1396
Nan Zhang9c69a122018-08-22 10:22:08 -07001397 if Bool(d.properties.Write_sdk_values) {
1398 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1399 }
1400
Nan Zhang1598a9e2018-09-04 17:14:32 -07001401 if Bool(d.properties.Create_doc_stubs) {
1402 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1403 } else {
1404 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1405 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001406 return metalavaFlags
1407}
1408
1409func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1410 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001411 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001412 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001413 flags += " --include-annotations"
1414 validatingNullability := strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs")
1415 migratingNullability := String(d.properties.Previous_api) != ""
1416 if !(migratingNullability || validatingNullability) {
1417 ctx.PropertyErrorf("previous_api",
1418 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001419 }
Pete Gillina262c052018-09-14 14:25:48 +01001420 if migratingNullability {
1421 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1422 *implicits = append(*implicits, previousApi)
1423 flags += " --migrate-nullness " + previousApi.String()
1424 }
1425 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001426 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1427 *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile)
1428 flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String()
Pete Gillina262c052018-09-14 14:25:48 +01001429 }
Nan Zhanga40da042018-08-01 12:48:00 -07001430
1431 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1432 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1433
Nan Zhangf4936b02018-08-01 15:00:28 -07001434 flags += " --extract-annotations " + d.annotationsZip.String()
1435
Nan Zhang1598a9e2018-09-04 17:14:32 -07001436 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001437 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001438 "has to be non-empty if annotations was enabled!")
1439 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001440 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1441 if t, ok := m.(*ExportedDroiddocDir); ok {
1442 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001443 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001444 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001445 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001446 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1447 }
1448 })
Nan Zhanga40da042018-08-01 12:48:00 -07001449 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001450 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001451 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001452
1453 return flags
1454}
1455
1456func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1457 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1458 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001459 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1460 if t, ok := m.(*ExportedDroiddocDir); ok {
1461 *implicits = append(*implicits, t.deps...)
1462 flags += " --merge-inclusion-annotations " + t.dir.String()
1463 } else {
1464 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1465 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1466 }
1467 })
Nan Zhanga40da042018-08-01 12:48:00 -07001468
1469 return flags
1470}
1471
Nan Zhang9c69a122018-08-22 10:22:08 -07001472func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1473 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1474 var flags string
1475 if Bool(d.properties.Api_levels_annotations_enabled) {
1476 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1477 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1478
1479 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1480 ctx.PropertyErrorf("api_levels_annotations_dirs",
1481 "has to be non-empty if api levels annotations was enabled!")
1482 }
1483
1484 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1485 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1486 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1487
1488 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1489 if t, ok := m.(*ExportedDroiddocDir); ok {
1490 var androidJars android.Paths
1491 for _, dep := range t.deps {
1492 if strings.HasSuffix(dep.String(), "android.jar") {
1493 androidJars = append(androidJars, dep)
1494 }
1495 }
1496 *implicits = append(*implicits, androidJars...)
1497 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1498 } else {
1499 ctx.PropertyErrorf("api_levels_annotations_dirs",
1500 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1501 }
1502 })
1503
1504 }
1505
1506 return flags
1507}
1508
Nan Zhang71bbe632018-09-17 14:32:21 -07001509func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1510 implicitOutputs *android.WritablePaths) string {
1511 var flags string
1512 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1513 if d.apiFile.String() == "" {
1514 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1515 }
1516
1517 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1518 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1519
1520 flags = " --api-xml " + d.apiXmlFile.String()
1521
1522 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1523 ctx.PropertyErrorf("check_api.last_released.api_file",
1524 "has to be non-empty if jdiff was enabled!")
1525 }
1526 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1527 "check_api.last_released.api_file")
1528 *implicits = append(*implicits, lastReleasedApi)
1529
1530 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1531 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1532
1533 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1534 d.lastReleasedApiXmlFile.String()
1535 }
1536
1537 return flags
1538}
1539
Nan Zhang1598a9e2018-09-04 17:14:32 -07001540func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1541 implicitOutputs android.WritablePaths, javaVersion,
1542 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001543
Nan Zhang86d2d552018-08-09 15:33:27 -07001544 ctx.Build(pctx, android.BuildParams{
1545 Rule: metalava,
1546 Description: "Metalava",
1547 Output: d.Javadoc.stubsSrcJar,
1548 Inputs: d.Javadoc.srcFiles,
1549 Implicits: implicits,
1550 ImplicitOutputs: implicitOutputs,
1551 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001552 "outDir": android.PathForModuleOut(ctx, "out").String(),
1553 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1554 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1555 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001556 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001557 "bootclasspathArgs": bootclasspathArgs,
1558 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001559 "sourcepathArgs": sourcepathArgs,
1560 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001561 },
1562 })
1563}
1564
Nan Zhang1598a9e2018-09-04 17:14:32 -07001565func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1566 apiFile, removedApiFile android.Path, implicits android.Paths,
1567 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001568 output android.WritablePath) {
1569 ctx.Build(pctx, android.BuildParams{
1570 Rule: metalavaApiCheck,
1571 Description: "Metalava Check API",
1572 Output: output,
1573 Inputs: d.Javadoc.srcFiles,
1574 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1575 implicits...),
1576 Args: map[string]string{
1577 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1578 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1579 "javaVersion": javaVersion,
1580 "bootclasspathArgs": bootclasspathArgs,
1581 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001582 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001583 "opts": opts,
1584 "msg": msg,
1585 },
1586 })
1587}
1588
Nan Zhang71bbe632018-09-17 14:32:21 -07001589func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1590 implicitOutputs android.WritablePaths,
1591 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1592 ctx.Build(pctx, android.BuildParams{
1593 Rule: javadoc,
1594 Description: "Jdiff",
1595 Output: d.jdiffStubsSrcJar,
1596 Inputs: d.Javadoc.srcFiles,
1597 Implicits: implicits,
1598 ImplicitOutputs: implicitOutputs,
1599 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001600 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1601 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1602 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001603 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1604 "opts": opts,
1605 "bootclasspathArgs": bootclasspathArgs,
1606 "classpathArgs": classpathArgs,
1607 "sourcepathArgs": sourcepathArgs,
1608 "docZip": d.jdiffDocZip.String(),
1609 },
1610 })
1611}
1612
Nan Zhang1598a9e2018-09-04 17:14:32 -07001613func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001614 deps := d.Javadoc.collectDeps(ctx)
1615
1616 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001617
Nan Zhanga40da042018-08-01 12:48:00 -07001618 var implicits android.Paths
1619 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001620 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001621
1622 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001623 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001624 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1625 }
1626
1627 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001628 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001629 jdiffImplicits := implicits
1630
Nan Zhanga40da042018-08-01 12:48:00 -07001631 if err != nil {
1632 return
1633 }
1634
Nan Zhang1598a9e2018-09-04 17:14:32 -07001635 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1636 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001637 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001638 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001639 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1640
Nan Zhang1598a9e2018-09-04 17:14:32 -07001641 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1642 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1643 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1644 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1645 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001646 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001647 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1648 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001649 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001650 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001651
Nan Zhang1598a9e2018-09-04 17:14:32 -07001652 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1653 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001654 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1655 "check_api.current.api_file")
1656 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1657 "check_api.current_removed_api_file")
1658
Nan Zhang2760dfc2018-08-24 17:32:54 +00001659 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001660 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1661 " --check-compatibility:removed:current " + removedApiFile.String() +
1662 flags.metalavaInclusionAnnotationsFlags
Nan Zhang2760dfc2018-08-24 17:32:54 +00001663
Nan Zhang1598a9e2018-09-04 17:14:32 -07001664 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1665 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1666 fmt.Sprintf(`\n******************************\n`+
1667 `You have tried to change the API from what has been previously approved.\n\n`+
1668 `To make these errors go away, you have two choices:\n`+
1669 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1670 ` errors above.\n\n`+
1671 ` 2. You can update current.txt by executing the following command:\n`+
1672 ` make %s-update-current-api\n\n`+
1673 ` To submit the revised current.txt to the main Android repository,\n`+
1674 ` you will need approval.\n`+
1675 `******************************\n`, ctx.ModuleName()),
1676 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001677
1678 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001679 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1680 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001681 }
Nan Zhanga40da042018-08-01 12:48:00 -07001682
Nan Zhang1598a9e2018-09-04 17:14:32 -07001683 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1684 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001685 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1686 "check_api.last_released.api_file")
1687 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1688 "check_api.last_released.removed_api_file")
1689
Nan Zhang2760dfc2018-08-24 17:32:54 +00001690 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001691 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1692 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
1693 removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001694
Nan Zhang1598a9e2018-09-04 17:14:32 -07001695 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1696 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1697 `\n******************************\n`+
1698 `You have tried to change the API from what has been previously released in\n`+
1699 `an SDK. Please fix the errors listed above.\n`+
1700 `******************************\n`,
1701 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001702 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001703
Pete Gillin581d6082018-10-22 15:55:04 +01001704 if String(d.properties.Check_nullability_warnings) != "" {
1705 if d.nullabilityWarningsFile == nil {
1706 ctx.PropertyErrorf("check_nullability_warnings",
1707 "Cannot specify check_nullability_warnings unless validating nullability")
1708 }
1709 checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings),
1710 "check_nullability_warnings")
1711 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
1712 msg := fmt.Sprintf(`\n******************************\n`+
1713 `The warnings encountered during nullability annotation validation did\n`+
1714 `not match the checked in file of expected warnings. The diffs are shown\n`+
1715 `above. You have two options:\n`+
1716 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1717 ` 2. Update the file of expected warnings by running:\n`+
1718 ` cp %s %s\n`+
1719 ` and submitting the updated file as part of your change.`,
1720 d.nullabilityWarningsFile, checkNullabilityWarnings)
1721 ctx.Build(pctx, android.BuildParams{
1722 Rule: nullabilityWarningsCheck,
1723 Description: "Nullability Warnings Check",
1724 Output: d.checkNullabilityWarningsTimestamp,
1725 Implicits: android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile},
1726 Args: map[string]string{
1727 "expected": checkNullabilityWarnings.String(),
1728 "actual": d.nullabilityWarningsFile.String(),
1729 "msg": msg,
1730 },
1731 })
1732 }
1733
Nan Zhang71bbe632018-09-17 14:32:21 -07001734 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1735
Nan Zhang86b06202018-09-21 17:09:21 -07001736 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1737 // since there's cron job downstream that fetch this .zip file periodically.
1738 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001739 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1740 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1741
1742 var jdiffImplicitOutputs android.WritablePaths
1743 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1744
1745 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1746 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1747
1748 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1749 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1750 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1751 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1752 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1753 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1754
1755 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1756 flags.sourcepathArgs, opts)
1757 }
Nan Zhang581fd212018-01-10 16:06:12 -08001758}
Dan Willemsencc090972018-02-26 14:33:31 -08001759
Nan Zhanga40da042018-08-01 12:48:00 -07001760//
Nan Zhangf4936b02018-08-01 15:00:28 -07001761// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001762//
Dan Willemsencc090972018-02-26 14:33:31 -08001763var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001764var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001765var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001766var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001767
Nan Zhangf4936b02018-08-01 15:00:28 -07001768type ExportedDroiddocDirProperties struct {
1769 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001770 Path *string
1771}
1772
Nan Zhangf4936b02018-08-01 15:00:28 -07001773type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001774 android.ModuleBase
1775
Nan Zhangf4936b02018-08-01 15:00:28 -07001776 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001777
1778 deps android.Paths
1779 dir android.Path
1780}
1781
Nan Zhangf4936b02018-08-01 15:00:28 -07001782func ExportedDroiddocDirFactory() android.Module {
1783 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001784 module.AddProperties(&module.properties)
1785 android.InitAndroidModule(module)
1786 return module
1787}
1788
Nan Zhangf4936b02018-08-01 15:00:28 -07001789func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001790
Nan Zhangf4936b02018-08-01 15:00:28 -07001791func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001792 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1793 d.dir = path
1794 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1795}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001796
1797//
1798// Defaults
1799//
1800type DocDefaults struct {
1801 android.ModuleBase
1802 android.DefaultsModuleBase
1803}
1804
1805func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1806}
1807
1808func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1809}
1810
1811func DocDefaultsFactory() android.Module {
1812 module := &DocDefaults{}
1813
1814 module.AddProperties(
1815 &JavadocProperties{},
1816 &DroiddocProperties{},
1817 )
1818
1819 android.InitDefaultsModule(module)
1820
1821 return module
1822}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001823
1824func StubsDefaultsFactory() android.Module {
1825 module := &DocDefaults{}
1826
1827 module.AddProperties(
1828 &JavadocProperties{},
1829 &DroidstubsProperties{},
1830 )
1831
1832 android.InitDefaultsModule(module)
1833
1834 return module
1835}