blob: b724e1541606707f6f0351193e7755194a772190 [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
Dan Willemsen419290a2018-10-31 15:28:47 -0700487func (j *Javadoc) targetSdkVersion() string {
488 return j.sdkVersion()
489}
490
Nan Zhang581fd212018-01-10 16:06:12 -0800491func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
492 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700493 if !Bool(j.properties.No_standard_libs) {
494 sdkDep := decodeSdkDep(ctx, sdkContext(j))
495 if sdkDep.useDefaultLibs {
496 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
497 if ctx.Config().TargetOpenJDK9() {
498 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
499 }
500 if !Bool(j.properties.No_framework_libs) {
501 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
502 }
503 } else if sdkDep.useModule {
504 if ctx.Config().TargetOpenJDK9() {
505 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
506 }
507 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700508 }
Nan Zhang581fd212018-01-10 16:06:12 -0800509 }
510 }
511
Colin Cross42d48b72018-08-29 14:10:52 -0700512 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700513 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700514 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700515 }
Nan Zhang581fd212018-01-10 16:06:12 -0800516
517 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
518
519 // exclude_srcs may contain filegroup or genrule.
520 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700521
522 // arg_files may contains filegroup or genrule.
523 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800524}
525
Nan Zhangb2b33de2018-02-23 11:18:47 -0800526func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
527 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
528 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900529 // convert foo.bar.baz to foo/bar/baz
530 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
531 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800532 if _, found := whitelistPathPrefixes[prefix]; !found {
533 whitelistPathPrefixes[prefix] = true
534 }
535 }
536 }
537}
538
Nan Zhanga40da042018-08-01 12:48:00 -0700539func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
540 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900541
542 // aidl flags.
543 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
544 if len(aidlFlags) > 0 {
545 // optimization.
546 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
547 flags.aidlFlags = "$aidlFlags"
548 }
549
550 return flags
551}
552
553func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
554 aidlIncludeDirs android.Paths) []string {
555
556 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
557 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
558
559 var flags []string
560 if aidlPreprocess.Valid() {
561 flags = append(flags, "-p"+aidlPreprocess.String())
562 } else {
563 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
564 }
565
566 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
567 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
568 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
569 flags = append(flags, "-I"+src.String())
570 }
571
572 return flags
573}
574
575func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700576 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900577
578 outSrcFiles := make(android.Paths, 0, len(srcFiles))
579
580 for _, srcFile := range srcFiles {
581 switch srcFile.Ext() {
582 case ".aidl":
583 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
584 outSrcFiles = append(outSrcFiles, javaFile)
585 default:
586 outSrcFiles = append(outSrcFiles, srcFile)
587 }
588 }
589
590 return outSrcFiles
591}
592
Nan Zhang581fd212018-01-10 16:06:12 -0800593func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
594 var deps deps
595
Colin Cross83bb3162018-06-25 15:48:06 -0700596 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800597 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700598 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800599 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700600 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800601 }
602
603 ctx.VisitDirectDeps(func(module android.Module) {
604 otherName := ctx.OtherModuleName(module)
605 tag := ctx.OtherModuleDependencyTag(module)
606
Colin Cross2d24c1b2018-05-23 10:59:18 -0700607 switch tag {
608 case bootClasspathTag:
609 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800610 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700611 } else {
612 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
613 }
614 case libTag:
615 switch dep := module.(type) {
616 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800617 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700618 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700619 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900620 linkType := javaSdk
621 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
622 linkType = javaSystem
623 } else if sdkVersion == "" {
624 linkType = javaPlatform
625 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900626 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700627 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800628 checkProducesJars(ctx, dep)
629 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800630 default:
631 ctx.ModuleErrorf("depends on non-java module %q", otherName)
632 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700633 case srcsLibTag:
634 switch dep := module.(type) {
635 case Dependency:
636 srcs := dep.(SrcDependency).CompiledSrcs()
637 whitelistPathPrefixes := make(map[string]bool)
638 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
639 for _, src := range srcs {
640 if _, ok := src.(android.WritablePath); ok { // generated sources
641 deps.srcs = append(deps.srcs, src)
642 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700643 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700644 if strings.HasPrefix(src.Rel(), k) {
645 deps.srcs = append(deps.srcs, src)
646 break
647 }
648 }
649 }
650 }
651 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
652 default:
653 ctx.ModuleErrorf("depends on non-java module %q", otherName)
654 }
Nan Zhang357466b2018-04-17 17:38:36 -0700655 case systemModulesTag:
656 if deps.systemModules != nil {
657 panic("Found two system module dependencies")
658 }
659 sm := module.(*SystemModules)
660 if sm.outputFile == nil {
661 panic("Missing directory for system module dependency")
662 }
663 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800664 }
665 })
666 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
667 // may contain filegroup or genrule.
668 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700669 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900670 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800671
672 // srcs may depend on some genrule output.
673 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800674 j.srcJars = append(j.srcJars, deps.srcJars...)
675
Nan Zhang581fd212018-01-10 16:06:12 -0800676 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800677 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800678
679 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800680 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800681
Nan Zhang9c69a122018-08-22 10:22:08 -0700682 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800683 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
684 }
685 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800686
Nan Zhang1598a9e2018-09-04 17:14:32 -0700687 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
688 argFilesMap := map[string]android.Path{}
689
690 for _, f := range j.argFiles {
691 if _, exists := argFilesMap[f.Rel()]; !exists {
692 argFilesMap[f.Rel()] = f
693 } else {
694 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
695 f, argFilesMap[f.Rel()], f.Rel())
696 }
697 }
698
699 var err error
700 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
701 if strings.HasPrefix(name, "location ") {
702 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
703 if f, ok := argFilesMap[label]; ok {
704 return f.String(), nil
705 } else {
706 return "", fmt.Errorf("unknown location label %q", label)
707 }
708 } else if name == "genDir" {
709 return android.PathForModuleGen(ctx).String(), nil
710 }
711 return "", fmt.Errorf("unknown variable '$(%s)'", name)
712 })
713
714 if err != nil {
715 ctx.PropertyErrorf("args", "%s", err.Error())
716 }
717
Nan Zhang581fd212018-01-10 16:06:12 -0800718 return deps
719}
720
721func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
722 j.addDeps(ctx)
723}
724
725func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
726 deps := j.collectDeps(ctx)
727
728 var implicits android.Paths
729 implicits = append(implicits, deps.bootClasspath...)
730 implicits = append(implicits, deps.classpath...)
731
Nan Zhang1598a9e2018-09-04 17:14:32 -0700732 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700733
Colin Cross83bb3162018-06-25 15:48:06 -0700734 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700735 if len(deps.bootClasspath) > 0 {
736 var systemModules classpath
737 if deps.systemModules != nil {
738 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800739 }
Colin Cross997262f2018-06-19 22:49:39 -0700740 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
741 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800742 }
743 if len(deps.classpath.Strings()) > 0 {
744 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
745 }
746
747 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700748 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800749
Nan Zhangaf322cc2018-06-19 15:15:38 -0700750 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800751
Nan Zhang1598a9e2018-09-04 17:14:32 -0700752 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
753
Nan Zhang581fd212018-01-10 16:06:12 -0800754 ctx.Build(pctx, android.BuildParams{
755 Rule: javadoc,
756 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800757 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800758 ImplicitOutput: j.docZip,
759 Inputs: j.srcFiles,
760 Implicits: implicits,
761 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700762 "outDir": android.PathForModuleOut(ctx, "out").String(),
763 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
764 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800765 "srcJars": strings.Join(j.srcJars.Strings(), " "),
766 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700767 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800768 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700769 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800770 "docZip": j.docZip.String(),
771 },
772 })
773}
774
Nan Zhanga40da042018-08-01 12:48:00 -0700775//
776// Droiddoc
777//
778type Droiddoc struct {
779 Javadoc
780
781 properties DroiddocProperties
782 apiFile android.WritablePath
783 dexApiFile android.WritablePath
784 privateApiFile android.WritablePath
785 privateDexApiFile android.WritablePath
786 removedApiFile android.WritablePath
787 removedDexApiFile android.WritablePath
788 exactApiFile android.WritablePath
789 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700790 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700791
792 checkCurrentApiTimestamp android.WritablePath
793 updateCurrentApiTimestamp android.WritablePath
794 checkLastReleasedApiTimestamp android.WritablePath
795
Nan Zhanga40da042018-08-01 12:48:00 -0700796 apiFilePath android.Path
797}
798
Nan Zhanga40da042018-08-01 12:48:00 -0700799func DroiddocFactory() android.Module {
800 module := &Droiddoc{}
801
802 module.AddProperties(&module.properties,
803 &module.Javadoc.properties)
804
805 InitDroiddocModule(module, android.HostAndDeviceSupported)
806 return module
807}
808
809func DroiddocHostFactory() android.Module {
810 module := &Droiddoc{}
811
812 module.AddProperties(&module.properties,
813 &module.Javadoc.properties)
814
815 InitDroiddocModule(module, android.HostSupported)
816 return module
817}
818
819func (d *Droiddoc) ApiFilePath() android.Path {
820 return d.apiFilePath
821}
822
Nan Zhang581fd212018-01-10 16:06:12 -0800823func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
824 d.Javadoc.addDeps(ctx)
825
Nan Zhang79614d12018-04-19 18:03:39 -0700826 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800827 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
828 }
829
Nan Zhang581fd212018-01-10 16:06:12 -0800830 // knowntags may contain filegroup or genrule.
831 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700832
Nan Zhange2ba5d42018-07-11 15:16:55 -0700833 if String(d.properties.Static_doc_index_redirect) != "" {
834 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
835 }
836
837 if String(d.properties.Static_doc_properties) != "" {
838 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
839 }
840
Nan Zhang1598a9e2018-09-04 17:14:32 -0700841 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700842 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
843 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
844 }
845
Nan Zhang1598a9e2018-09-04 17:14:32 -0700846 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700847 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
848 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
849 }
Nan Zhang581fd212018-01-10 16:06:12 -0800850}
851
Nan Zhang66dc2362018-08-14 20:41:04 -0700852func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
853 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700854 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800855
Nan Zhanga40da042018-08-01 12:48:00 -0700856 *implicits = append(*implicits, deps.bootClasspath...)
857 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800858
Nan Zhangc94f9d82018-06-26 10:02:26 -0700859 if len(deps.bootClasspath.Strings()) > 0 {
860 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700861 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700862 }
Nan Zhanga40da042018-08-01 12:48:00 -0700863 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700864 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700865 dokkaClasspath := classpath{}
866 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
867 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
868 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700869
Nan Zhang9c69a122018-08-22 10:22:08 -0700870 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
871 // based stubs generation.
872 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
873 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
874 // the correct package name base path.
875 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
876 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
877 } else {
878 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
879 }
Nan Zhang581fd212018-01-10 16:06:12 -0800880
Nan Zhanga40da042018-08-01 12:48:00 -0700881 return flags, nil
882}
Nan Zhang581fd212018-01-10 16:06:12 -0800883
Nan Zhanga40da042018-08-01 12:48:00 -0700884func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700885 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800886
Nan Zhanga40da042018-08-01 12:48:00 -0700887 *implicits = append(*implicits, jsilver)
888 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700889
Nan Zhang46130972018-06-04 11:28:01 -0700890 var date string
891 if runtime.GOOS == "darwin" {
892 date = `date -r`
893 } else {
894 date = `date -d`
895 }
896
Nan Zhang443fa522018-08-20 20:58:28 -0700897 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
898 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
899 // 1.9 language features.
900 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700901 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800902 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700903 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700904
Nan Zhanga40da042018-08-01 12:48:00 -0700905 if String(d.properties.Custom_template) == "" {
906 // TODO: This is almost always droiddoc-templates-sdk
907 ctx.PropertyErrorf("custom_template", "must specify a template")
908 }
909
910 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700911 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700912 *implicits = append(*implicits, t.deps...)
913 args = args + " -templatedir " + t.dir.String()
914 } else {
915 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
916 }
917 })
918
919 if len(d.properties.Html_dirs) > 0 {
920 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
921 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
922 args = args + " -htmldir " + htmlDir.String()
923 }
924
925 if len(d.properties.Html_dirs) > 1 {
926 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
927 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
928 args = args + " -htmldir2 " + htmlDir2.String()
929 }
930
931 if len(d.properties.Html_dirs) > 2 {
932 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
933 }
934
935 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
936 *implicits = append(*implicits, knownTags...)
937
938 for _, kt := range knownTags {
939 args = args + " -knowntags " + kt.String()
940 }
941
942 for _, hdf := range d.properties.Hdf {
943 args = args + " -hdf " + hdf
944 }
945
946 if String(d.properties.Proofread_file) != "" {
947 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
948 args = args + " -proofread " + proofreadFile.String()
949 }
950
951 if String(d.properties.Todo_file) != "" {
952 // tricky part:
953 // we should not compute full path for todo_file through PathForModuleOut().
954 // the non-standard doclet will get the full path relative to "-o".
955 args = args + " -todo " + String(d.properties.Todo_file)
956 }
957
958 if String(d.properties.Resourcesdir) != "" {
959 // TODO: should we add files under resourcesDir to the implicits? It seems that
960 // resourcesDir is one sub dir of htmlDir
961 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
962 args = args + " -resourcesdir " + resourcesDir.String()
963 }
964
965 if String(d.properties.Resourcesoutdir) != "" {
966 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
967 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
968 }
969 return args
970}
971
Nan Zhang1598a9e2018-09-04 17:14:32 -0700972func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
973 implicitOutputs *android.WritablePaths) string {
974 var doclavaFlags string
975 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
976 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
977 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700978 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
979 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700980 *implicitOutputs = append(*implicitOutputs, d.apiFile)
981 d.apiFilePath = d.apiFile
982 }
983
Nan Zhang1598a9e2018-09-04 17:14:32 -0700984 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
985 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
986 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700987 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
988 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700989 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
990 }
991
992 if String(d.properties.Private_api_filename) != "" {
993 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
994 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700995 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
996 }
997
998 if String(d.properties.Dex_api_filename) != "" {
999 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1000 doclavaFlags += " -dexApi " + d.dexApiFile.String()
1001 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1002 }
1003
1004 if String(d.properties.Private_dex_api_filename) != "" {
1005 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1006 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001007 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1008 }
1009
1010 if String(d.properties.Removed_dex_api_filename) != "" {
1011 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1012 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001013 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1014 }
1015
1016 if String(d.properties.Exact_api_filename) != "" {
1017 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1018 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001019 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1020 }
1021
1022 if String(d.properties.Dex_mapping_filename) != "" {
1023 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1024 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001025 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1026 }
1027
Nan Zhang66dc2362018-08-14 20:41:04 -07001028 if String(d.properties.Proguard_filename) != "" {
1029 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1030 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001031 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1032 }
1033
Nan Zhanga40da042018-08-01 12:48:00 -07001034 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001035 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001036 }
1037
1038 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001039 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001040 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001041
1042 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001043}
1044
1045func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1046 var cmds string
1047 if String(d.properties.Static_doc_index_redirect) != "" {
1048 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1049 "static_doc_index_redirect")
1050 *implicits = append(*implicits, static_doc_index_redirect)
1051 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001052 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001053 }
1054
1055 if String(d.properties.Static_doc_properties) != "" {
1056 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1057 "static_doc_properties")
1058 *implicits = append(*implicits, static_doc_properties)
1059 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001060 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001061 }
1062 return cmds
1063}
1064
Nan Zhang1598a9e2018-09-04 17:14:32 -07001065func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1066 implicitOutputs android.WritablePaths,
1067 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1068 ctx.Build(pctx, android.BuildParams{
1069 Rule: javadoc,
1070 Description: "Doclava",
1071 Output: d.Javadoc.stubsSrcJar,
1072 Inputs: d.Javadoc.srcFiles,
1073 Implicits: implicits,
1074 ImplicitOutputs: implicitOutputs,
1075 Args: map[string]string{
1076 "outDir": android.PathForModuleOut(ctx, "out").String(),
1077 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1078 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1079 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1080 "opts": opts,
1081 "bootclasspathArgs": bootclasspathArgs,
1082 "classpathArgs": classpathArgs,
1083 "sourcepathArgs": sourcepathArgs,
1084 "docZip": d.Javadoc.docZip.String(),
1085 "postDoclavaCmds": postDoclavaCmds,
1086 },
1087 })
1088}
1089
1090func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1091 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1092 ctx.Build(pctx, android.BuildParams{
1093 Rule: apiCheck,
1094 Description: "Doclava Check API",
1095 Output: output,
1096 Inputs: nil,
1097 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1098 checkApiClasspath...),
1099 Args: map[string]string{
1100 "msg": msg,
1101 "classpath": checkApiClasspath.FormJavaClassPath(""),
1102 "opts": opts,
1103 "apiFile": apiFile.String(),
1104 "apiFileToCheck": d.apiFile.String(),
1105 "removedApiFile": removedApiFile.String(),
1106 "removedApiFileToCheck": d.removedApiFile.String(),
1107 },
1108 })
1109}
1110
1111func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1112 classpathArgs, opts string) {
1113 ctx.Build(pctx, android.BuildParams{
1114 Rule: dokka,
1115 Description: "Dokka",
1116 Output: d.Javadoc.stubsSrcJar,
1117 Inputs: d.Javadoc.srcFiles,
1118 Implicits: implicits,
1119 Args: map[string]string{
1120 "outDir": android.PathForModuleOut(ctx, "out").String(),
1121 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1122 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1123 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1124 "classpathArgs": classpathArgs,
1125 "opts": opts,
1126 "docZip": d.Javadoc.docZip.String(),
1127 },
1128 })
1129}
1130
1131func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1132 deps := d.Javadoc.collectDeps(ctx)
1133
1134 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1135 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1136 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1137 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1138
1139 var implicits android.Paths
1140 implicits = append(implicits, d.Javadoc.srcJars...)
1141 implicits = append(implicits, d.Javadoc.argFiles...)
1142
1143 var implicitOutputs android.WritablePaths
1144 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1145 for _, o := range d.Javadoc.properties.Out {
1146 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1147 }
1148
1149 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1150 if err != nil {
1151 return
1152 }
1153
1154 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1155 if Bool(d.properties.Dokka_enabled) {
1156 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1157 } else {
1158 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1159 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1160 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1161 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1162 flags.postDoclavaCmds)
1163 }
1164
1165 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1166 !ctx.Config().IsPdkBuild() {
1167 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1168 "check_api.current.api_file")
1169 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1170 "check_api.current_removed_api_file")
1171
1172 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1173 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1174 fmt.Sprintf(`\n******************************\n`+
1175 `You have tried to change the API from what has been previously approved.\n\n`+
1176 `To make these errors go away, you have two choices:\n`+
1177 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1178 ` errors above.\n\n`+
1179 ` 2. You can update current.txt by executing the following command:\n`+
1180 ` make %s-update-current-api\n\n`+
1181 ` To submit the revised current.txt to the main Android repository,\n`+
1182 ` you will need approval.\n`+
1183 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1184 d.checkCurrentApiTimestamp)
1185
1186 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1187 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1188 d.updateCurrentApiTimestamp)
1189 }
1190
1191 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1192 !ctx.Config().IsPdkBuild() {
1193 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1194 "check_api.last_released.api_file")
1195 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1196 "check_api.last_released.removed_api_file")
1197
1198 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1199 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1200 `\n******************************\n`+
1201 `You have tried to change the API from what has been previously released in\n`+
1202 `an SDK. Please fix the errors listed above.\n`+
1203 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1204 d.checkLastReleasedApiTimestamp)
1205 }
1206}
1207
1208//
1209// Droidstubs
1210//
1211type Droidstubs struct {
1212 Javadoc
1213
Nan Zhang71bbe632018-09-17 14:32:21 -07001214 properties DroidstubsProperties
1215 apiFile android.WritablePath
1216 apiXmlFile android.WritablePath
1217 lastReleasedApiXmlFile android.WritablePath
1218 dexApiFile android.WritablePath
1219 privateApiFile android.WritablePath
1220 privateDexApiFile android.WritablePath
1221 removedApiFile android.WritablePath
1222 removedDexApiFile android.WritablePath
1223 apiMappingFile android.WritablePath
1224 exactApiFile android.WritablePath
Nan Zhang199645c2018-09-19 12:40:06 -07001225 proguardFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001226
1227 checkCurrentApiTimestamp android.WritablePath
1228 updateCurrentApiTimestamp android.WritablePath
1229 checkLastReleasedApiTimestamp android.WritablePath
1230
1231 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001232 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001233
1234 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001235
1236 jdiffDocZip android.WritablePath
1237 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001238}
1239
1240func DroidstubsFactory() android.Module {
1241 module := &Droidstubs{}
1242
1243 module.AddProperties(&module.properties,
1244 &module.Javadoc.properties)
1245
1246 InitDroiddocModule(module, android.HostAndDeviceSupported)
1247 return module
1248}
1249
1250func DroidstubsHostFactory() android.Module {
1251 module := &Droidstubs{}
1252
1253 module.AddProperties(&module.properties,
1254 &module.Javadoc.properties)
1255
1256 InitDroiddocModule(module, android.HostSupported)
1257 return module
1258}
1259
1260func (d *Droidstubs) ApiFilePath() android.Path {
1261 return d.apiFilePath
1262}
1263
1264func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1265 d.Javadoc.addDeps(ctx)
1266
1267 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1268 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1269 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1270 }
1271
1272 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1273 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1274 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1275 }
1276
1277 if String(d.properties.Previous_api) != "" {
1278 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1279 }
1280
1281 if len(d.properties.Merge_annotations_dirs) != 0 {
1282 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1283 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1284 }
1285 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001286
Pete Gillin77167902018-09-19 18:16:26 +01001287 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1288 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1289 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1290 }
1291 }
1292
Nan Zhang9c69a122018-08-22 10:22:08 -07001293 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1294 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1295 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1296 }
1297 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001298}
1299
1300func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1301 deps deps) (droiddocBuilderFlags, error) {
1302 var flags droiddocBuilderFlags
1303
1304 *implicits = append(*implicits, deps.bootClasspath...)
1305 *implicits = append(*implicits, deps.classpath...)
1306
1307 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1308 // since it doesn't support system modules yet.
1309 if len(deps.bootClasspath.Strings()) > 0 {
1310 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1311 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1312 }
1313 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1314
Sundong Ahn56dce442018-10-05 18:41:09 +09001315 flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\""
Nan Zhang1598a9e2018-09-04 17:14:32 -07001316 return flags, nil
1317}
1318
1319func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1320 implicitOutputs *android.WritablePaths) string {
1321 var metalavaFlags string
1322 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1323 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1324 String(d.properties.Api_filename) != "" {
1325 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1326 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1327 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1328 d.apiFilePath = d.apiFile
1329 }
1330
1331 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1332 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1333 String(d.properties.Removed_api_filename) != "" {
1334 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1335 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1336 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1337 }
1338
1339 if String(d.properties.Private_api_filename) != "" {
1340 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1341 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1342 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1343 }
1344
1345 if String(d.properties.Dex_api_filename) != "" {
1346 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1347 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1348 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1349 }
1350
1351 if String(d.properties.Private_dex_api_filename) != "" {
1352 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1353 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1354 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1355 }
1356
1357 if String(d.properties.Removed_dex_api_filename) != "" {
1358 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1359 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1360 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1361 }
1362
1363 if String(d.properties.Exact_api_filename) != "" {
1364 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1365 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1366 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1367 }
1368
Nan Zhang9c69a122018-08-22 10:22:08 -07001369 if String(d.properties.Dex_mapping_filename) != "" {
1370 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1371 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1372 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1373 }
1374
Nan Zhang199645c2018-09-19 12:40:06 -07001375 if String(d.properties.Proguard_filename) != "" {
1376 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1377 metalavaFlags += " --proguard " + d.proguardFile.String()
1378 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1379 }
1380
Nan Zhang9c69a122018-08-22 10:22:08 -07001381 if Bool(d.properties.Write_sdk_values) {
1382 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1383 }
1384
Nan Zhang1598a9e2018-09-04 17:14:32 -07001385 if Bool(d.properties.Create_doc_stubs) {
1386 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1387 } else {
1388 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1389 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001390 return metalavaFlags
1391}
1392
1393func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1394 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001395 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001396 if Bool(d.properties.Annotations_enabled) {
Pete Gillina262c052018-09-14 14:25:48 +01001397 flags += " --include-annotations"
1398 validatingNullability := strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs")
1399 migratingNullability := String(d.properties.Previous_api) != ""
1400 if !(migratingNullability || validatingNullability) {
1401 ctx.PropertyErrorf("previous_api",
1402 "has to be non-empty if annotations was enabled (unless validating nullability)")
Nan Zhanga40da042018-08-01 12:48:00 -07001403 }
Pete Gillina262c052018-09-14 14:25:48 +01001404 if migratingNullability {
1405 previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api")
1406 *implicits = append(*implicits, previousApi)
1407 flags += " --migrate-nullness " + previousApi.String()
1408 }
1409 if validatingNullability {
1410 nullabilityWarningsTxt := android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
1411 *implicitOutputs = append(*implicitOutputs, nullabilityWarningsTxt)
1412 flags += " --nullability-warnings-txt " + nullabilityWarningsTxt.String()
1413 }
Nan Zhanga40da042018-08-01 12:48:00 -07001414
1415 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1416 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1417
Nan Zhangf4936b02018-08-01 15:00:28 -07001418 flags += " --extract-annotations " + d.annotationsZip.String()
1419
Nan Zhang1598a9e2018-09-04 17:14:32 -07001420 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001421 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001422 "has to be non-empty if annotations was enabled!")
1423 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001424 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1425 if t, ok := m.(*ExportedDroiddocDir); ok {
1426 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001427 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001428 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001429 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001430 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1431 }
1432 })
Nan Zhanga40da042018-08-01 12:48:00 -07001433 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001434 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
Nan Zhanga40da042018-08-01 12:48:00 -07001435 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001436
1437 return flags
1438}
1439
1440func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext,
1441 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1442 var flags string
Pete Gillin77167902018-09-19 18:16:26 +01001443 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1444 if t, ok := m.(*ExportedDroiddocDir); ok {
1445 *implicits = append(*implicits, t.deps...)
1446 flags += " --merge-inclusion-annotations " + t.dir.String()
1447 } else {
1448 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1449 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1450 }
1451 })
Nan Zhanga40da042018-08-01 12:48:00 -07001452
1453 return flags
1454}
1455
Nan Zhang9c69a122018-08-22 10:22:08 -07001456func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1457 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1458 var flags string
1459 if Bool(d.properties.Api_levels_annotations_enabled) {
1460 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1461 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1462
1463 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1464 ctx.PropertyErrorf("api_levels_annotations_dirs",
1465 "has to be non-empty if api levels annotations was enabled!")
1466 }
1467
1468 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1469 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1470 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1471
1472 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1473 if t, ok := m.(*ExportedDroiddocDir); ok {
1474 var androidJars android.Paths
1475 for _, dep := range t.deps {
1476 if strings.HasSuffix(dep.String(), "android.jar") {
1477 androidJars = append(androidJars, dep)
1478 }
1479 }
1480 *implicits = append(*implicits, androidJars...)
1481 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1482 } else {
1483 ctx.PropertyErrorf("api_levels_annotations_dirs",
1484 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1485 }
1486 })
1487
1488 }
1489
1490 return flags
1491}
1492
Nan Zhang71bbe632018-09-17 14:32:21 -07001493func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1494 implicitOutputs *android.WritablePaths) string {
1495 var flags string
1496 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1497 if d.apiFile.String() == "" {
1498 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1499 }
1500
1501 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1502 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1503
1504 flags = " --api-xml " + d.apiXmlFile.String()
1505
1506 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1507 ctx.PropertyErrorf("check_api.last_released.api_file",
1508 "has to be non-empty if jdiff was enabled!")
1509 }
1510 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1511 "check_api.last_released.api_file")
1512 *implicits = append(*implicits, lastReleasedApi)
1513
1514 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1515 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1516
1517 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1518 d.lastReleasedApiXmlFile.String()
1519 }
1520
1521 return flags
1522}
1523
Nan Zhang1598a9e2018-09-04 17:14:32 -07001524func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1525 implicitOutputs android.WritablePaths, javaVersion,
1526 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001527
Nan Zhang86d2d552018-08-09 15:33:27 -07001528 ctx.Build(pctx, android.BuildParams{
1529 Rule: metalava,
1530 Description: "Metalava",
1531 Output: d.Javadoc.stubsSrcJar,
1532 Inputs: d.Javadoc.srcFiles,
1533 Implicits: implicits,
1534 ImplicitOutputs: implicitOutputs,
1535 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001536 "outDir": android.PathForModuleOut(ctx, "out").String(),
1537 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1538 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1539 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001540 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001541 "bootclasspathArgs": bootclasspathArgs,
1542 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001543 "sourcepathArgs": sourcepathArgs,
1544 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001545 },
1546 })
1547}
1548
Nan Zhang1598a9e2018-09-04 17:14:32 -07001549func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1550 apiFile, removedApiFile android.Path, implicits android.Paths,
1551 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001552 output android.WritablePath) {
1553 ctx.Build(pctx, android.BuildParams{
1554 Rule: metalavaApiCheck,
1555 Description: "Metalava Check API",
1556 Output: output,
1557 Inputs: d.Javadoc.srcFiles,
1558 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1559 implicits...),
1560 Args: map[string]string{
1561 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1562 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1563 "javaVersion": javaVersion,
1564 "bootclasspathArgs": bootclasspathArgs,
1565 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001566 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001567 "opts": opts,
1568 "msg": msg,
1569 },
1570 })
1571}
1572
Nan Zhang71bbe632018-09-17 14:32:21 -07001573func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1574 implicitOutputs android.WritablePaths,
1575 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1576 ctx.Build(pctx, android.BuildParams{
1577 Rule: javadoc,
1578 Description: "Jdiff",
1579 Output: d.jdiffStubsSrcJar,
1580 Inputs: d.Javadoc.srcFiles,
1581 Implicits: implicits,
1582 ImplicitOutputs: implicitOutputs,
1583 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001584 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1585 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1586 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001587 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1588 "opts": opts,
1589 "bootclasspathArgs": bootclasspathArgs,
1590 "classpathArgs": classpathArgs,
1591 "sourcepathArgs": sourcepathArgs,
1592 "docZip": d.jdiffDocZip.String(),
1593 },
1594 })
1595}
1596
Nan Zhang1598a9e2018-09-04 17:14:32 -07001597func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001598 deps := d.Javadoc.collectDeps(ctx)
1599
1600 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001601
Nan Zhanga40da042018-08-01 12:48:00 -07001602 var implicits android.Paths
1603 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001604 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001605
1606 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001607 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001608 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1609 }
1610
1611 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001612 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001613 jdiffImplicits := implicits
1614
Nan Zhanga40da042018-08-01 12:48:00 -07001615 if err != nil {
1616 return
1617 }
1618
Nan Zhang1598a9e2018-09-04 17:14:32 -07001619 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1620 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001621 flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001622 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001623 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1624
Nan Zhang1598a9e2018-09-04 17:14:32 -07001625 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1626 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1627 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1628 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1629 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001630 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001631 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1632 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001633 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001634 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001635
Nan Zhang1598a9e2018-09-04 17:14:32 -07001636 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1637 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001638 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1639 "check_api.current.api_file")
1640 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1641 "check_api.current_removed_api_file")
1642
Nan Zhang2760dfc2018-08-24 17:32:54 +00001643 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001644 opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1645 " --check-compatibility:removed:current " + removedApiFile.String() +
1646 flags.metalavaInclusionAnnotationsFlags
Nan Zhang2760dfc2018-08-24 17:32:54 +00001647
Nan Zhang1598a9e2018-09-04 17:14:32 -07001648 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1649 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1650 fmt.Sprintf(`\n******************************\n`+
1651 `You have tried to change the API from what has been previously approved.\n\n`+
1652 `To make these errors go away, you have two choices:\n`+
1653 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1654 ` errors above.\n\n`+
1655 ` 2. You can update current.txt by executing the following command:\n`+
1656 ` make %s-update-current-api\n\n`+
1657 ` To submit the revised current.txt to the main Android repository,\n`+
1658 ` you will need approval.\n`+
1659 `******************************\n`, ctx.ModuleName()),
1660 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001661
1662 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001663 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1664 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001665 }
Nan Zhanga40da042018-08-01 12:48:00 -07001666
Nan Zhang1598a9e2018-09-04 17:14:32 -07001667 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1668 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001669 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1670 "check_api.last_released.api_file")
1671 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1672 "check_api.last_released.removed_api_file")
1673
Nan Zhang2760dfc2018-08-24 17:32:54 +00001674 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001675 opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1676 flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " +
1677 removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001678
Nan Zhang1598a9e2018-09-04 17:14:32 -07001679 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1680 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1681 `\n******************************\n`+
1682 `You have tried to change the API from what has been previously released in\n`+
1683 `an SDK. Please fix the errors listed above.\n`+
1684 `******************************\n`,
1685 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001686 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001687
1688 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1689
Nan Zhang86b06202018-09-21 17:09:21 -07001690 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1691 // since there's cron job downstream that fetch this .zip file periodically.
1692 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001693 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1694 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1695
1696 var jdiffImplicitOutputs android.WritablePaths
1697 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1698
1699 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1700 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1701
1702 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1703 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1704 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1705 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1706 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1707 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1708
1709 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1710 flags.sourcepathArgs, opts)
1711 }
Nan Zhang581fd212018-01-10 16:06:12 -08001712}
Dan Willemsencc090972018-02-26 14:33:31 -08001713
Nan Zhanga40da042018-08-01 12:48:00 -07001714//
Nan Zhangf4936b02018-08-01 15:00:28 -07001715// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001716//
Dan Willemsencc090972018-02-26 14:33:31 -08001717var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001718var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001719var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001720var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001721
Nan Zhangf4936b02018-08-01 15:00:28 -07001722type ExportedDroiddocDirProperties struct {
1723 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001724 Path *string
1725}
1726
Nan Zhangf4936b02018-08-01 15:00:28 -07001727type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001728 android.ModuleBase
1729
Nan Zhangf4936b02018-08-01 15:00:28 -07001730 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001731
1732 deps android.Paths
1733 dir android.Path
1734}
1735
Nan Zhangf4936b02018-08-01 15:00:28 -07001736func ExportedDroiddocDirFactory() android.Module {
1737 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001738 module.AddProperties(&module.properties)
1739 android.InitAndroidModule(module)
1740 return module
1741}
1742
Nan Zhangf4936b02018-08-01 15:00:28 -07001743func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001744
Nan Zhangf4936b02018-08-01 15:00:28 -07001745func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001746 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1747 d.dir = path
1748 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1749}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001750
1751//
1752// Defaults
1753//
1754type DocDefaults struct {
1755 android.ModuleBase
1756 android.DefaultsModuleBase
1757}
1758
1759func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1760}
1761
1762func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1763}
1764
1765func DocDefaultsFactory() android.Module {
1766 module := &DocDefaults{}
1767
1768 module.AddProperties(
1769 &JavadocProperties{},
1770 &DroiddocProperties{},
1771 )
1772
1773 android.InitDefaultsModule(module)
1774
1775 return module
1776}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001777
1778func StubsDefaultsFactory() android.Module {
1779 module := &DocDefaults{}
1780
1781 module.AddProperties(
1782 &JavadocProperties{},
1783 &DroidstubsProperties{},
1784 )
1785
1786 android.InitDefaultsModule(module)
1787
1788 return module
1789}