blob: 23614ec67b1657d305d5420eb89e8a9768fe96b1 [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
109 dokka = pctx.AndroidStaticRule("dokka",
110 blueprint.RuleParams{
111 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
112 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
113 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
114 `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` +
115 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
116 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
117 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
118 CommandDeps: []string{
119 "${config.ZipSyncCmd}",
120 "${config.DokkaJar}",
121 "${config.MetalavaJar}",
122 "${config.SoongZipCmd}",
123 },
124 Restat: true,
125 },
126 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800127)
128
129func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800130 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700131 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132
Nan Zhang581fd212018-01-10 16:06:12 -0800133 android.RegisterModuleType("droiddoc", DroiddocFactory)
134 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700135 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800136 android.RegisterModuleType("javadoc", JavadocFactory)
137 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700138
139 android.RegisterModuleType("droidstubs", DroidstubsFactory)
140 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800141}
142
Colin Crossa1ce2a02018-06-20 15:19:39 -0700143var (
144 srcsLibTag = dependencyTag{name: "sources from javalib"}
145)
146
Nan Zhang581fd212018-01-10 16:06:12 -0800147type JavadocProperties struct {
148 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
149 // or .aidl files.
150 Srcs []string `android:"arch_variant"`
151
152 // list of directories rooted at the Android.bp file that will
153 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800154 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // list of source files that should not be used to build the Java module.
157 // This is most useful in the arch/multilib variants to remove non-common files
158 // filegroup or genrule can be included within this property.
159 Exclude_srcs []string `android:"arch_variant"`
160
Nan Zhangb2b33de2018-02-23 11:18:47 -0800161 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800162 Libs []string `android:"arch_variant"`
163
Nan Zhang5994b622018-09-21 16:39:51 -0700164 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
165 // ext, and framework for device targets)
166 No_standard_libs *bool
167
Nan Zhange66c7272018-03-06 12:59:27 -0800168 // don't build against the framework libraries (legacy-test, core-junit,
169 // ext, and framework for device targets)
170 No_framework_libs *bool
171
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 // the java library (in classpath) for documentation that provides java srcs and srcjars.
173 Srcs_lib *string
174
175 // the base dirs under srcs_lib will be scanned for java srcs.
176 Srcs_lib_whitelist_dirs []string
177
178 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
179 Srcs_lib_whitelist_pkgs []string
180
Nan Zhang581fd212018-01-10 16:06:12 -0800181 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800182 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800183
184 // if not blank, set to the version of the sdk to compile against
185 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900186
187 Aidl struct {
188 // Top level directories to pass to aidl tool
189 Include_dirs []string
190
191 // Directories rooted at the Android.bp file to pass to aidl tool
192 Local_include_dirs []string
193 }
Nan Zhang357466b2018-04-17 17:38:36 -0700194
195 // If not blank, set the java version passed to javadoc as -source
196 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700197
198 // local files that are used within user customized droiddoc options.
199 Arg_files []string
200
201 // user customized droiddoc args.
202 // Available variables for substitution:
203 //
204 // $(location <label>): the path to the arg_files with name <label>
205 Args *string
206
207 // names of the output files used in args that will be generated
208 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800209}
210
Nan Zhang61819ce2018-05-04 18:49:16 -0700211type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900212 // path to the API txt file that the new API extracted from source code is checked
213 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700214 Api_file *string
215
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900216 // path to the API txt file that the new @removed API extractd from source code is
217 // checked against. The path can be local to the module or from other module (via
218 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700219 Removed_api_file *string
220
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900221 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700222 Args *string
223}
224
Nan Zhang581fd212018-01-10 16:06:12 -0800225type DroiddocProperties struct {
226 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800227 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800228
Nan Zhanga40da042018-08-01 12:48:00 -0700229 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800230 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800231
232 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800233 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800234
235 // proofread file contains all of the text content of the javadocs concatenated into one file,
236 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800237 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800238
239 // a todo file lists the program elements that are missing documentation.
240 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800241 Todo_file *string
242
243 // directory under current module source that provide additional resources (images).
244 Resourcesdir *string
245
246 // resources output directory under out/soong/.intermediates.
247 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800248
Nan Zhange2ba5d42018-07-11 15:16:55 -0700249 // if set to true, collect the values used by the Dev tools and
250 // write them in files packaged with the SDK. Defaults to false.
251 Write_sdk_values *bool
252
253 // index.html under current module will be copied to docs out dir, if not null.
254 Static_doc_index_redirect *string
255
256 // source.properties under current module will be copied to docs out dir, if not null.
257 Static_doc_properties *string
258
Nan Zhang581fd212018-01-10 16:06:12 -0800259 // a list of files under current module source dir which contains known tags in Java sources.
260 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800261 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700262
263 // the tag name used to distinguish if the API files belong to public/system/test.
264 Api_tag_name *string
265
266 // the generated public API filename by Doclava.
267 Api_filename *string
268
David Brazdilfbe4cc32018-05-31 13:56:46 +0100269 // the generated public Dex API filename by Doclava.
270 Dex_api_filename *string
271
Nan Zhang28c68b92018-03-13 16:17:01 -0700272 // the generated private API filename by Doclava.
273 Private_api_filename *string
274
275 // the generated private Dex API filename by Doclava.
276 Private_dex_api_filename *string
277
278 // the generated removed API filename by Doclava.
279 Removed_api_filename *string
280
David Brazdilaac0c3c2018-04-24 16:23:29 +0100281 // the generated removed Dex API filename by Doclava.
282 Removed_dex_api_filename *string
283
Mathew Inwood76c3de12018-06-22 15:28:11 +0100284 // mapping of dex signatures to source file and line number. This is a temporary property and
285 // will be deleted; you probably shouldn't be using it.
286 Dex_mapping_filename *string
287
Nan Zhang28c68b92018-03-13 16:17:01 -0700288 // the generated exact API filename by Doclava.
289 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700290
Nan Zhang66dc2362018-08-14 20:41:04 -0700291 // the generated proguard filename by Doclava.
292 Proguard_filename *string
293
Nan Zhang853f4202018-04-12 16:55:56 -0700294 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
295 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700296
297 Check_api struct {
298 Last_released ApiToCheck
299
300 Current ApiToCheck
301 }
Nan Zhang79614d12018-04-19 18:03:39 -0700302
Nan Zhang1598a9e2018-09-04 17:14:32 -0700303 // if set to true, generate docs through Dokka instead of Doclava.
304 Dokka_enabled *bool
305}
306
307type DroidstubsProperties struct {
308 // the tag name used to distinguish if the API files belong to public/system/test.
309 Api_tag_name *string
310
Nan Zhang199645c2018-09-19 12:40:06 -0700311 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700312 Api_filename *string
313
Nan Zhang199645c2018-09-19 12:40:06 -0700314 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700315 Dex_api_filename *string
316
Nan Zhang199645c2018-09-19 12:40:06 -0700317 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700318 Private_api_filename *string
319
Nan Zhang199645c2018-09-19 12:40:06 -0700320 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700321 Private_dex_api_filename *string
322
Nan Zhang199645c2018-09-19 12:40:06 -0700323 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700324 Removed_api_filename *string
325
Nan Zhang199645c2018-09-19 12:40:06 -0700326 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700327 Removed_dex_api_filename *string
328
Nan Zhang9c69a122018-08-22 10:22:08 -0700329 // mapping of dex signatures to source file and line number. This is a temporary property and
330 // will be deleted; you probably shouldn't be using it.
331 Dex_mapping_filename *string
332
Nan Zhang199645c2018-09-19 12:40:06 -0700333 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Exact_api_filename *string
335
Nan Zhang199645c2018-09-19 12:40:06 -0700336 // the generated proguard filename by Metalava.
337 Proguard_filename *string
338
Nan Zhang1598a9e2018-09-04 17:14:32 -0700339 Check_api struct {
340 Last_released ApiToCheck
341
342 Current ApiToCheck
343 }
Nan Zhang79614d12018-04-19 18:03:39 -0700344
345 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700346 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700347
348 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700350
Pete Gillin77167902018-09-19 18:16:26 +0100351 // 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 -0700352 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700353
Pete Gillin77167902018-09-19 18:16:26 +0100354 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
355 Merge_inclusion_annotations_dirs []string
356
Nan Zhang1598a9e2018-09-04 17:14:32 -0700357 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
358 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700359
360 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
361 Api_levels_annotations_enabled *bool
362
363 // the dirs which Metalava extracts API levels annotations from.
364 Api_levels_annotations_dirs []string
365
366 // if set to true, collect the values used by the Dev tools and
367 // write them in files packaged with the SDK. Defaults to false.
368 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700369
370 // If set to true, .xml based public API file will be also generated, and
371 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
372 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800373}
374
Nan Zhanga40da042018-08-01 12:48:00 -0700375//
376// Common flags passed down to build rule
377//
378type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700379 bootClasspathArgs string
380 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700381 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700382 dokkaClasspathArgs string
383 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700384
Nan Zhanga40da042018-08-01 12:48:00 -0700385 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700386 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700387 postDoclavaCmds string
388
Nan Zhang9c69a122018-08-22 10:22:08 -0700389 metalavaStubsFlags string
390 metalavaAnnotationsFlags string
Neil Fullerb2f14ec2018-10-21 22:13:19 +0100391 metalavaInclusionAnnotationsFlags string
Nan Zhang9c69a122018-08-22 10:22:08 -0700392 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700393
Nan Zhang71bbe632018-09-17 14:32:21 -0700394 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700395}
396
397func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
398 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
399 android.InitDefaultableModule(module)
400}
401
Nan Zhang1598a9e2018-09-04 17:14:32 -0700402func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
403 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
404 return true
405 } else if String(apiToCheck.Api_file) != "" {
406 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
407 } else if String(apiToCheck.Removed_api_file) != "" {
408 panic("for " + apiVersionTag + " api_file has to be non-empty!")
409 }
410
411 return false
412}
413
414type ApiFilePath interface {
415 ApiFilePath() android.Path
416}
417
418func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
419 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
420 ctx.Build(pctx, android.BuildParams{
421 Rule: updateApi,
422 Description: "Update API",
423 Output: output,
424 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
425 destApiFile, destRemovedApiFile),
426 Args: map[string]string{
427 "destApiFile": destApiFile.String(),
428 "srcApiFile": srcApiFile.String(),
429 "destRemovedApiFile": destRemovedApiFile.String(),
430 "srcRemovedApiFile": srcRemovedApiFile.String(),
431 },
432 })
433}
434
Nan Zhanga40da042018-08-01 12:48:00 -0700435//
436// Javadoc
437//
Nan Zhang581fd212018-01-10 16:06:12 -0800438type Javadoc struct {
439 android.ModuleBase
440 android.DefaultableModuleBase
441
442 properties JavadocProperties
443
444 srcJars android.Paths
445 srcFiles android.Paths
446 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700447 argFiles android.Paths
448
449 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800450
Nan Zhangccff0f72018-03-08 17:26:16 -0800451 docZip android.WritablePath
452 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800453}
454
Nan Zhangb2b33de2018-02-23 11:18:47 -0800455func (j *Javadoc) Srcs() android.Paths {
456 return android.Paths{j.stubsSrcJar}
457}
458
Nan Zhang581fd212018-01-10 16:06:12 -0800459func JavadocFactory() android.Module {
460 module := &Javadoc{}
461
462 module.AddProperties(&module.properties)
463
464 InitDroiddocModule(module, android.HostAndDeviceSupported)
465 return module
466}
467
468func JavadocHostFactory() android.Module {
469 module := &Javadoc{}
470
471 module.AddProperties(&module.properties)
472
473 InitDroiddocModule(module, android.HostSupported)
474 return module
475}
476
Nan Zhanga40da042018-08-01 12:48:00 -0700477var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800478
Colin Cross83bb3162018-06-25 15:48:06 -0700479func (j *Javadoc) sdkVersion() string {
480 return String(j.properties.Sdk_version)
481}
482
483func (j *Javadoc) minSdkVersion() string {
484 return j.sdkVersion()
485}
486
Nan Zhang581fd212018-01-10 16:06:12 -0800487func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
488 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700489 if !Bool(j.properties.No_standard_libs) {
490 sdkDep := decodeSdkDep(ctx, sdkContext(j))
491 if sdkDep.useDefaultLibs {
492 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
493 if ctx.Config().TargetOpenJDK9() {
494 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
495 }
496 if !Bool(j.properties.No_framework_libs) {
497 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
498 }
499 } else if sdkDep.useModule {
500 if ctx.Config().TargetOpenJDK9() {
501 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
502 }
503 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700504 }
Nan Zhang581fd212018-01-10 16:06:12 -0800505 }
506 }
507
Colin Cross42d48b72018-08-29 14:10:52 -0700508 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700509 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700510 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700511 }
Nan Zhang581fd212018-01-10 16:06:12 -0800512
513 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
514
515 // exclude_srcs may contain filegroup or genrule.
516 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700517
518 // arg_files may contains filegroup or genrule.
519 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800520}
521
Nan Zhangb2b33de2018-02-23 11:18:47 -0800522func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
523 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
524 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900525 // convert foo.bar.baz to foo/bar/baz
526 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
527 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800528 if _, found := whitelistPathPrefixes[prefix]; !found {
529 whitelistPathPrefixes[prefix] = true
530 }
531 }
532 }
533}
534
Nan Zhanga40da042018-08-01 12:48:00 -0700535func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
536 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900537
538 // aidl flags.
539 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
540 if len(aidlFlags) > 0 {
541 // optimization.
542 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
543 flags.aidlFlags = "$aidlFlags"
544 }
545
546 return flags
547}
548
549func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
550 aidlIncludeDirs android.Paths) []string {
551
552 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
553 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
554
555 var flags []string
556 if aidlPreprocess.Valid() {
557 flags = append(flags, "-p"+aidlPreprocess.String())
558 } else {
559 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
560 }
561
562 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
563 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
564 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
565 flags = append(flags, "-I"+src.String())
566 }
567
568 return flags
569}
570
571func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700572 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900573
574 outSrcFiles := make(android.Paths, 0, len(srcFiles))
575
576 for _, srcFile := range srcFiles {
577 switch srcFile.Ext() {
578 case ".aidl":
579 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
580 outSrcFiles = append(outSrcFiles, javaFile)
581 default:
582 outSrcFiles = append(outSrcFiles, srcFile)
583 }
584 }
585
586 return outSrcFiles
587}
588
Nan Zhang581fd212018-01-10 16:06:12 -0800589func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
590 var deps deps
591
Colin Cross83bb3162018-06-25 15:48:06 -0700592 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800593 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700594 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800595 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700596 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800597 }
598
599 ctx.VisitDirectDeps(func(module android.Module) {
600 otherName := ctx.OtherModuleName(module)
601 tag := ctx.OtherModuleDependencyTag(module)
602
Colin Cross2d24c1b2018-05-23 10:59:18 -0700603 switch tag {
604 case bootClasspathTag:
605 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800606 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700607 } else {
608 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
609 }
610 case libTag:
611 switch dep := module.(type) {
612 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800613 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700614 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700615 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900616 linkType := javaSdk
617 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
618 linkType = javaSystem
619 } else if sdkVersion == "" {
620 linkType = javaPlatform
621 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900622 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700623 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800624 checkProducesJars(ctx, dep)
625 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800626 default:
627 ctx.ModuleErrorf("depends on non-java module %q", otherName)
628 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700629 case srcsLibTag:
630 switch dep := module.(type) {
631 case Dependency:
632 srcs := dep.(SrcDependency).CompiledSrcs()
633 whitelistPathPrefixes := make(map[string]bool)
634 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
635 for _, src := range srcs {
636 if _, ok := src.(android.WritablePath); ok { // generated sources
637 deps.srcs = append(deps.srcs, src)
638 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700639 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700640 if strings.HasPrefix(src.Rel(), k) {
641 deps.srcs = append(deps.srcs, src)
642 break
643 }
644 }
645 }
646 }
647 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
648 default:
649 ctx.ModuleErrorf("depends on non-java module %q", otherName)
650 }
Nan Zhang357466b2018-04-17 17:38:36 -0700651 case systemModulesTag:
652 if deps.systemModules != nil {
653 panic("Found two system module dependencies")
654 }
655 sm := module.(*SystemModules)
656 if sm.outputFile == nil {
657 panic("Missing directory for system module dependency")
658 }
659 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800660 }
661 })
662 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
663 // may contain filegroup or genrule.
664 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700665 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900666 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800667
668 // srcs may depend on some genrule output.
669 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800670 j.srcJars = append(j.srcJars, deps.srcJars...)
671
Nan Zhang581fd212018-01-10 16:06:12 -0800672 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800673 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800674
675 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800676 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800677
Nan Zhang9c69a122018-08-22 10:22:08 -0700678 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800679 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
680 }
681 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800682
Nan Zhang1598a9e2018-09-04 17:14:32 -0700683 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
684 argFilesMap := map[string]android.Path{}
685
686 for _, f := range j.argFiles {
687 if _, exists := argFilesMap[f.Rel()]; !exists {
688 argFilesMap[f.Rel()] = f
689 } else {
690 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
691 f, argFilesMap[f.Rel()], f.Rel())
692 }
693 }
694
695 var err error
696 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
697 if strings.HasPrefix(name, "location ") {
698 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
699 if f, ok := argFilesMap[label]; ok {
700 return f.String(), nil
701 } else {
702 return "", fmt.Errorf("unknown location label %q", label)
703 }
704 } else if name == "genDir" {
705 return android.PathForModuleGen(ctx).String(), nil
706 }
707 return "", fmt.Errorf("unknown variable '$(%s)'", name)
708 })
709
710 if err != nil {
711 ctx.PropertyErrorf("args", "%s", err.Error())
712 }
713
Nan Zhang581fd212018-01-10 16:06:12 -0800714 return deps
715}
716
717func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
718 j.addDeps(ctx)
719}
720
721func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
722 deps := j.collectDeps(ctx)
723
724 var implicits android.Paths
725 implicits = append(implicits, deps.bootClasspath...)
726 implicits = append(implicits, deps.classpath...)
727
Nan Zhang1598a9e2018-09-04 17:14:32 -0700728 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700729
Colin Cross83bb3162018-06-25 15:48:06 -0700730 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700731 if len(deps.bootClasspath) > 0 {
732 var systemModules classpath
733 if deps.systemModules != nil {
734 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800735 }
Colin Cross997262f2018-06-19 22:49:39 -0700736 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
737 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800738 }
739 if len(deps.classpath.Strings()) > 0 {
740 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
741 }
742
743 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700744 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800745
Nan Zhangaf322cc2018-06-19 15:15:38 -0700746 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800747
Nan Zhang1598a9e2018-09-04 17:14:32 -0700748 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
749
Nan Zhang581fd212018-01-10 16:06:12 -0800750 ctx.Build(pctx, android.BuildParams{
751 Rule: javadoc,
752 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800753 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800754 ImplicitOutput: j.docZip,
755 Inputs: j.srcFiles,
756 Implicits: implicits,
757 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700758 "outDir": android.PathForModuleOut(ctx, "out").String(),
759 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
760 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800761 "srcJars": strings.Join(j.srcJars.Strings(), " "),
762 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700763 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800764 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700765 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800766 "docZip": j.docZip.String(),
767 },
768 })
769}
770
Nan Zhanga40da042018-08-01 12:48:00 -0700771//
772// Droiddoc
773//
774type Droiddoc struct {
775 Javadoc
776
777 properties DroiddocProperties
778 apiFile android.WritablePath
779 dexApiFile android.WritablePath
780 privateApiFile android.WritablePath
781 privateDexApiFile android.WritablePath
782 removedApiFile android.WritablePath
783 removedDexApiFile android.WritablePath
784 exactApiFile android.WritablePath
785 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700786 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700787
788 checkCurrentApiTimestamp android.WritablePath
789 updateCurrentApiTimestamp android.WritablePath
790 checkLastReleasedApiTimestamp android.WritablePath
791
Nan Zhanga40da042018-08-01 12:48:00 -0700792 apiFilePath android.Path
793}
794
Nan Zhanga40da042018-08-01 12:48:00 -0700795func DroiddocFactory() android.Module {
796 module := &Droiddoc{}
797
798 module.AddProperties(&module.properties,
799 &module.Javadoc.properties)
800
801 InitDroiddocModule(module, android.HostAndDeviceSupported)
802 return module
803}
804
805func DroiddocHostFactory() android.Module {
806 module := &Droiddoc{}
807
808 module.AddProperties(&module.properties,
809 &module.Javadoc.properties)
810
811 InitDroiddocModule(module, android.HostSupported)
812 return module
813}
814
815func (d *Droiddoc) ApiFilePath() android.Path {
816 return d.apiFilePath
817}
818
Nan Zhang581fd212018-01-10 16:06:12 -0800819func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
820 d.Javadoc.addDeps(ctx)
821
Nan Zhang79614d12018-04-19 18:03:39 -0700822 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800823 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
824 }
825
Nan Zhang581fd212018-01-10 16:06:12 -0800826 // knowntags may contain filegroup or genrule.
827 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700828
Nan Zhange2ba5d42018-07-11 15:16:55 -0700829 if String(d.properties.Static_doc_index_redirect) != "" {
830 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
831 }
832
833 if String(d.properties.Static_doc_properties) != "" {
834 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
835 }
836
Nan Zhang1598a9e2018-09-04 17:14:32 -0700837 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700838 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
839 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
840 }
841
Nan Zhang1598a9e2018-09-04 17:14:32 -0700842 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700843 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
844 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
845 }
Nan Zhang581fd212018-01-10 16:06:12 -0800846}
847
Nan Zhang66dc2362018-08-14 20:41:04 -0700848func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
849 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700850 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800851
Nan Zhanga40da042018-08-01 12:48:00 -0700852 *implicits = append(*implicits, deps.bootClasspath...)
853 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800854
Nan Zhangc94f9d82018-06-26 10:02:26 -0700855 if len(deps.bootClasspath.Strings()) > 0 {
856 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700857 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700858 }
Nan Zhanga40da042018-08-01 12:48:00 -0700859 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700860 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700861 dokkaClasspath := classpath{}
862 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
863 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
864 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700865
Nan Zhang9c69a122018-08-22 10:22:08 -0700866 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
867 // based stubs generation.
868 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
869 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
870 // the correct package name base path.
871 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
872 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
873 } else {
874 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
875 }
Nan Zhang581fd212018-01-10 16:06:12 -0800876
Nan Zhanga40da042018-08-01 12:48:00 -0700877 return flags, nil
878}
Nan Zhang581fd212018-01-10 16:06:12 -0800879
Nan Zhanga40da042018-08-01 12:48:00 -0700880func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700881 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800882
Nan Zhanga40da042018-08-01 12:48:00 -0700883 *implicits = append(*implicits, jsilver)
884 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700885
Nan Zhang46130972018-06-04 11:28:01 -0700886 var date string
887 if runtime.GOOS == "darwin" {
888 date = `date -r`
889 } else {
890 date = `date -d`
891 }
892
Nan Zhang443fa522018-08-20 20:58:28 -0700893 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
894 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
895 // 1.9 language features.
896 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700897 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800898 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700899 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700900
Nan Zhanga40da042018-08-01 12:48:00 -0700901 if String(d.properties.Custom_template) == "" {
902 // TODO: This is almost always droiddoc-templates-sdk
903 ctx.PropertyErrorf("custom_template", "must specify a template")
904 }
905
906 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700907 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700908 *implicits = append(*implicits, t.deps...)
909 args = args + " -templatedir " + t.dir.String()
910 } else {
911 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
912 }
913 })
914
915 if len(d.properties.Html_dirs) > 0 {
916 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
917 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
918 args = args + " -htmldir " + htmlDir.String()
919 }
920
921 if len(d.properties.Html_dirs) > 1 {
922 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
923 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
924 args = args + " -htmldir2 " + htmlDir2.String()
925 }
926
927 if len(d.properties.Html_dirs) > 2 {
928 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
929 }
930
931 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
932 *implicits = append(*implicits, knownTags...)
933
934 for _, kt := range knownTags {
935 args = args + " -knowntags " + kt.String()
936 }
937
938 for _, hdf := range d.properties.Hdf {
939 args = args + " -hdf " + hdf
940 }
941
942 if String(d.properties.Proofread_file) != "" {
943 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
944 args = args + " -proofread " + proofreadFile.String()
945 }
946
947 if String(d.properties.Todo_file) != "" {
948 // tricky part:
949 // we should not compute full path for todo_file through PathForModuleOut().
950 // the non-standard doclet will get the full path relative to "-o".
951 args = args + " -todo " + String(d.properties.Todo_file)
952 }
953
954 if String(d.properties.Resourcesdir) != "" {
955 // TODO: should we add files under resourcesDir to the implicits? It seems that
956 // resourcesDir is one sub dir of htmlDir
957 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
958 args = args + " -resourcesdir " + resourcesDir.String()
959 }
960
961 if String(d.properties.Resourcesoutdir) != "" {
962 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
963 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
964 }
965 return args
966}
967
Nan Zhang1598a9e2018-09-04 17:14:32 -0700968func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
969 implicitOutputs *android.WritablePaths) string {
970 var doclavaFlags string
971 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
972 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
973 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700974 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
975 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700976 *implicitOutputs = append(*implicitOutputs, d.apiFile)
977 d.apiFilePath = d.apiFile
978 }
979
Nan Zhang1598a9e2018-09-04 17:14:32 -0700980 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
981 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
982 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700983 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
984 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700985 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
986 }
987
988 if String(d.properties.Private_api_filename) != "" {
989 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
990 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700991 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
992 }
993
994 if String(d.properties.Dex_api_filename) != "" {
995 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
996 doclavaFlags += " -dexApi " + d.dexApiFile.String()
997 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
998 }
999
1000 if String(d.properties.Private_dex_api_filename) != "" {
1001 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1002 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001003 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1004 }
1005
1006 if String(d.properties.Removed_dex_api_filename) != "" {
1007 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1008 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001009 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1010 }
1011
1012 if String(d.properties.Exact_api_filename) != "" {
1013 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1014 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001015 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1016 }
1017
1018 if String(d.properties.Dex_mapping_filename) != "" {
1019 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1020 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001021 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1022 }
1023
Nan Zhang66dc2362018-08-14 20:41:04 -07001024 if String(d.properties.Proguard_filename) != "" {
1025 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1026 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001027 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1028 }
1029
Nan Zhanga40da042018-08-01 12:48:00 -07001030 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001031 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001032 }
1033
1034 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001035 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001036 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001037
1038 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001039}
1040
1041func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1042 var cmds string
1043 if String(d.properties.Static_doc_index_redirect) != "" {
1044 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1045 "static_doc_index_redirect")
1046 *implicits = append(*implicits, static_doc_index_redirect)
1047 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001048 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001049 }
1050
1051 if String(d.properties.Static_doc_properties) != "" {
1052 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1053 "static_doc_properties")
1054 *implicits = append(*implicits, static_doc_properties)
1055 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001056 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001057 }
1058 return cmds
1059}
1060
Nan Zhang1598a9e2018-09-04 17:14:32 -07001061func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1062 implicitOutputs android.WritablePaths,
1063 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1064 ctx.Build(pctx, android.BuildParams{
1065 Rule: javadoc,
1066 Description: "Doclava",
1067 Output: d.Javadoc.stubsSrcJar,
1068 Inputs: d.Javadoc.srcFiles,
1069 Implicits: implicits,
1070 ImplicitOutputs: implicitOutputs,
1071 Args: map[string]string{
1072 "outDir": android.PathForModuleOut(ctx, "out").String(),
1073 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1074 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1075 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1076 "opts": opts,
1077 "bootclasspathArgs": bootclasspathArgs,
1078 "classpathArgs": classpathArgs,
1079 "sourcepathArgs": sourcepathArgs,
1080 "docZip": d.Javadoc.docZip.String(),
1081 "postDoclavaCmds": postDoclavaCmds,
1082 },
1083 })
1084}
1085
1086func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1087 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1088 ctx.Build(pctx, android.BuildParams{
1089 Rule: apiCheck,
1090 Description: "Doclava Check API",
1091 Output: output,
1092 Inputs: nil,
1093 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1094 checkApiClasspath...),
1095 Args: map[string]string{
1096 "msg": msg,
1097 "classpath": checkApiClasspath.FormJavaClassPath(""),
1098 "opts": opts,
1099 "apiFile": apiFile.String(),
1100 "apiFileToCheck": d.apiFile.String(),
1101 "removedApiFile": removedApiFile.String(),
1102 "removedApiFileToCheck": d.removedApiFile.String(),
1103 },
1104 })
1105}
1106
1107func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1108 classpathArgs, opts string) {
1109 ctx.Build(pctx, android.BuildParams{
1110 Rule: dokka,
1111 Description: "Dokka",
1112 Output: d.Javadoc.stubsSrcJar,
1113 Inputs: d.Javadoc.srcFiles,
1114 Implicits: implicits,
1115 Args: map[string]string{
1116 "outDir": android.PathForModuleOut(ctx, "out").String(),
1117 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1118 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1119 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1120 "classpathArgs": classpathArgs,
1121 "opts": opts,
1122 "docZip": d.Javadoc.docZip.String(),
1123 },
1124 })
1125}
1126
1127func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1128 deps := d.Javadoc.collectDeps(ctx)
1129
1130 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1131 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1132 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1133 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1134
1135 var implicits android.Paths
1136 implicits = append(implicits, d.Javadoc.srcJars...)
1137 implicits = append(implicits, d.Javadoc.argFiles...)
1138
1139 var implicitOutputs android.WritablePaths
1140 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1141 for _, o := range d.Javadoc.properties.Out {
1142 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1143 }
1144
1145 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1146 if err != nil {
1147 return
1148 }
1149
1150 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1151 if Bool(d.properties.Dokka_enabled) {
1152 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1153 } else {
1154 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1155 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1156 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1157 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1158 flags.postDoclavaCmds)
1159 }
1160
1161 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1162 !ctx.Config().IsPdkBuild() {
1163 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1164 "check_api.current.api_file")
1165 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1166 "check_api.current_removed_api_file")
1167
1168 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1169 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1170 fmt.Sprintf(`\n******************************\n`+
1171 `You have tried to change the API from what has been previously approved.\n\n`+
1172 `To make these errors go away, you have two choices:\n`+
1173 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1174 ` errors above.\n\n`+
1175 ` 2. You can update current.txt by executing the following command:\n`+
1176 ` make %s-update-current-api\n\n`+
1177 ` To submit the revised current.txt to the main Android repository,\n`+
1178 ` you will need approval.\n`+
1179 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1180 d.checkCurrentApiTimestamp)
1181
1182 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1183 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1184 d.updateCurrentApiTimestamp)
1185 }
1186
1187 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1188 !ctx.Config().IsPdkBuild() {
1189 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1190 "check_api.last_released.api_file")
1191 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1192 "check_api.last_released.removed_api_file")
1193
1194 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1195 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1196 `\n******************************\n`+
1197 `You have tried to change the API from what has been previously released in\n`+
1198 `an SDK. Please fix the errors listed above.\n`+
1199 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1200 d.checkLastReleasedApiTimestamp)
1201 }
1202}
1203
1204//
1205// Droidstubs
1206//
1207type Droidstubs struct {
1208 Javadoc
1209
Nan Zhang71bbe632018-09-17 14:32:21 -07001210 properties DroidstubsProperties
1211 apiFile android.WritablePath
1212 apiXmlFile android.WritablePath
1213 lastReleasedApiXmlFile android.WritablePath
1214 dexApiFile android.WritablePath
1215 privateApiFile android.WritablePath
1216 privateDexApiFile android.WritablePath
1217 removedApiFile android.WritablePath
1218 removedDexApiFile android.WritablePath
1219 apiMappingFile android.WritablePath
1220 exactApiFile android.WritablePath
Nan Zhang199645c2018-09-19 12:40:06 -07001221 proguardFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001222
1223 checkCurrentApiTimestamp android.WritablePath
1224 updateCurrentApiTimestamp android.WritablePath
1225 checkLastReleasedApiTimestamp android.WritablePath
1226
1227 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001228 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001229
1230 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001231
1232 jdiffDocZip android.WritablePath
1233 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001234}
1235
1236func DroidstubsFactory() android.Module {
1237 module := &Droidstubs{}
1238
1239 module.AddProperties(&module.properties,
1240 &module.Javadoc.properties)
1241
1242 InitDroiddocModule(module, android.HostAndDeviceSupported)
1243 return module
1244}
1245
1246func DroidstubsHostFactory() android.Module {
1247 module := &Droidstubs{}
1248
1249 module.AddProperties(&module.properties,
1250 &module.Javadoc.properties)
1251
1252 InitDroiddocModule(module, android.HostSupported)
1253 return module
1254}
1255
1256func (d *Droidstubs) ApiFilePath() android.Path {
1257 return d.apiFilePath
1258}
1259
1260func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1261 d.Javadoc.addDeps(ctx)
1262
1263 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1264 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1265 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1266 }
1267
1268 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1269 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1270 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1271 }
1272
1273 if String(d.properties.Previous_api) != "" {
1274 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1275 }
1276
1277 if len(d.properties.Merge_annotations_dirs) != 0 {
1278 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1279 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1280 }
1281 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001282
Pete Gillin77167902018-09-19 18:16:26 +01001283 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1284 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1285 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1286 }
1287 }
1288
Nan Zhang9c69a122018-08-22 10:22:08 -07001289 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1290 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1291 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1292 }
1293 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001294}
1295
1296func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1297 deps deps) (droiddocBuilderFlags, error) {
1298 var flags droiddocBuilderFlags
1299
1300 *implicits = append(*implicits, deps.bootClasspath...)
1301 *implicits = append(*implicits, deps.classpath...)
1302
1303 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1304 // since it doesn't support system modules yet.
1305 if len(deps.bootClasspath.Strings()) > 0 {
1306 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1307 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1308 }
1309 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1310
Sundong Ahn56dce442018-10-05 18:41:09 +09001311 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001312 return flags, nil
1313}
1314
1315func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1316 implicitOutputs *android.WritablePaths) string {
1317 var metalavaFlags string
1318 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1319 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1320 String(d.properties.Api_filename) != "" {
1321 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1322 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1323 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1324 d.apiFilePath = d.apiFile
1325 }
1326
1327 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1328 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1329 String(d.properties.Removed_api_filename) != "" {
1330 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1331 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1332 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1333 }
1334
1335 if String(d.properties.Private_api_filename) != "" {
1336 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1337 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1338 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1339 }
1340
1341 if String(d.properties.Dex_api_filename) != "" {
1342 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1343 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1344 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1345 }
1346
1347 if String(d.properties.Private_dex_api_filename) != "" {
1348 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1349 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1350 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1351 }
1352
1353 if String(d.properties.Removed_dex_api_filename) != "" {
1354 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1355 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1356 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1357 }
1358
1359 if String(d.properties.Exact_api_filename) != "" {
1360 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1361 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1362 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1363 }
1364
Nan Zhang9c69a122018-08-22 10:22:08 -07001365 if String(d.properties.Dex_mapping_filename) != "" {
1366 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1367 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1368 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1369 }
1370
Nan Zhang199645c2018-09-19 12:40:06 -07001371 if String(d.properties.Proguard_filename) != "" {
1372 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1373 metalavaFlags += " --proguard " + d.proguardFile.String()
1374 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1375 }
1376
Nan Zhang9c69a122018-08-22 10:22:08 -07001377 if Bool(d.properties.Write_sdk_values) {
1378 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1379 }
1380
Nan Zhang1598a9e2018-09-04 17:14:32 -07001381 if Bool(d.properties.Create_doc_stubs) {
1382 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1383 } else {
1384 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1385 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001386 return metalavaFlags
1387}
1388
1389func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1390 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001391 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001392 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001393 flags += " --include-annotations"
1394 validatingNullability := strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs")
1395 migratingNullability := String(d.properties.Previous_api) != ""
1396 if !(migratingNullability || validatingNullability) {
1397 ctx.PropertyErrorf("previous_api",
1398 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001399 }
Pete Gillina262c052018-09-14 14:25:48 +01001400 if migratingNullability {
1401 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1402 *implicits = append(*implicits, previousApi)
1403 flags += " --migrate-nullness " + previousApi.String()
1404 }
1405 if validatingNullability {
1406 nullabilityWarningsTxt := android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1407 *implicitOutputs = append(*implicitOutputs, nullabilityWarningsTxt)
1408 flags += " --nullability-warnings-txt " + nullabilityWarningsTxt.String()
1409 }
Nan Zhanga40da042018-08-01 12:48:00 -07001410
1411 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1412 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1413
Nan Zhangf4936b02018-08-01 15:00:28 -07001414 flags += " --extract-annotations " + d.annotationsZip.String()
1415
Nan Zhang1598a9e2018-09-04 17:14:32 -07001416 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001417 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001418 "has to be non-empty if annotations was enabled!")
1419 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001420 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1421 if t, ok := m.(*ExportedDroiddocDir); ok {
1422 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001423 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001424 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001425 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001426 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1427 }
1428 })
Nan Zhanga40da042018-08-01 12:48:00 -07001429 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001430 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001431 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001432
1433 return flags
1434}
1435
1436func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1437 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1438 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001439 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1440 if t, ok := m.(*ExportedDroiddocDir); ok {
1441 *implicits = append(*implicits, t.deps...)
1442 flags += " --merge-inclusion-annotations " + t.dir.String()
1443 } else {
1444 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1445 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1446 }
1447 })
Nan Zhanga40da042018-08-01 12:48:00 -07001448
1449 return flags
1450}
1451
Nan Zhang9c69a122018-08-22 10:22:08 -07001452func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1453 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1454 var flags string
1455 if Bool(d.properties.Api_levels_annotations_enabled) {
1456 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1457 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1458
1459 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1460 ctx.PropertyErrorf("api_levels_annotations_dirs",
1461 "has to be non-empty if api levels annotations was enabled!")
1462 }
1463
1464 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1465 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1466 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1467
1468 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1469 if t, ok := m.(*ExportedDroiddocDir); ok {
1470 var androidJars android.Paths
1471 for _, dep := range t.deps {
1472 if strings.HasSuffix(dep.String(), "android.jar") {
1473 androidJars = append(androidJars, dep)
1474 }
1475 }
1476 *implicits = append(*implicits, androidJars...)
1477 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1478 } else {
1479 ctx.PropertyErrorf("api_levels_annotations_dirs",
1480 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1481 }
1482 })
1483
1484 }
1485
1486 return flags
1487}
1488
Nan Zhang71bbe632018-09-17 14:32:21 -07001489func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1490 implicitOutputs *android.WritablePaths) string {
1491 var flags string
1492 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1493 if d.apiFile.String() == "" {
1494 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1495 }
1496
1497 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1498 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1499
1500 flags = " --api-xml " + d.apiXmlFile.String()
1501
1502 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1503 ctx.PropertyErrorf("check_api.last_released.api_file",
1504 "has to be non-empty if jdiff was enabled!")
1505 }
1506 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1507 "check_api.last_released.api_file")
1508 *implicits = append(*implicits, lastReleasedApi)
1509
1510 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1511 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1512
1513 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1514 d.lastReleasedApiXmlFile.String()
1515 }
1516
1517 return flags
1518}
1519
Nan Zhang1598a9e2018-09-04 17:14:32 -07001520func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1521 implicitOutputs android.WritablePaths, javaVersion,
1522 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001523
Nan Zhang86d2d552018-08-09 15:33:27 -07001524 ctx.Build(pctx, android.BuildParams{
1525 Rule: metalava,
1526 Description: "Metalava",
1527 Output: d.Javadoc.stubsSrcJar,
1528 Inputs: d.Javadoc.srcFiles,
1529 Implicits: implicits,
1530 ImplicitOutputs: implicitOutputs,
1531 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001532 "outDir": android.PathForModuleOut(ctx, "out").String(),
1533 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1534 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1535 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001536 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001537 "bootclasspathArgs": bootclasspathArgs,
1538 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001539 "sourcepathArgs": sourcepathArgs,
1540 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001541 },
1542 })
1543}
1544
Nan Zhang1598a9e2018-09-04 17:14:32 -07001545func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1546 apiFile, removedApiFile android.Path, implicits android.Paths,
1547 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001548 output android.WritablePath) {
1549 ctx.Build(pctx, android.BuildParams{
1550 Rule: metalavaApiCheck,
1551 Description: "Metalava Check API",
1552 Output: output,
1553 Inputs: d.Javadoc.srcFiles,
1554 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1555 implicits...),
1556 Args: map[string]string{
1557 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1558 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1559 "javaVersion": javaVersion,
1560 "bootclasspathArgs": bootclasspathArgs,
1561 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001562 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001563 "opts": opts,
1564 "msg": msg,
1565 },
1566 })
1567}
1568
Nan Zhang71bbe632018-09-17 14:32:21 -07001569func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1570 implicitOutputs android.WritablePaths,
1571 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1572 ctx.Build(pctx, android.BuildParams{
1573 Rule: javadoc,
1574 Description: "Jdiff",
1575 Output: d.jdiffStubsSrcJar,
1576 Inputs: d.Javadoc.srcFiles,
1577 Implicits: implicits,
1578 ImplicitOutputs: implicitOutputs,
1579 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001580 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1581 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1582 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001583 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1584 "opts": opts,
1585 "bootclasspathArgs": bootclasspathArgs,
1586 "classpathArgs": classpathArgs,
1587 "sourcepathArgs": sourcepathArgs,
1588 "docZip": d.jdiffDocZip.String(),
1589 },
1590 })
1591}
1592
Nan Zhang1598a9e2018-09-04 17:14:32 -07001593func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001594 deps := d.Javadoc.collectDeps(ctx)
1595
1596 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001597
Nan Zhanga40da042018-08-01 12:48:00 -07001598 var implicits android.Paths
1599 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001600 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001601
1602 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001603 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001604 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1605 }
1606
1607 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001608 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001609 jdiffImplicits := implicits
1610
Nan Zhanga40da042018-08-01 12:48:00 -07001611 if err != nil {
1612 return
1613 }
1614
Nan Zhang1598a9e2018-09-04 17:14:32 -07001615 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1616 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001617 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001618 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001619 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1620
Nan Zhang1598a9e2018-09-04 17:14:32 -07001621 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1622 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1623 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1624 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1625 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001626 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001627 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1628 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001629 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001630 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001631
Nan Zhang1598a9e2018-09-04 17:14:32 -07001632 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1633 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001634 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1635 "check_api.current.api_file")
1636 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1637 "check_api.current_removed_api_file")
1638
Nan Zhang2760dfc2018-08-24 17:32:54 +00001639 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001640 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1641 " --check-compatibility:removed:current " + removedApiFile.String() +
1642 flags.metalavaInclusionAnnotationsFlags
Nan Zhang2760dfc2018-08-24 17:32:54 +00001643
Nan Zhang1598a9e2018-09-04 17:14:32 -07001644 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1645 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1646 fmt.Sprintf(`\n******************************\n`+
1647 `You have tried to change the API from what has been previously approved.\n\n`+
1648 `To make these errors go away, you have two choices:\n`+
1649 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1650 ` errors above.\n\n`+
1651 ` 2. You can update current.txt by executing the following command:\n`+
1652 ` make %s-update-current-api\n\n`+
1653 ` To submit the revised current.txt to the main Android repository,\n`+
1654 ` you will need approval.\n`+
1655 `******************************\n`, ctx.ModuleName()),
1656 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001657
1658 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001659 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1660 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001661 }
Nan Zhanga40da042018-08-01 12:48:00 -07001662
Nan Zhang1598a9e2018-09-04 17:14:32 -07001663 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1664 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001665 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1666 "check_api.last_released.api_file")
1667 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1668 "check_api.last_released.removed_api_file")
1669
Nan Zhang2760dfc2018-08-24 17:32:54 +00001670 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001671 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1672 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
1673 removedApiFile.String() + " "
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 `\n******************************\n`+
1678 `You have tried to change the API from what has been previously released in\n`+
1679 `an SDK. Please fix the errors listed above.\n`+
1680 `******************************\n`,
1681 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001682 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001683
1684 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1685
Nan Zhang86b06202018-09-21 17:09:21 -07001686 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1687 // since there's cron job downstream that fetch this .zip file periodically.
1688 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001689 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1690 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1691
1692 var jdiffImplicitOutputs android.WritablePaths
1693 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1694
1695 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1696 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1697
1698 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1699 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1700 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1701 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1702 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1703 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1704
1705 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1706 flags.sourcepathArgs, opts)
1707 }
Nan Zhang581fd212018-01-10 16:06:12 -08001708}
Dan Willemsencc090972018-02-26 14:33:31 -08001709
Nan Zhanga40da042018-08-01 12:48:00 -07001710//
Nan Zhangf4936b02018-08-01 15:00:28 -07001711// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001712//
Dan Willemsencc090972018-02-26 14:33:31 -08001713var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001714var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001715var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001716var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001717
Nan Zhangf4936b02018-08-01 15:00:28 -07001718type ExportedDroiddocDirProperties struct {
1719 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001720 Path *string
1721}
1722
Nan Zhangf4936b02018-08-01 15:00:28 -07001723type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001724 android.ModuleBase
1725
Nan Zhangf4936b02018-08-01 15:00:28 -07001726 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001727
1728 deps android.Paths
1729 dir android.Path
1730}
1731
Nan Zhangf4936b02018-08-01 15:00:28 -07001732func ExportedDroiddocDirFactory() android.Module {
1733 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001734 module.AddProperties(&module.properties)
1735 android.InitAndroidModule(module)
1736 return module
1737}
1738
Nan Zhangf4936b02018-08-01 15:00:28 -07001739func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001740
Nan Zhangf4936b02018-08-01 15:00:28 -07001741func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001742 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1743 d.dir = path
1744 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1745}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001746
1747//
1748// Defaults
1749//
1750type DocDefaults struct {
1751 android.ModuleBase
1752 android.DefaultsModuleBase
1753}
1754
1755func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1756}
1757
1758func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1759}
1760
1761func DocDefaultsFactory() android.Module {
1762 module := &DocDefaults{}
1763
1764 module.AddProperties(
1765 &JavadocProperties{},
1766 &DroiddocProperties{},
1767 )
1768
1769 android.InitDefaultsModule(module)
1770
1771 return module
1772}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001773
1774func StubsDefaultsFactory() android.Module {
1775 module := &DocDefaults{}
1776
1777 module.AddProperties(
1778 &JavadocProperties{},
1779 &DroidstubsProperties{},
1780 )
1781
1782 android.InitDefaultsModule(module)
1783
1784 return module
1785}