blob: bfe72f6876611a2d72190ab245adaa6218125f8d [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 Zhangaf322cc2018-06-19 15:15:38 -070033 `${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 },
43 Rspfile: "$out.rsp",
44 RspfileContent: "$in",
45 Restat: true,
46 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070047 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang1598a9e2018-09-04 17:14:32 -070048 "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070049
50 apiCheck = pctx.AndroidStaticRule("apiCheck",
51 blueprint.RuleParams{
52 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
53 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090054 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070055 CommandDeps: []string{
56 "${config.ApiCheckCmd}",
57 },
58 },
59 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
60
61 updateApi = pctx.AndroidStaticRule("updateApi",
62 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070063 Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` +
Nan Zhang61819ce2018-05-04 18:49:16 -070064 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
65 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070066 "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile")
Nan Zhang79614d12018-04-19 18:03:39 -070067
68 metalava = pctx.AndroidStaticRule("metalava",
69 blueprint.RuleParams{
Nan Zhang1598a9e2018-09-04 17:14:32 -070070 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
71 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070072 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070073 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070074 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
75 `$opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070076 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
77 CommandDeps: []string{
78 "${config.ZipSyncCmd}",
79 "${config.JavaCmd}",
80 "${config.MetalavaJar}",
Nan Zhang79614d12018-04-19 18:03:39 -070081 "${config.SoongZipCmd}",
82 },
83 Rspfile: "$out.rsp",
84 RspfileContent: "$in",
85 Restat: true,
86 },
Nan Zhang1598a9e2018-09-04 17:14:32 -070087 "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
88 "classpathArgs", "sourcepathArgs", "opts")
Nan Zhang2760dfc2018-08-24 17:32:54 +000089
90 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
91 blueprint.RuleParams{
92 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
93 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
94 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang1598a9e2018-09-04 17:14:32 -070095 `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` +
Nan Zhang2760dfc2018-08-24 17:32:54 +000096 `$opts && touch $out ) || ` +
97 `( echo -e "$msg" ; exit 38 )`,
98 CommandDeps: []string{
99 "${config.ZipSyncCmd}",
100 "${config.JavaCmd}",
101 "${config.MetalavaJar}",
102 },
103 Rspfile: "$out.rsp",
104 RspfileContent: "$in",
105 },
Nan Zhang1598a9e2018-09-04 17:14:32 -0700106 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg")
107
108 dokka = pctx.AndroidStaticRule("dokka",
109 blueprint.RuleParams{
110 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` +
111 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
112 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
113 `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` +
114 `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` +
115 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
116 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
117 CommandDeps: []string{
118 "${config.ZipSyncCmd}",
119 "${config.DokkaJar}",
120 "${config.MetalavaJar}",
121 "${config.SoongZipCmd}",
122 },
123 Restat: true,
124 },
125 "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -0800126)
127
128func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800129 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700130 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800131
Nan Zhang581fd212018-01-10 16:06:12 -0800132 android.RegisterModuleType("droiddoc", DroiddocFactory)
133 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700134 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800135 android.RegisterModuleType("javadoc", JavadocFactory)
136 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700137
138 android.RegisterModuleType("droidstubs", DroidstubsFactory)
139 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800140}
141
Colin Crossa1ce2a02018-06-20 15:19:39 -0700142var (
143 srcsLibTag = dependencyTag{name: "sources from javalib"}
144)
145
Nan Zhang581fd212018-01-10 16:06:12 -0800146type JavadocProperties struct {
147 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
148 // or .aidl files.
149 Srcs []string `android:"arch_variant"`
150
151 // list of directories rooted at the Android.bp file that will
152 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800153 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800154
155 // list of source files that should not be used to build the Java module.
156 // This is most useful in the arch/multilib variants to remove non-common files
157 // filegroup or genrule can be included within this property.
158 Exclude_srcs []string `android:"arch_variant"`
159
Nan Zhangb2b33de2018-02-23 11:18:47 -0800160 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800161 Libs []string `android:"arch_variant"`
162
Nan Zhang5994b622018-09-21 16:39:51 -0700163 // don't build against the default libraries (bootclasspath, legacy-test, core-junit,
164 // ext, and framework for device targets)
165 No_standard_libs *bool
166
Nan Zhange66c7272018-03-06 12:59:27 -0800167 // don't build against the framework libraries (legacy-test, core-junit,
168 // ext, and framework for device targets)
169 No_framework_libs *bool
170
Nan Zhangb2b33de2018-02-23 11:18:47 -0800171 // the java library (in classpath) for documentation that provides java srcs and srcjars.
172 Srcs_lib *string
173
174 // the base dirs under srcs_lib will be scanned for java srcs.
175 Srcs_lib_whitelist_dirs []string
176
177 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
178 Srcs_lib_whitelist_pkgs []string
179
Nan Zhang581fd212018-01-10 16:06:12 -0800180 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800181 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800182
183 // if not blank, set to the version of the sdk to compile against
184 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900185
186 Aidl struct {
187 // Top level directories to pass to aidl tool
188 Include_dirs []string
189
190 // Directories rooted at the Android.bp file to pass to aidl tool
191 Local_include_dirs []string
192 }
Nan Zhang357466b2018-04-17 17:38:36 -0700193
194 // If not blank, set the java version passed to javadoc as -source
195 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700196
197 // local files that are used within user customized droiddoc options.
198 Arg_files []string
199
200 // user customized droiddoc args.
201 // Available variables for substitution:
202 //
203 // $(location <label>): the path to the arg_files with name <label>
204 Args *string
205
206 // names of the output files used in args that will be generated
207 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800208}
209
Nan Zhang61819ce2018-05-04 18:49:16 -0700210type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900211 // path to the API txt file that the new API extracted from source code is checked
212 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700213 Api_file *string
214
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900215 // path to the API txt file that the new @removed API extractd from source code is
216 // checked against. The path can be local to the module or from other module (via
217 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700218 Removed_api_file *string
219
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900220 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700221 Args *string
222}
223
Nan Zhang581fd212018-01-10 16:06:12 -0800224type DroiddocProperties struct {
225 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800226 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800227
Nan Zhanga40da042018-08-01 12:48:00 -0700228 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800229 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800230
231 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800232 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800233
234 // proofread file contains all of the text content of the javadocs concatenated into one file,
235 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800237
238 // a todo file lists the program elements that are missing documentation.
239 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800240 Todo_file *string
241
242 // directory under current module source that provide additional resources (images).
243 Resourcesdir *string
244
245 // resources output directory under out/soong/.intermediates.
246 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800247
Nan Zhange2ba5d42018-07-11 15:16:55 -0700248 // if set to true, collect the values used by the Dev tools and
249 // write them in files packaged with the SDK. Defaults to false.
250 Write_sdk_values *bool
251
252 // index.html under current module will be copied to docs out dir, if not null.
253 Static_doc_index_redirect *string
254
255 // source.properties under current module will be copied to docs out dir, if not null.
256 Static_doc_properties *string
257
Nan Zhang581fd212018-01-10 16:06:12 -0800258 // a list of files under current module source dir which contains known tags in Java sources.
259 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800260 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700261
262 // the tag name used to distinguish if the API files belong to public/system/test.
263 Api_tag_name *string
264
265 // the generated public API filename by Doclava.
266 Api_filename *string
267
David Brazdilfbe4cc32018-05-31 13:56:46 +0100268 // the generated public Dex API filename by Doclava.
269 Dex_api_filename *string
270
Nan Zhang28c68b92018-03-13 16:17:01 -0700271 // the generated private API filename by Doclava.
272 Private_api_filename *string
273
274 // the generated private Dex API filename by Doclava.
275 Private_dex_api_filename *string
276
277 // the generated removed API filename by Doclava.
278 Removed_api_filename *string
279
David Brazdilaac0c3c2018-04-24 16:23:29 +0100280 // the generated removed Dex API filename by Doclava.
281 Removed_dex_api_filename *string
282
Mathew Inwood76c3de12018-06-22 15:28:11 +0100283 // mapping of dex signatures to source file and line number. This is a temporary property and
284 // will be deleted; you probably shouldn't be using it.
285 Dex_mapping_filename *string
286
Nan Zhang28c68b92018-03-13 16:17:01 -0700287 // the generated exact API filename by Doclava.
288 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700289
Nan Zhang66dc2362018-08-14 20:41:04 -0700290 // the generated proguard filename by Doclava.
291 Proguard_filename *string
292
Nan Zhang853f4202018-04-12 16:55:56 -0700293 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
294 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700295
296 Check_api struct {
297 Last_released ApiToCheck
298
299 Current ApiToCheck
300 }
Nan Zhang79614d12018-04-19 18:03:39 -0700301
Nan Zhang1598a9e2018-09-04 17:14:32 -0700302 // if set to true, generate docs through Dokka instead of Doclava.
303 Dokka_enabled *bool
304}
305
306type DroidstubsProperties struct {
307 // the tag name used to distinguish if the API files belong to public/system/test.
308 Api_tag_name *string
309
Nan Zhang199645c2018-09-19 12:40:06 -0700310 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700311 Api_filename *string
312
Nan Zhang199645c2018-09-19 12:40:06 -0700313 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700314 Dex_api_filename *string
315
Nan Zhang199645c2018-09-19 12:40:06 -0700316 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700317 Private_api_filename *string
318
Nan Zhang199645c2018-09-19 12:40:06 -0700319 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700320 Private_dex_api_filename *string
321
Nan Zhang199645c2018-09-19 12:40:06 -0700322 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700323 Removed_api_filename *string
324
Nan Zhang199645c2018-09-19 12:40:06 -0700325 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700326 Removed_dex_api_filename *string
327
Nan Zhang9c69a122018-08-22 10:22:08 -0700328 // mapping of dex signatures to source file and line number. This is a temporary property and
329 // will be deleted; you probably shouldn't be using it.
330 Dex_mapping_filename *string
331
Nan Zhang199645c2018-09-19 12:40:06 -0700332 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700333 Exact_api_filename *string
334
Nan Zhang199645c2018-09-19 12:40:06 -0700335 // the generated proguard filename by Metalava.
336 Proguard_filename *string
337
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338 Check_api struct {
339 Last_released ApiToCheck
340
341 Current ApiToCheck
342 }
Nan Zhang79614d12018-04-19 18:03:39 -0700343
344 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700345 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700346
347 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700348 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700349
Pete Gillin77167902018-09-19 18:16:26 +0100350 // 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 -0700351 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700352
Pete Gillin77167902018-09-19 18:16:26 +0100353 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
354 Merge_inclusion_annotations_dirs []string
355
Nan Zhang1598a9e2018-09-04 17:14:32 -0700356 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
357 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700358
359 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
360 Api_levels_annotations_enabled *bool
361
362 // the dirs which Metalava extracts API levels annotations from.
363 Api_levels_annotations_dirs []string
364
365 // if set to true, collect the values used by the Dev tools and
366 // write them in files packaged with the SDK. Defaults to false.
367 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700368
369 // If set to true, .xml based public API file will be also generated, and
370 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
371 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800372}
373
Nan Zhanga40da042018-08-01 12:48:00 -0700374//
375// Common flags passed down to build rule
376//
377type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700378 bootClasspathArgs string
379 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700380 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700381 dokkaClasspathArgs string
382 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700383
Nan Zhanga40da042018-08-01 12:48:00 -0700384 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700385 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700386 postDoclavaCmds string
387
Nan Zhang9c69a122018-08-22 10:22:08 -0700388 metalavaStubsFlags string
389 metalavaAnnotationsFlags string
390 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700391
Nan Zhang71bbe632018-09-17 14:32:21 -0700392 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700393}
394
395func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
396 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
397 android.InitDefaultableModule(module)
398}
399
Nan Zhang1598a9e2018-09-04 17:14:32 -0700400func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
401 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
402 return true
403 } else if String(apiToCheck.Api_file) != "" {
404 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
405 } else if String(apiToCheck.Removed_api_file) != "" {
406 panic("for " + apiVersionTag + " api_file has to be non-empty!")
407 }
408
409 return false
410}
411
412type ApiFilePath interface {
413 ApiFilePath() android.Path
414}
415
416func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
417 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
418 ctx.Build(pctx, android.BuildParams{
419 Rule: updateApi,
420 Description: "Update API",
421 Output: output,
422 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
423 destApiFile, destRemovedApiFile),
424 Args: map[string]string{
425 "destApiFile": destApiFile.String(),
426 "srcApiFile": srcApiFile.String(),
427 "destRemovedApiFile": destRemovedApiFile.String(),
428 "srcRemovedApiFile": srcRemovedApiFile.String(),
429 },
430 })
431}
432
Nan Zhanga40da042018-08-01 12:48:00 -0700433//
434// Javadoc
435//
Nan Zhang581fd212018-01-10 16:06:12 -0800436type Javadoc struct {
437 android.ModuleBase
438 android.DefaultableModuleBase
439
440 properties JavadocProperties
441
442 srcJars android.Paths
443 srcFiles android.Paths
444 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700445 argFiles android.Paths
446
447 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800448
Nan Zhangccff0f72018-03-08 17:26:16 -0800449 docZip android.WritablePath
450 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800451}
452
Nan Zhangb2b33de2018-02-23 11:18:47 -0800453func (j *Javadoc) Srcs() android.Paths {
454 return android.Paths{j.stubsSrcJar}
455}
456
Nan Zhang581fd212018-01-10 16:06:12 -0800457func JavadocFactory() android.Module {
458 module := &Javadoc{}
459
460 module.AddProperties(&module.properties)
461
462 InitDroiddocModule(module, android.HostAndDeviceSupported)
463 return module
464}
465
466func JavadocHostFactory() android.Module {
467 module := &Javadoc{}
468
469 module.AddProperties(&module.properties)
470
471 InitDroiddocModule(module, android.HostSupported)
472 return module
473}
474
Nan Zhanga40da042018-08-01 12:48:00 -0700475var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800476
Colin Cross83bb3162018-06-25 15:48:06 -0700477func (j *Javadoc) sdkVersion() string {
478 return String(j.properties.Sdk_version)
479}
480
481func (j *Javadoc) minSdkVersion() string {
482 return j.sdkVersion()
483}
484
Nan Zhang581fd212018-01-10 16:06:12 -0800485func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
486 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700487 if !Bool(j.properties.No_standard_libs) {
488 sdkDep := decodeSdkDep(ctx, sdkContext(j))
489 if sdkDep.useDefaultLibs {
490 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
491 if ctx.Config().TargetOpenJDK9() {
492 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
493 }
494 if !Bool(j.properties.No_framework_libs) {
495 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
496 }
497 } else if sdkDep.useModule {
498 if ctx.Config().TargetOpenJDK9() {
499 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
500 }
501 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700502 }
Nan Zhang581fd212018-01-10 16:06:12 -0800503 }
504 }
505
Colin Cross42d48b72018-08-29 14:10:52 -0700506 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700507 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700508 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700509 }
Nan Zhang581fd212018-01-10 16:06:12 -0800510
511 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
512
513 // exclude_srcs may contain filegroup or genrule.
514 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700515
516 // arg_files may contains filegroup or genrule.
517 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800518}
519
Nan Zhangb2b33de2018-02-23 11:18:47 -0800520func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
521 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
522 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900523 // convert foo.bar.baz to foo/bar/baz
524 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
525 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800526 if _, found := whitelistPathPrefixes[prefix]; !found {
527 whitelistPathPrefixes[prefix] = true
528 }
529 }
530 }
531}
532
Nan Zhanga40da042018-08-01 12:48:00 -0700533func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
534 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900535
536 // aidl flags.
537 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
538 if len(aidlFlags) > 0 {
539 // optimization.
540 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
541 flags.aidlFlags = "$aidlFlags"
542 }
543
544 return flags
545}
546
547func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
548 aidlIncludeDirs android.Paths) []string {
549
550 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
551 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
552
553 var flags []string
554 if aidlPreprocess.Valid() {
555 flags = append(flags, "-p"+aidlPreprocess.String())
556 } else {
557 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
558 }
559
560 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
561 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
562 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
563 flags = append(flags, "-I"+src.String())
564 }
565
566 return flags
567}
568
569func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700570 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900571
572 outSrcFiles := make(android.Paths, 0, len(srcFiles))
573
574 for _, srcFile := range srcFiles {
575 switch srcFile.Ext() {
576 case ".aidl":
577 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
578 outSrcFiles = append(outSrcFiles, javaFile)
579 default:
580 outSrcFiles = append(outSrcFiles, srcFile)
581 }
582 }
583
584 return outSrcFiles
585}
586
Nan Zhang581fd212018-01-10 16:06:12 -0800587func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
588 var deps deps
589
Colin Cross83bb3162018-06-25 15:48:06 -0700590 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800591 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700592 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800593 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700594 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800595 }
596
597 ctx.VisitDirectDeps(func(module android.Module) {
598 otherName := ctx.OtherModuleName(module)
599 tag := ctx.OtherModuleDependencyTag(module)
600
Colin Cross2d24c1b2018-05-23 10:59:18 -0700601 switch tag {
602 case bootClasspathTag:
603 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800604 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700605 } else {
606 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
607 }
608 case libTag:
609 switch dep := module.(type) {
610 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800611 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700612 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700613 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900614 linkType := javaSdk
615 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
616 linkType = javaSystem
617 } else if sdkVersion == "" {
618 linkType = javaPlatform
619 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900620 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700621 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800622 checkProducesJars(ctx, dep)
623 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800624 default:
625 ctx.ModuleErrorf("depends on non-java module %q", otherName)
626 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700627 case srcsLibTag:
628 switch dep := module.(type) {
629 case Dependency:
630 srcs := dep.(SrcDependency).CompiledSrcs()
631 whitelistPathPrefixes := make(map[string]bool)
632 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
633 for _, src := range srcs {
634 if _, ok := src.(android.WritablePath); ok { // generated sources
635 deps.srcs = append(deps.srcs, src)
636 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700637 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700638 if strings.HasPrefix(src.Rel(), k) {
639 deps.srcs = append(deps.srcs, src)
640 break
641 }
642 }
643 }
644 }
645 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
646 default:
647 ctx.ModuleErrorf("depends on non-java module %q", otherName)
648 }
Nan Zhang357466b2018-04-17 17:38:36 -0700649 case systemModulesTag:
650 if deps.systemModules != nil {
651 panic("Found two system module dependencies")
652 }
653 sm := module.(*SystemModules)
654 if sm.outputFile == nil {
655 panic("Missing directory for system module dependency")
656 }
657 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800658 }
659 })
660 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
661 // may contain filegroup or genrule.
662 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700663 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900664 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800665
666 // srcs may depend on some genrule output.
667 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800668 j.srcJars = append(j.srcJars, deps.srcJars...)
669
Nan Zhang581fd212018-01-10 16:06:12 -0800670 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800671 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800672
673 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800674 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800675
Nan Zhang9c69a122018-08-22 10:22:08 -0700676 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800677 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
678 }
679 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800680
Nan Zhang1598a9e2018-09-04 17:14:32 -0700681 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
682 argFilesMap := map[string]android.Path{}
683
684 for _, f := range j.argFiles {
685 if _, exists := argFilesMap[f.Rel()]; !exists {
686 argFilesMap[f.Rel()] = f
687 } else {
688 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
689 f, argFilesMap[f.Rel()], f.Rel())
690 }
691 }
692
693 var err error
694 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
695 if strings.HasPrefix(name, "location ") {
696 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
697 if f, ok := argFilesMap[label]; ok {
698 return f.String(), nil
699 } else {
700 return "", fmt.Errorf("unknown location label %q", label)
701 }
702 } else if name == "genDir" {
703 return android.PathForModuleGen(ctx).String(), nil
704 }
705 return "", fmt.Errorf("unknown variable '$(%s)'", name)
706 })
707
708 if err != nil {
709 ctx.PropertyErrorf("args", "%s", err.Error())
710 }
711
Nan Zhang581fd212018-01-10 16:06:12 -0800712 return deps
713}
714
715func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
716 j.addDeps(ctx)
717}
718
719func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
720 deps := j.collectDeps(ctx)
721
722 var implicits android.Paths
723 implicits = append(implicits, deps.bootClasspath...)
724 implicits = append(implicits, deps.classpath...)
725
Nan Zhang1598a9e2018-09-04 17:14:32 -0700726 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700727
Colin Cross83bb3162018-06-25 15:48:06 -0700728 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700729 if len(deps.bootClasspath) > 0 {
730 var systemModules classpath
731 if deps.systemModules != nil {
732 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800733 }
Colin Cross997262f2018-06-19 22:49:39 -0700734 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
735 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800736 }
737 if len(deps.classpath.Strings()) > 0 {
738 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
739 }
740
741 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700742 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800743
Nan Zhangaf322cc2018-06-19 15:15:38 -0700744 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800745
Nan Zhang1598a9e2018-09-04 17:14:32 -0700746 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
747
Nan Zhang581fd212018-01-10 16:06:12 -0800748 ctx.Build(pctx, android.BuildParams{
749 Rule: javadoc,
750 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800751 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800752 ImplicitOutput: j.docZip,
753 Inputs: j.srcFiles,
754 Implicits: implicits,
755 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700756 "outDir": android.PathForModuleOut(ctx, "out").String(),
757 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
758 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800759 "srcJars": strings.Join(j.srcJars.Strings(), " "),
760 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700761 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800762 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700763 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800764 "docZip": j.docZip.String(),
765 },
766 })
767}
768
Nan Zhanga40da042018-08-01 12:48:00 -0700769//
770// Droiddoc
771//
772type Droiddoc struct {
773 Javadoc
774
775 properties DroiddocProperties
776 apiFile android.WritablePath
777 dexApiFile android.WritablePath
778 privateApiFile android.WritablePath
779 privateDexApiFile android.WritablePath
780 removedApiFile android.WritablePath
781 removedDexApiFile android.WritablePath
782 exactApiFile android.WritablePath
783 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700784 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700785
786 checkCurrentApiTimestamp android.WritablePath
787 updateCurrentApiTimestamp android.WritablePath
788 checkLastReleasedApiTimestamp android.WritablePath
789
Nan Zhanga40da042018-08-01 12:48:00 -0700790 apiFilePath android.Path
791}
792
Nan Zhanga40da042018-08-01 12:48:00 -0700793func DroiddocFactory() android.Module {
794 module := &Droiddoc{}
795
796 module.AddProperties(&module.properties,
797 &module.Javadoc.properties)
798
799 InitDroiddocModule(module, android.HostAndDeviceSupported)
800 return module
801}
802
803func DroiddocHostFactory() android.Module {
804 module := &Droiddoc{}
805
806 module.AddProperties(&module.properties,
807 &module.Javadoc.properties)
808
809 InitDroiddocModule(module, android.HostSupported)
810 return module
811}
812
813func (d *Droiddoc) ApiFilePath() android.Path {
814 return d.apiFilePath
815}
816
Nan Zhang581fd212018-01-10 16:06:12 -0800817func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
818 d.Javadoc.addDeps(ctx)
819
Nan Zhang79614d12018-04-19 18:03:39 -0700820 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800821 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
822 }
823
Nan Zhang581fd212018-01-10 16:06:12 -0800824 // knowntags may contain filegroup or genrule.
825 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700826
Nan Zhange2ba5d42018-07-11 15:16:55 -0700827 if String(d.properties.Static_doc_index_redirect) != "" {
828 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
829 }
830
831 if String(d.properties.Static_doc_properties) != "" {
832 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
833 }
834
Nan Zhang1598a9e2018-09-04 17:14:32 -0700835 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700836 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
837 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
838 }
839
Nan Zhang1598a9e2018-09-04 17:14:32 -0700840 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700841 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
842 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
843 }
Nan Zhang581fd212018-01-10 16:06:12 -0800844}
845
Nan Zhang66dc2362018-08-14 20:41:04 -0700846func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
847 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700848 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800849
Nan Zhanga40da042018-08-01 12:48:00 -0700850 *implicits = append(*implicits, deps.bootClasspath...)
851 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800852
Nan Zhangc94f9d82018-06-26 10:02:26 -0700853 if len(deps.bootClasspath.Strings()) > 0 {
854 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700855 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700856 }
Nan Zhanga40da042018-08-01 12:48:00 -0700857 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700858 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700859 dokkaClasspath := classpath{}
860 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
861 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
862 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700863
Nan Zhang9c69a122018-08-22 10:22:08 -0700864 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
865 // based stubs generation.
866 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
867 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
868 // the correct package name base path.
869 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
870 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
871 } else {
872 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
873 }
Nan Zhang581fd212018-01-10 16:06:12 -0800874
Nan Zhanga40da042018-08-01 12:48:00 -0700875 return flags, nil
876}
Nan Zhang581fd212018-01-10 16:06:12 -0800877
Nan Zhanga40da042018-08-01 12:48:00 -0700878func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700879 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800880
Nan Zhanga40da042018-08-01 12:48:00 -0700881 *implicits = append(*implicits, jsilver)
882 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700883
Nan Zhang46130972018-06-04 11:28:01 -0700884 var date string
885 if runtime.GOOS == "darwin" {
886 date = `date -r`
887 } else {
888 date = `date -d`
889 }
890
Nan Zhang443fa522018-08-20 20:58:28 -0700891 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
892 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
893 // 1.9 language features.
894 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700895 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800896 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700897 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700898
Nan Zhanga40da042018-08-01 12:48:00 -0700899 if String(d.properties.Custom_template) == "" {
900 // TODO: This is almost always droiddoc-templates-sdk
901 ctx.PropertyErrorf("custom_template", "must specify a template")
902 }
903
904 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700905 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700906 *implicits = append(*implicits, t.deps...)
907 args = args + " -templatedir " + t.dir.String()
908 } else {
909 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
910 }
911 })
912
913 if len(d.properties.Html_dirs) > 0 {
914 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
915 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
916 args = args + " -htmldir " + htmlDir.String()
917 }
918
919 if len(d.properties.Html_dirs) > 1 {
920 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
921 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
922 args = args + " -htmldir2 " + htmlDir2.String()
923 }
924
925 if len(d.properties.Html_dirs) > 2 {
926 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
927 }
928
929 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
930 *implicits = append(*implicits, knownTags...)
931
932 for _, kt := range knownTags {
933 args = args + " -knowntags " + kt.String()
934 }
935
936 for _, hdf := range d.properties.Hdf {
937 args = args + " -hdf " + hdf
938 }
939
940 if String(d.properties.Proofread_file) != "" {
941 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
942 args = args + " -proofread " + proofreadFile.String()
943 }
944
945 if String(d.properties.Todo_file) != "" {
946 // tricky part:
947 // we should not compute full path for todo_file through PathForModuleOut().
948 // the non-standard doclet will get the full path relative to "-o".
949 args = args + " -todo " + String(d.properties.Todo_file)
950 }
951
952 if String(d.properties.Resourcesdir) != "" {
953 // TODO: should we add files under resourcesDir to the implicits? It seems that
954 // resourcesDir is one sub dir of htmlDir
955 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
956 args = args + " -resourcesdir " + resourcesDir.String()
957 }
958
959 if String(d.properties.Resourcesoutdir) != "" {
960 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
961 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
962 }
963 return args
964}
965
Nan Zhang1598a9e2018-09-04 17:14:32 -0700966func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
967 implicitOutputs *android.WritablePaths) string {
968 var doclavaFlags string
969 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
970 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
971 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700972 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
973 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700974 *implicitOutputs = append(*implicitOutputs, d.apiFile)
975 d.apiFilePath = d.apiFile
976 }
977
Nan Zhang1598a9e2018-09-04 17:14:32 -0700978 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
979 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
980 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700981 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
982 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700983 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
984 }
985
986 if String(d.properties.Private_api_filename) != "" {
987 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
988 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700989 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
990 }
991
992 if String(d.properties.Dex_api_filename) != "" {
993 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
994 doclavaFlags += " -dexApi " + d.dexApiFile.String()
995 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
996 }
997
998 if String(d.properties.Private_dex_api_filename) != "" {
999 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1000 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001001 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1002 }
1003
1004 if String(d.properties.Removed_dex_api_filename) != "" {
1005 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1006 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001007 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1008 }
1009
1010 if String(d.properties.Exact_api_filename) != "" {
1011 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1012 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001013 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1014 }
1015
1016 if String(d.properties.Dex_mapping_filename) != "" {
1017 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1018 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001019 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1020 }
1021
Nan Zhang66dc2362018-08-14 20:41:04 -07001022 if String(d.properties.Proguard_filename) != "" {
1023 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1024 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001025 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1026 }
1027
Nan Zhanga40da042018-08-01 12:48:00 -07001028 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001029 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001030 }
1031
1032 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001033 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001034 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001035
1036 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001037}
1038
1039func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1040 var cmds string
1041 if String(d.properties.Static_doc_index_redirect) != "" {
1042 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1043 "static_doc_index_redirect")
1044 *implicits = append(*implicits, static_doc_index_redirect)
1045 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001046 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001047 }
1048
1049 if String(d.properties.Static_doc_properties) != "" {
1050 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1051 "static_doc_properties")
1052 *implicits = append(*implicits, static_doc_properties)
1053 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001054 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001055 }
1056 return cmds
1057}
1058
Nan Zhang1598a9e2018-09-04 17:14:32 -07001059func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1060 implicitOutputs android.WritablePaths,
1061 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1062 ctx.Build(pctx, android.BuildParams{
1063 Rule: javadoc,
1064 Description: "Doclava",
1065 Output: d.Javadoc.stubsSrcJar,
1066 Inputs: d.Javadoc.srcFiles,
1067 Implicits: implicits,
1068 ImplicitOutputs: implicitOutputs,
1069 Args: map[string]string{
1070 "outDir": android.PathForModuleOut(ctx, "out").String(),
1071 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1072 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1073 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1074 "opts": opts,
1075 "bootclasspathArgs": bootclasspathArgs,
1076 "classpathArgs": classpathArgs,
1077 "sourcepathArgs": sourcepathArgs,
1078 "docZip": d.Javadoc.docZip.String(),
1079 "postDoclavaCmds": postDoclavaCmds,
1080 },
1081 })
1082}
1083
1084func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1085 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1086 ctx.Build(pctx, android.BuildParams{
1087 Rule: apiCheck,
1088 Description: "Doclava Check API",
1089 Output: output,
1090 Inputs: nil,
1091 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1092 checkApiClasspath...),
1093 Args: map[string]string{
1094 "msg": msg,
1095 "classpath": checkApiClasspath.FormJavaClassPath(""),
1096 "opts": opts,
1097 "apiFile": apiFile.String(),
1098 "apiFileToCheck": d.apiFile.String(),
1099 "removedApiFile": removedApiFile.String(),
1100 "removedApiFileToCheck": d.removedApiFile.String(),
1101 },
1102 })
1103}
1104
1105func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1106 classpathArgs, opts string) {
1107 ctx.Build(pctx, android.BuildParams{
1108 Rule: dokka,
1109 Description: "Dokka",
1110 Output: d.Javadoc.stubsSrcJar,
1111 Inputs: d.Javadoc.srcFiles,
1112 Implicits: implicits,
1113 Args: map[string]string{
1114 "outDir": android.PathForModuleOut(ctx, "out").String(),
1115 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1116 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1117 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1118 "classpathArgs": classpathArgs,
1119 "opts": opts,
1120 "docZip": d.Javadoc.docZip.String(),
1121 },
1122 })
1123}
1124
1125func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1126 deps := d.Javadoc.collectDeps(ctx)
1127
1128 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1129 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1130 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1131 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1132
1133 var implicits android.Paths
1134 implicits = append(implicits, d.Javadoc.srcJars...)
1135 implicits = append(implicits, d.Javadoc.argFiles...)
1136
1137 var implicitOutputs android.WritablePaths
1138 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1139 for _, o := range d.Javadoc.properties.Out {
1140 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1141 }
1142
1143 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1144 if err != nil {
1145 return
1146 }
1147
1148 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1149 if Bool(d.properties.Dokka_enabled) {
1150 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1151 } else {
1152 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1153 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1154 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1155 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1156 flags.postDoclavaCmds)
1157 }
1158
1159 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1160 !ctx.Config().IsPdkBuild() {
1161 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1162 "check_api.current.api_file")
1163 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1164 "check_api.current_removed_api_file")
1165
1166 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1167 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1168 fmt.Sprintf(`\n******************************\n`+
1169 `You have tried to change the API from what has been previously approved.\n\n`+
1170 `To make these errors go away, you have two choices:\n`+
1171 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1172 ` errors above.\n\n`+
1173 ` 2. You can update current.txt by executing the following command:\n`+
1174 ` make %s-update-current-api\n\n`+
1175 ` To submit the revised current.txt to the main Android repository,\n`+
1176 ` you will need approval.\n`+
1177 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1178 d.checkCurrentApiTimestamp)
1179
1180 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1181 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1182 d.updateCurrentApiTimestamp)
1183 }
1184
1185 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1186 !ctx.Config().IsPdkBuild() {
1187 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1188 "check_api.last_released.api_file")
1189 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1190 "check_api.last_released.removed_api_file")
1191
1192 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1193 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1194 `\n******************************\n`+
1195 `You have tried to change the API from what has been previously released in\n`+
1196 `an SDK. Please fix the errors listed above.\n`+
1197 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1198 d.checkLastReleasedApiTimestamp)
1199 }
1200}
1201
1202//
1203// Droidstubs
1204//
1205type Droidstubs struct {
1206 Javadoc
1207
Nan Zhang71bbe632018-09-17 14:32:21 -07001208 properties DroidstubsProperties
1209 apiFile android.WritablePath
1210 apiXmlFile android.WritablePath
1211 lastReleasedApiXmlFile android.WritablePath
1212 dexApiFile android.WritablePath
1213 privateApiFile android.WritablePath
1214 privateDexApiFile android.WritablePath
1215 removedApiFile android.WritablePath
1216 removedDexApiFile android.WritablePath
1217 apiMappingFile android.WritablePath
1218 exactApiFile android.WritablePath
Nan Zhang199645c2018-09-19 12:40:06 -07001219 proguardFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001220
1221 checkCurrentApiTimestamp android.WritablePath
1222 updateCurrentApiTimestamp android.WritablePath
1223 checkLastReleasedApiTimestamp android.WritablePath
1224
1225 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001226 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001227
1228 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001229
1230 jdiffDocZip android.WritablePath
1231 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001232}
1233
1234func DroidstubsFactory() android.Module {
1235 module := &Droidstubs{}
1236
1237 module.AddProperties(&module.properties,
1238 &module.Javadoc.properties)
1239
1240 InitDroiddocModule(module, android.HostAndDeviceSupported)
1241 return module
1242}
1243
1244func DroidstubsHostFactory() android.Module {
1245 module := &Droidstubs{}
1246
1247 module.AddProperties(&module.properties,
1248 &module.Javadoc.properties)
1249
1250 InitDroiddocModule(module, android.HostSupported)
1251 return module
1252}
1253
1254func (d *Droidstubs) ApiFilePath() android.Path {
1255 return d.apiFilePath
1256}
1257
1258func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1259 d.Javadoc.addDeps(ctx)
1260
1261 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1262 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1263 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1264 }
1265
1266 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1267 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1268 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1269 }
1270
1271 if String(d.properties.Previous_api) != "" {
1272 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1273 }
1274
1275 if len(d.properties.Merge_annotations_dirs) != 0 {
1276 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1277 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1278 }
1279 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001280
Pete Gillin77167902018-09-19 18:16:26 +01001281 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1282 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1283 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1284 }
1285 }
1286
Nan Zhang9c69a122018-08-22 10:22:08 -07001287 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1288 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1289 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1290 }
1291 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001292}
1293
1294func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1295 deps deps) (droiddocBuilderFlags, error) {
1296 var flags droiddocBuilderFlags
1297
1298 *implicits = append(*implicits, deps.bootClasspath...)
1299 *implicits = append(*implicits, deps.classpath...)
1300
1301 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1302 // since it doesn't support system modules yet.
1303 if len(deps.bootClasspath.Strings()) > 0 {
1304 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1305 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1306 }
1307 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1308
1309 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1310
1311 return flags, nil
1312}
1313
1314func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1315 implicitOutputs *android.WritablePaths) string {
1316 var metalavaFlags string
1317 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1318 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1319 String(d.properties.Api_filename) != "" {
1320 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1321 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1322 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1323 d.apiFilePath = d.apiFile
1324 }
1325
1326 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1327 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1328 String(d.properties.Removed_api_filename) != "" {
1329 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1330 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1331 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1332 }
1333
1334 if String(d.properties.Private_api_filename) != "" {
1335 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1336 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1337 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1338 }
1339
1340 if String(d.properties.Dex_api_filename) != "" {
1341 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1342 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1343 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1344 }
1345
1346 if String(d.properties.Private_dex_api_filename) != "" {
1347 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1348 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1349 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1350 }
1351
1352 if String(d.properties.Removed_dex_api_filename) != "" {
1353 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1354 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1355 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1356 }
1357
1358 if String(d.properties.Exact_api_filename) != "" {
1359 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1360 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1361 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1362 }
1363
Nan Zhang9c69a122018-08-22 10:22:08 -07001364 if String(d.properties.Dex_mapping_filename) != "" {
1365 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1366 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1367 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1368 }
1369
Nan Zhang199645c2018-09-19 12:40:06 -07001370 if String(d.properties.Proguard_filename) != "" {
1371 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1372 metalavaFlags += " --proguard " + d.proguardFile.String()
1373 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1374 }
1375
Nan Zhang9c69a122018-08-22 10:22:08 -07001376 if Bool(d.properties.Write_sdk_values) {
1377 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1378 }
1379
Nan Zhang1598a9e2018-09-04 17:14:32 -07001380 if Bool(d.properties.Create_doc_stubs) {
1381 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1382 } else {
1383 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1384 }
1385
1386 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) {
1393 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001394 ctx.PropertyErrorf("metalava_previous_api",
1395 "has to be non-empty if annotations was enabled!")
1396 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001397 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001398 "metalava_previous_api")
1399 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001400
Nan Zhangd05a4362018-08-15 13:28:54 -07001401 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001402
1403 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1404 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1405
Nan Zhangf4936b02018-08-01 15:00:28 -07001406 flags += " --extract-annotations " + d.annotationsZip.String()
1407
Nan Zhang1598a9e2018-09-04 17:14:32 -07001408 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001409 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001410 "has to be non-empty if annotations was enabled!")
1411 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001412 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1413 if t, ok := m.(*ExportedDroiddocDir); ok {
1414 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001415 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001416 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001417 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001418 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1419 }
1420 })
Nan Zhanga40da042018-08-01 12:48:00 -07001421 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1422 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1423 }
Pete Gillin77167902018-09-19 18:16:26 +01001424 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1425 if t, ok := m.(*ExportedDroiddocDir); ok {
1426 *implicits = append(*implicits, t.deps...)
1427 flags += " --merge-inclusion-annotations " + t.dir.String()
1428 } else {
1429 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1430 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1431 }
1432 })
Nan Zhanga40da042018-08-01 12:48:00 -07001433
1434 return flags
1435}
1436
Nan Zhang9c69a122018-08-22 10:22:08 -07001437func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1438 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1439 var flags string
1440 if Bool(d.properties.Api_levels_annotations_enabled) {
1441 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1442 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1443
1444 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1445 ctx.PropertyErrorf("api_levels_annotations_dirs",
1446 "has to be non-empty if api levels annotations was enabled!")
1447 }
1448
1449 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1450 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1451 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1452
1453 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1454 if t, ok := m.(*ExportedDroiddocDir); ok {
1455 var androidJars android.Paths
1456 for _, dep := range t.deps {
1457 if strings.HasSuffix(dep.String(), "android.jar") {
1458 androidJars = append(androidJars, dep)
1459 }
1460 }
1461 *implicits = append(*implicits, androidJars...)
1462 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1463 } else {
1464 ctx.PropertyErrorf("api_levels_annotations_dirs",
1465 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1466 }
1467 })
1468
1469 }
1470
1471 return flags
1472}
1473
Nan Zhang71bbe632018-09-17 14:32:21 -07001474func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1475 implicitOutputs *android.WritablePaths) string {
1476 var flags string
1477 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1478 if d.apiFile.String() == "" {
1479 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1480 }
1481
1482 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1483 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1484
1485 flags = " --api-xml " + d.apiXmlFile.String()
1486
1487 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1488 ctx.PropertyErrorf("check_api.last_released.api_file",
1489 "has to be non-empty if jdiff was enabled!")
1490 }
1491 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1492 "check_api.last_released.api_file")
1493 *implicits = append(*implicits, lastReleasedApi)
1494
1495 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1496 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1497
1498 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1499 d.lastReleasedApiXmlFile.String()
1500 }
1501
1502 return flags
1503}
1504
Nan Zhang1598a9e2018-09-04 17:14:32 -07001505func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1506 implicitOutputs android.WritablePaths, javaVersion,
1507 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001508
Nan Zhang86d2d552018-08-09 15:33:27 -07001509 ctx.Build(pctx, android.BuildParams{
1510 Rule: metalava,
1511 Description: "Metalava",
1512 Output: d.Javadoc.stubsSrcJar,
1513 Inputs: d.Javadoc.srcFiles,
1514 Implicits: implicits,
1515 ImplicitOutputs: implicitOutputs,
1516 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001517 "outDir": android.PathForModuleOut(ctx, "out").String(),
1518 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1519 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1520 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001521 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001522 "bootclasspathArgs": bootclasspathArgs,
1523 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001524 "sourcepathArgs": sourcepathArgs,
1525 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001526 },
1527 })
1528}
1529
Nan Zhang1598a9e2018-09-04 17:14:32 -07001530func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1531 apiFile, removedApiFile android.Path, implicits android.Paths,
1532 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001533 output android.WritablePath) {
1534 ctx.Build(pctx, android.BuildParams{
1535 Rule: metalavaApiCheck,
1536 Description: "Metalava Check API",
1537 Output: output,
1538 Inputs: d.Javadoc.srcFiles,
1539 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1540 implicits...),
1541 Args: map[string]string{
1542 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1543 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1544 "javaVersion": javaVersion,
1545 "bootclasspathArgs": bootclasspathArgs,
1546 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001547 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001548 "opts": opts,
1549 "msg": msg,
1550 },
1551 })
1552}
1553
Nan Zhang71bbe632018-09-17 14:32:21 -07001554func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1555 implicitOutputs android.WritablePaths,
1556 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1557 ctx.Build(pctx, android.BuildParams{
1558 Rule: javadoc,
1559 Description: "Jdiff",
1560 Output: d.jdiffStubsSrcJar,
1561 Inputs: d.Javadoc.srcFiles,
1562 Implicits: implicits,
1563 ImplicitOutputs: implicitOutputs,
1564 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001565 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1566 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1567 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001568 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1569 "opts": opts,
1570 "bootclasspathArgs": bootclasspathArgs,
1571 "classpathArgs": classpathArgs,
1572 "sourcepathArgs": sourcepathArgs,
1573 "docZip": d.jdiffDocZip.String(),
1574 },
1575 })
1576}
1577
Nan Zhang1598a9e2018-09-04 17:14:32 -07001578func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001579 deps := d.Javadoc.collectDeps(ctx)
1580
1581 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001582
Nan Zhanga40da042018-08-01 12:48:00 -07001583 var implicits android.Paths
1584 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001585 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001586
1587 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001588 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001589 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1590 }
1591
1592 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001593 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001594 jdiffImplicits := implicits
1595
Nan Zhanga40da042018-08-01 12:48:00 -07001596 if err != nil {
1597 return
1598 }
1599
Nan Zhang1598a9e2018-09-04 17:14:32 -07001600 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1601 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001602 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001603 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1604
Nan Zhang1598a9e2018-09-04 17:14:32 -07001605 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1606 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1607 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1608 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1609 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001610 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001611 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1612 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Nan Zhang9c69a122018-08-22 10:22:08 -07001613 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001614 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001615
Nan Zhang1598a9e2018-09-04 17:14:32 -07001616 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1617 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001618 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1619 "check_api.current.api_file")
1620 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1621 "check_api.current_removed_api_file")
1622
Nan Zhang2760dfc2018-08-24 17:32:54 +00001623 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001624 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1625 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001626
Nan Zhang1598a9e2018-09-04 17:14:32 -07001627 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1628 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1629 fmt.Sprintf(`\n******************************\n`+
1630 `You have tried to change the API from what has been previously approved.\n\n`+
1631 `To make these errors go away, you have two choices:\n`+
1632 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1633 ` errors above.\n\n`+
1634 ` 2. You can update current.txt by executing the following command:\n`+
1635 ` make %s-update-current-api\n\n`+
1636 ` To submit the revised current.txt to the main Android repository,\n`+
1637 ` you will need approval.\n`+
1638 `******************************\n`, ctx.ModuleName()),
1639 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001640
1641 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001642 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1643 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001644 }
Nan Zhanga40da042018-08-01 12:48:00 -07001645
Nan Zhang1598a9e2018-09-04 17:14:32 -07001646 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1647 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001648 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1649 "check_api.last_released.api_file")
1650 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1651 "check_api.last_released.removed_api_file")
1652
Nan Zhang2760dfc2018-08-24 17:32:54 +00001653 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001654 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1655 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001656
Nan Zhang1598a9e2018-09-04 17:14:32 -07001657 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1658 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1659 `\n******************************\n`+
1660 `You have tried to change the API from what has been previously released in\n`+
1661 `an SDK. Please fix the errors listed above.\n`+
1662 `******************************\n`,
1663 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001664 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001665
1666 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1667
Nan Zhang86b06202018-09-21 17:09:21 -07001668 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1669 // since there's cron job downstream that fetch this .zip file periodically.
1670 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001671 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1672 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1673
1674 var jdiffImplicitOutputs android.WritablePaths
1675 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1676
1677 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1678 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1679
1680 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1681 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1682 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1683 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1684 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1685 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1686
1687 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1688 flags.sourcepathArgs, opts)
1689 }
Nan Zhang581fd212018-01-10 16:06:12 -08001690}
Dan Willemsencc090972018-02-26 14:33:31 -08001691
Nan Zhanga40da042018-08-01 12:48:00 -07001692//
Nan Zhangf4936b02018-08-01 15:00:28 -07001693// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001694//
Dan Willemsencc090972018-02-26 14:33:31 -08001695var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001696var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001697var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001698var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001699
Nan Zhangf4936b02018-08-01 15:00:28 -07001700type ExportedDroiddocDirProperties struct {
1701 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001702 Path *string
1703}
1704
Nan Zhangf4936b02018-08-01 15:00:28 -07001705type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001706 android.ModuleBase
1707
Nan Zhangf4936b02018-08-01 15:00:28 -07001708 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001709
1710 deps android.Paths
1711 dir android.Path
1712}
1713
Nan Zhangf4936b02018-08-01 15:00:28 -07001714func ExportedDroiddocDirFactory() android.Module {
1715 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001716 module.AddProperties(&module.properties)
1717 android.InitAndroidModule(module)
1718 return module
1719}
1720
Nan Zhangf4936b02018-08-01 15:00:28 -07001721func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001722
Nan Zhangf4936b02018-08-01 15:00:28 -07001723func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001724 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1725 d.dir = path
1726 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1727}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001728
1729//
1730// Defaults
1731//
1732type DocDefaults struct {
1733 android.ModuleBase
1734 android.DefaultsModuleBase
1735}
1736
1737func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1738}
1739
1740func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1741}
1742
1743func DocDefaultsFactory() android.Module {
1744 module := &DocDefaults{}
1745
1746 module.AddProperties(
1747 &JavadocProperties{},
1748 &DroiddocProperties{},
1749 )
1750
1751 android.InitDefaultsModule(module)
1752
1753 return module
1754}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001755
1756func StubsDefaultsFactory() android.Module {
1757 module := &DocDefaults{}
1758
1759 module.AddProperties(
1760 &JavadocProperties{},
1761 &DroidstubsProperties{},
1762 )
1763
1764 android.InitDefaultsModule(module)
1765
1766 return module
1767}