blob: e9b7c0e189bf2757aa5cff8cf9e6c2bd6f00ec78 [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
310 // the generated public API filename by Doclava.
311 Api_filename *string
312
313 // the generated public Dex API filename by Doclava.
314 Dex_api_filename *string
315
316 // the generated private API filename by Doclava.
317 Private_api_filename *string
318
319 // the generated private Dex API filename by Doclava.
320 Private_dex_api_filename *string
321
322 // the generated removed API filename by Doclava.
323 Removed_api_filename *string
324
325 // the generated removed Dex API filename by Doclava.
326 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 Zhang1598a9e2018-09-04 17:14:32 -0700332 // the generated exact API filename by Doclava.
333 Exact_api_filename *string
334
335 Check_api struct {
336 Last_released ApiToCheck
337
338 Current ApiToCheck
339 }
Nan Zhang79614d12018-04-19 18:03:39 -0700340
341 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700342 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700343
344 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700345 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700346
Pete Gillin77167902018-09-19 18:16:26 +0100347 // 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 -0700348 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700349
Pete Gillin77167902018-09-19 18:16:26 +0100350 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
351 Merge_inclusion_annotations_dirs []string
352
Nan Zhang1598a9e2018-09-04 17:14:32 -0700353 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
354 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700355
356 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
357 Api_levels_annotations_enabled *bool
358
359 // the dirs which Metalava extracts API levels annotations from.
360 Api_levels_annotations_dirs []string
361
362 // if set to true, collect the values used by the Dev tools and
363 // write them in files packaged with the SDK. Defaults to false.
364 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700365
366 // If set to true, .xml based public API file will be also generated, and
367 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
368 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800369}
370
Nan Zhanga40da042018-08-01 12:48:00 -0700371//
372// Common flags passed down to build rule
373//
374type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700375 bootClasspathArgs string
376 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700377 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700378 dokkaClasspathArgs string
379 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700380
Nan Zhanga40da042018-08-01 12:48:00 -0700381 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700382 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700383 postDoclavaCmds string
384
Nan Zhang9c69a122018-08-22 10:22:08 -0700385 metalavaStubsFlags string
386 metalavaAnnotationsFlags string
387 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700388
Nan Zhang71bbe632018-09-17 14:32:21 -0700389 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700390}
391
392func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
393 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
394 android.InitDefaultableModule(module)
395}
396
Nan Zhang1598a9e2018-09-04 17:14:32 -0700397func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
398 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
399 return true
400 } else if String(apiToCheck.Api_file) != "" {
401 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
402 } else if String(apiToCheck.Removed_api_file) != "" {
403 panic("for " + apiVersionTag + " api_file has to be non-empty!")
404 }
405
406 return false
407}
408
409type ApiFilePath interface {
410 ApiFilePath() android.Path
411}
412
413func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
414 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
415 ctx.Build(pctx, android.BuildParams{
416 Rule: updateApi,
417 Description: "Update API",
418 Output: output,
419 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
420 destApiFile, destRemovedApiFile),
421 Args: map[string]string{
422 "destApiFile": destApiFile.String(),
423 "srcApiFile": srcApiFile.String(),
424 "destRemovedApiFile": destRemovedApiFile.String(),
425 "srcRemovedApiFile": srcRemovedApiFile.String(),
426 },
427 })
428}
429
Nan Zhanga40da042018-08-01 12:48:00 -0700430//
431// Javadoc
432//
Nan Zhang581fd212018-01-10 16:06:12 -0800433type Javadoc struct {
434 android.ModuleBase
435 android.DefaultableModuleBase
436
437 properties JavadocProperties
438
439 srcJars android.Paths
440 srcFiles android.Paths
441 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700442 argFiles android.Paths
443
444 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800445
Nan Zhangccff0f72018-03-08 17:26:16 -0800446 docZip android.WritablePath
447 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800448}
449
Nan Zhangb2b33de2018-02-23 11:18:47 -0800450func (j *Javadoc) Srcs() android.Paths {
451 return android.Paths{j.stubsSrcJar}
452}
453
Nan Zhang581fd212018-01-10 16:06:12 -0800454func JavadocFactory() android.Module {
455 module := &Javadoc{}
456
457 module.AddProperties(&module.properties)
458
459 InitDroiddocModule(module, android.HostAndDeviceSupported)
460 return module
461}
462
463func JavadocHostFactory() android.Module {
464 module := &Javadoc{}
465
466 module.AddProperties(&module.properties)
467
468 InitDroiddocModule(module, android.HostSupported)
469 return module
470}
471
Nan Zhanga40da042018-08-01 12:48:00 -0700472var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800473
Colin Cross83bb3162018-06-25 15:48:06 -0700474func (j *Javadoc) sdkVersion() string {
475 return String(j.properties.Sdk_version)
476}
477
478func (j *Javadoc) minSdkVersion() string {
479 return j.sdkVersion()
480}
481
Nan Zhang581fd212018-01-10 16:06:12 -0800482func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
483 if ctx.Device() {
Nan Zhang5994b622018-09-21 16:39:51 -0700484 if !Bool(j.properties.No_standard_libs) {
485 sdkDep := decodeSdkDep(ctx, sdkContext(j))
486 if sdkDep.useDefaultLibs {
487 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
488 if ctx.Config().TargetOpenJDK9() {
489 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
490 }
491 if !Bool(j.properties.No_framework_libs) {
492 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
493 }
494 } else if sdkDep.useModule {
495 if ctx.Config().TargetOpenJDK9() {
496 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
497 }
498 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang357466b2018-04-17 17:38:36 -0700499 }
Nan Zhang581fd212018-01-10 16:06:12 -0800500 }
501 }
502
Colin Cross42d48b72018-08-29 14:10:52 -0700503 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700504 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700505 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700506 }
Nan Zhang581fd212018-01-10 16:06:12 -0800507
508 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
509
510 // exclude_srcs may contain filegroup or genrule.
511 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700512
513 // arg_files may contains filegroup or genrule.
514 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800515}
516
Nan Zhangb2b33de2018-02-23 11:18:47 -0800517func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
518 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
519 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900520 // convert foo.bar.baz to foo/bar/baz
521 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
522 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800523 if _, found := whitelistPathPrefixes[prefix]; !found {
524 whitelistPathPrefixes[prefix] = true
525 }
526 }
527 }
528}
529
Nan Zhanga40da042018-08-01 12:48:00 -0700530func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
531 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900532
533 // aidl flags.
534 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
535 if len(aidlFlags) > 0 {
536 // optimization.
537 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
538 flags.aidlFlags = "$aidlFlags"
539 }
540
541 return flags
542}
543
544func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
545 aidlIncludeDirs android.Paths) []string {
546
547 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
548 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
549
550 var flags []string
551 if aidlPreprocess.Valid() {
552 flags = append(flags, "-p"+aidlPreprocess.String())
553 } else {
554 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
555 }
556
557 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
558 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
559 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
560 flags = append(flags, "-I"+src.String())
561 }
562
563 return flags
564}
565
566func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700567 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900568
569 outSrcFiles := make(android.Paths, 0, len(srcFiles))
570
571 for _, srcFile := range srcFiles {
572 switch srcFile.Ext() {
573 case ".aidl":
574 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
575 outSrcFiles = append(outSrcFiles, javaFile)
576 default:
577 outSrcFiles = append(outSrcFiles, srcFile)
578 }
579 }
580
581 return outSrcFiles
582}
583
Nan Zhang581fd212018-01-10 16:06:12 -0800584func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
585 var deps deps
586
Colin Cross83bb3162018-06-25 15:48:06 -0700587 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800588 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700589 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800590 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700591 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800592 }
593
594 ctx.VisitDirectDeps(func(module android.Module) {
595 otherName := ctx.OtherModuleName(module)
596 tag := ctx.OtherModuleDependencyTag(module)
597
Colin Cross2d24c1b2018-05-23 10:59:18 -0700598 switch tag {
599 case bootClasspathTag:
600 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800601 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700602 } else {
603 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
604 }
605 case libTag:
606 switch dep := module.(type) {
607 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800608 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700609 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700610 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900611 linkType := javaSdk
612 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
613 linkType = javaSystem
614 } else if sdkVersion == "" {
615 linkType = javaPlatform
616 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900617 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700618 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800619 checkProducesJars(ctx, dep)
620 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800621 default:
622 ctx.ModuleErrorf("depends on non-java module %q", otherName)
623 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700624 case srcsLibTag:
625 switch dep := module.(type) {
626 case Dependency:
627 srcs := dep.(SrcDependency).CompiledSrcs()
628 whitelistPathPrefixes := make(map[string]bool)
629 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
630 for _, src := range srcs {
631 if _, ok := src.(android.WritablePath); ok { // generated sources
632 deps.srcs = append(deps.srcs, src)
633 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700635 if strings.HasPrefix(src.Rel(), k) {
636 deps.srcs = append(deps.srcs, src)
637 break
638 }
639 }
640 }
641 }
642 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
643 default:
644 ctx.ModuleErrorf("depends on non-java module %q", otherName)
645 }
Nan Zhang357466b2018-04-17 17:38:36 -0700646 case systemModulesTag:
647 if deps.systemModules != nil {
648 panic("Found two system module dependencies")
649 }
650 sm := module.(*SystemModules)
651 if sm.outputFile == nil {
652 panic("Missing directory for system module dependency")
653 }
654 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800655 }
656 })
657 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
658 // may contain filegroup or genrule.
659 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700660 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900661 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800662
663 // srcs may depend on some genrule output.
664 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800665 j.srcJars = append(j.srcJars, deps.srcJars...)
666
Nan Zhang581fd212018-01-10 16:06:12 -0800667 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800668 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800669
670 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800671 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800672
Nan Zhang9c69a122018-08-22 10:22:08 -0700673 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800674 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
675 }
676 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800677
Nan Zhang1598a9e2018-09-04 17:14:32 -0700678 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
679 argFilesMap := map[string]android.Path{}
680
681 for _, f := range j.argFiles {
682 if _, exists := argFilesMap[f.Rel()]; !exists {
683 argFilesMap[f.Rel()] = f
684 } else {
685 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
686 f, argFilesMap[f.Rel()], f.Rel())
687 }
688 }
689
690 var err error
691 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
692 if strings.HasPrefix(name, "location ") {
693 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
694 if f, ok := argFilesMap[label]; ok {
695 return f.String(), nil
696 } else {
697 return "", fmt.Errorf("unknown location label %q", label)
698 }
699 } else if name == "genDir" {
700 return android.PathForModuleGen(ctx).String(), nil
701 }
702 return "", fmt.Errorf("unknown variable '$(%s)'", name)
703 })
704
705 if err != nil {
706 ctx.PropertyErrorf("args", "%s", err.Error())
707 }
708
Nan Zhang581fd212018-01-10 16:06:12 -0800709 return deps
710}
711
712func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
713 j.addDeps(ctx)
714}
715
716func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
717 deps := j.collectDeps(ctx)
718
719 var implicits android.Paths
720 implicits = append(implicits, deps.bootClasspath...)
721 implicits = append(implicits, deps.classpath...)
722
Nan Zhang1598a9e2018-09-04 17:14:32 -0700723 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700724
Colin Cross83bb3162018-06-25 15:48:06 -0700725 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700726 if len(deps.bootClasspath) > 0 {
727 var systemModules classpath
728 if deps.systemModules != nil {
729 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800730 }
Colin Cross997262f2018-06-19 22:49:39 -0700731 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
732 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800733 }
734 if len(deps.classpath.Strings()) > 0 {
735 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
736 }
737
738 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700739 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800740
Nan Zhangaf322cc2018-06-19 15:15:38 -0700741 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800742
Nan Zhang1598a9e2018-09-04 17:14:32 -0700743 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
744
Nan Zhang581fd212018-01-10 16:06:12 -0800745 ctx.Build(pctx, android.BuildParams{
746 Rule: javadoc,
747 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800748 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800749 ImplicitOutput: j.docZip,
750 Inputs: j.srcFiles,
751 Implicits: implicits,
752 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700753 "outDir": android.PathForModuleOut(ctx, "out").String(),
754 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
755 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800756 "srcJars": strings.Join(j.srcJars.Strings(), " "),
757 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700758 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800759 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700760 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800761 "docZip": j.docZip.String(),
762 },
763 })
764}
765
Nan Zhanga40da042018-08-01 12:48:00 -0700766//
767// Droiddoc
768//
769type Droiddoc struct {
770 Javadoc
771
772 properties DroiddocProperties
773 apiFile android.WritablePath
774 dexApiFile android.WritablePath
775 privateApiFile android.WritablePath
776 privateDexApiFile android.WritablePath
777 removedApiFile android.WritablePath
778 removedDexApiFile android.WritablePath
779 exactApiFile android.WritablePath
780 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700781 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700782
783 checkCurrentApiTimestamp android.WritablePath
784 updateCurrentApiTimestamp android.WritablePath
785 checkLastReleasedApiTimestamp android.WritablePath
786
Nan Zhanga40da042018-08-01 12:48:00 -0700787 apiFilePath android.Path
788}
789
Nan Zhanga40da042018-08-01 12:48:00 -0700790func DroiddocFactory() android.Module {
791 module := &Droiddoc{}
792
793 module.AddProperties(&module.properties,
794 &module.Javadoc.properties)
795
796 InitDroiddocModule(module, android.HostAndDeviceSupported)
797 return module
798}
799
800func DroiddocHostFactory() android.Module {
801 module := &Droiddoc{}
802
803 module.AddProperties(&module.properties,
804 &module.Javadoc.properties)
805
806 InitDroiddocModule(module, android.HostSupported)
807 return module
808}
809
810func (d *Droiddoc) ApiFilePath() android.Path {
811 return d.apiFilePath
812}
813
Nan Zhang581fd212018-01-10 16:06:12 -0800814func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
815 d.Javadoc.addDeps(ctx)
816
Nan Zhang79614d12018-04-19 18:03:39 -0700817 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800818 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
819 }
820
Nan Zhang581fd212018-01-10 16:06:12 -0800821 // knowntags may contain filegroup or genrule.
822 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700823
Nan Zhange2ba5d42018-07-11 15:16:55 -0700824 if String(d.properties.Static_doc_index_redirect) != "" {
825 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
826 }
827
828 if String(d.properties.Static_doc_properties) != "" {
829 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
830 }
831
Nan Zhang1598a9e2018-09-04 17:14:32 -0700832 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700833 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
834 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
835 }
836
Nan Zhang1598a9e2018-09-04 17:14:32 -0700837 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700838 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
839 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
840 }
Nan Zhang581fd212018-01-10 16:06:12 -0800841}
842
Nan Zhang66dc2362018-08-14 20:41:04 -0700843func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
844 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700845 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800846
Nan Zhanga40da042018-08-01 12:48:00 -0700847 *implicits = append(*implicits, deps.bootClasspath...)
848 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800849
Nan Zhangc94f9d82018-06-26 10:02:26 -0700850 if len(deps.bootClasspath.Strings()) > 0 {
851 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700852 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700853 }
Nan Zhanga40da042018-08-01 12:48:00 -0700854 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700855 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700856 dokkaClasspath := classpath{}
857 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
858 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
859 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700860
Nan Zhang9c69a122018-08-22 10:22:08 -0700861 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
862 // based stubs generation.
863 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
864 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
865 // the correct package name base path.
866 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
867 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
868 } else {
869 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
870 }
Nan Zhang581fd212018-01-10 16:06:12 -0800871
Nan Zhanga40da042018-08-01 12:48:00 -0700872 return flags, nil
873}
Nan Zhang581fd212018-01-10 16:06:12 -0800874
Nan Zhanga40da042018-08-01 12:48:00 -0700875func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700876 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800877
Nan Zhanga40da042018-08-01 12:48:00 -0700878 *implicits = append(*implicits, jsilver)
879 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700880
Nan Zhang46130972018-06-04 11:28:01 -0700881 var date string
882 if runtime.GOOS == "darwin" {
883 date = `date -r`
884 } else {
885 date = `date -d`
886 }
887
Nan Zhang443fa522018-08-20 20:58:28 -0700888 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
889 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
890 // 1.9 language features.
891 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700892 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800893 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700894 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700895
Nan Zhanga40da042018-08-01 12:48:00 -0700896 if String(d.properties.Custom_template) == "" {
897 // TODO: This is almost always droiddoc-templates-sdk
898 ctx.PropertyErrorf("custom_template", "must specify a template")
899 }
900
901 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700902 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700903 *implicits = append(*implicits, t.deps...)
904 args = args + " -templatedir " + t.dir.String()
905 } else {
906 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
907 }
908 })
909
910 if len(d.properties.Html_dirs) > 0 {
911 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
912 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
913 args = args + " -htmldir " + htmlDir.String()
914 }
915
916 if len(d.properties.Html_dirs) > 1 {
917 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
918 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
919 args = args + " -htmldir2 " + htmlDir2.String()
920 }
921
922 if len(d.properties.Html_dirs) > 2 {
923 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
924 }
925
926 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
927 *implicits = append(*implicits, knownTags...)
928
929 for _, kt := range knownTags {
930 args = args + " -knowntags " + kt.String()
931 }
932
933 for _, hdf := range d.properties.Hdf {
934 args = args + " -hdf " + hdf
935 }
936
937 if String(d.properties.Proofread_file) != "" {
938 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
939 args = args + " -proofread " + proofreadFile.String()
940 }
941
942 if String(d.properties.Todo_file) != "" {
943 // tricky part:
944 // we should not compute full path for todo_file through PathForModuleOut().
945 // the non-standard doclet will get the full path relative to "-o".
946 args = args + " -todo " + String(d.properties.Todo_file)
947 }
948
949 if String(d.properties.Resourcesdir) != "" {
950 // TODO: should we add files under resourcesDir to the implicits? It seems that
951 // resourcesDir is one sub dir of htmlDir
952 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
953 args = args + " -resourcesdir " + resourcesDir.String()
954 }
955
956 if String(d.properties.Resourcesoutdir) != "" {
957 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
958 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
959 }
960 return args
961}
962
Nan Zhang1598a9e2018-09-04 17:14:32 -0700963func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
964 implicitOutputs *android.WritablePaths) string {
965 var doclavaFlags string
966 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
967 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
968 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700969 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
970 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700971 *implicitOutputs = append(*implicitOutputs, d.apiFile)
972 d.apiFilePath = d.apiFile
973 }
974
Nan Zhang1598a9e2018-09-04 17:14:32 -0700975 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
976 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
977 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700978 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
979 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700980 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
981 }
982
983 if String(d.properties.Private_api_filename) != "" {
984 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
985 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700986 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
987 }
988
989 if String(d.properties.Dex_api_filename) != "" {
990 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
991 doclavaFlags += " -dexApi " + d.dexApiFile.String()
992 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
993 }
994
995 if String(d.properties.Private_dex_api_filename) != "" {
996 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
997 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700998 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
999 }
1000
1001 if String(d.properties.Removed_dex_api_filename) != "" {
1002 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1003 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001004 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1005 }
1006
1007 if String(d.properties.Exact_api_filename) != "" {
1008 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1009 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001010 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1011 }
1012
1013 if String(d.properties.Dex_mapping_filename) != "" {
1014 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1015 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001016 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1017 }
1018
Nan Zhang66dc2362018-08-14 20:41:04 -07001019 if String(d.properties.Proguard_filename) != "" {
1020 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1021 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001022 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1023 }
1024
Nan Zhanga40da042018-08-01 12:48:00 -07001025 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001026 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001027 }
1028
1029 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001030 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001031 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001032
1033 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001034}
1035
1036func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1037 var cmds string
1038 if String(d.properties.Static_doc_index_redirect) != "" {
1039 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1040 "static_doc_index_redirect")
1041 *implicits = append(*implicits, static_doc_index_redirect)
1042 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001043 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001044 }
1045
1046 if String(d.properties.Static_doc_properties) != "" {
1047 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1048 "static_doc_properties")
1049 *implicits = append(*implicits, static_doc_properties)
1050 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001051 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001052 }
1053 return cmds
1054}
1055
Nan Zhang1598a9e2018-09-04 17:14:32 -07001056func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1057 implicitOutputs android.WritablePaths,
1058 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1059 ctx.Build(pctx, android.BuildParams{
1060 Rule: javadoc,
1061 Description: "Doclava",
1062 Output: d.Javadoc.stubsSrcJar,
1063 Inputs: d.Javadoc.srcFiles,
1064 Implicits: implicits,
1065 ImplicitOutputs: implicitOutputs,
1066 Args: map[string]string{
1067 "outDir": android.PathForModuleOut(ctx, "out").String(),
1068 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1069 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1070 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1071 "opts": opts,
1072 "bootclasspathArgs": bootclasspathArgs,
1073 "classpathArgs": classpathArgs,
1074 "sourcepathArgs": sourcepathArgs,
1075 "docZip": d.Javadoc.docZip.String(),
1076 "postDoclavaCmds": postDoclavaCmds,
1077 },
1078 })
1079}
1080
1081func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1082 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1083 ctx.Build(pctx, android.BuildParams{
1084 Rule: apiCheck,
1085 Description: "Doclava Check API",
1086 Output: output,
1087 Inputs: nil,
1088 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1089 checkApiClasspath...),
1090 Args: map[string]string{
1091 "msg": msg,
1092 "classpath": checkApiClasspath.FormJavaClassPath(""),
1093 "opts": opts,
1094 "apiFile": apiFile.String(),
1095 "apiFileToCheck": d.apiFile.String(),
1096 "removedApiFile": removedApiFile.String(),
1097 "removedApiFileToCheck": d.removedApiFile.String(),
1098 },
1099 })
1100}
1101
1102func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1103 classpathArgs, opts string) {
1104 ctx.Build(pctx, android.BuildParams{
1105 Rule: dokka,
1106 Description: "Dokka",
1107 Output: d.Javadoc.stubsSrcJar,
1108 Inputs: d.Javadoc.srcFiles,
1109 Implicits: implicits,
1110 Args: map[string]string{
1111 "outDir": android.PathForModuleOut(ctx, "out").String(),
1112 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1113 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1114 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1115 "classpathArgs": classpathArgs,
1116 "opts": opts,
1117 "docZip": d.Javadoc.docZip.String(),
1118 },
1119 })
1120}
1121
1122func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1123 deps := d.Javadoc.collectDeps(ctx)
1124
1125 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1126 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1127 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1128 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1129
1130 var implicits android.Paths
1131 implicits = append(implicits, d.Javadoc.srcJars...)
1132 implicits = append(implicits, d.Javadoc.argFiles...)
1133
1134 var implicitOutputs android.WritablePaths
1135 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1136 for _, o := range d.Javadoc.properties.Out {
1137 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1138 }
1139
1140 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1141 if err != nil {
1142 return
1143 }
1144
1145 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1146 if Bool(d.properties.Dokka_enabled) {
1147 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1148 } else {
1149 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1150 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1151 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1152 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1153 flags.postDoclavaCmds)
1154 }
1155
1156 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1157 !ctx.Config().IsPdkBuild() {
1158 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1159 "check_api.current.api_file")
1160 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1161 "check_api.current_removed_api_file")
1162
1163 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1164 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1165 fmt.Sprintf(`\n******************************\n`+
1166 `You have tried to change the API from what has been previously approved.\n\n`+
1167 `To make these errors go away, you have two choices:\n`+
1168 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1169 ` errors above.\n\n`+
1170 ` 2. You can update current.txt by executing the following command:\n`+
1171 ` make %s-update-current-api\n\n`+
1172 ` To submit the revised current.txt to the main Android repository,\n`+
1173 ` you will need approval.\n`+
1174 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1175 d.checkCurrentApiTimestamp)
1176
1177 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1178 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1179 d.updateCurrentApiTimestamp)
1180 }
1181
1182 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1183 !ctx.Config().IsPdkBuild() {
1184 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1185 "check_api.last_released.api_file")
1186 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1187 "check_api.last_released.removed_api_file")
1188
1189 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1190 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1191 `\n******************************\n`+
1192 `You have tried to change the API from what has been previously released in\n`+
1193 `an SDK. Please fix the errors listed above.\n`+
1194 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1195 d.checkLastReleasedApiTimestamp)
1196 }
1197}
1198
1199//
1200// Droidstubs
1201//
1202type Droidstubs struct {
1203 Javadoc
1204
Nan Zhang71bbe632018-09-17 14:32:21 -07001205 properties DroidstubsProperties
1206 apiFile android.WritablePath
1207 apiXmlFile android.WritablePath
1208 lastReleasedApiXmlFile android.WritablePath
1209 dexApiFile android.WritablePath
1210 privateApiFile android.WritablePath
1211 privateDexApiFile android.WritablePath
1212 removedApiFile android.WritablePath
1213 removedDexApiFile android.WritablePath
1214 apiMappingFile android.WritablePath
1215 exactApiFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001216
1217 checkCurrentApiTimestamp android.WritablePath
1218 updateCurrentApiTimestamp android.WritablePath
1219 checkLastReleasedApiTimestamp android.WritablePath
1220
1221 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001222 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001223
1224 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001225
1226 jdiffDocZip android.WritablePath
1227 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001228}
1229
1230func DroidstubsFactory() android.Module {
1231 module := &Droidstubs{}
1232
1233 module.AddProperties(&module.properties,
1234 &module.Javadoc.properties)
1235
1236 InitDroiddocModule(module, android.HostAndDeviceSupported)
1237 return module
1238}
1239
1240func DroidstubsHostFactory() android.Module {
1241 module := &Droidstubs{}
1242
1243 module.AddProperties(&module.properties,
1244 &module.Javadoc.properties)
1245
1246 InitDroiddocModule(module, android.HostSupported)
1247 return module
1248}
1249
1250func (d *Droidstubs) ApiFilePath() android.Path {
1251 return d.apiFilePath
1252}
1253
1254func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1255 d.Javadoc.addDeps(ctx)
1256
1257 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1258 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1259 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1260 }
1261
1262 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1263 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1264 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1265 }
1266
1267 if String(d.properties.Previous_api) != "" {
1268 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1269 }
1270
1271 if len(d.properties.Merge_annotations_dirs) != 0 {
1272 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1273 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1274 }
1275 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001276
Pete Gillin77167902018-09-19 18:16:26 +01001277 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1278 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1279 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1280 }
1281 }
1282
Nan Zhang9c69a122018-08-22 10:22:08 -07001283 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1284 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1285 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1286 }
1287 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001288}
1289
1290func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1291 deps deps) (droiddocBuilderFlags, error) {
1292 var flags droiddocBuilderFlags
1293
1294 *implicits = append(*implicits, deps.bootClasspath...)
1295 *implicits = append(*implicits, deps.classpath...)
1296
1297 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1298 // since it doesn't support system modules yet.
1299 if len(deps.bootClasspath.Strings()) > 0 {
1300 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1301 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1302 }
1303 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1304
1305 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1306
1307 return flags, nil
1308}
1309
1310func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1311 implicitOutputs *android.WritablePaths) string {
1312 var metalavaFlags string
1313 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1314 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1315 String(d.properties.Api_filename) != "" {
1316 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1317 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1318 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1319 d.apiFilePath = d.apiFile
1320 }
1321
1322 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1323 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1324 String(d.properties.Removed_api_filename) != "" {
1325 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1326 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1327 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1328 }
1329
1330 if String(d.properties.Private_api_filename) != "" {
1331 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1332 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1333 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1334 }
1335
1336 if String(d.properties.Dex_api_filename) != "" {
1337 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1338 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1339 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1340 }
1341
1342 if String(d.properties.Private_dex_api_filename) != "" {
1343 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1344 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1345 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1346 }
1347
1348 if String(d.properties.Removed_dex_api_filename) != "" {
1349 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1350 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1351 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1352 }
1353
1354 if String(d.properties.Exact_api_filename) != "" {
1355 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1356 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1357 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1358 }
1359
Nan Zhang9c69a122018-08-22 10:22:08 -07001360 if String(d.properties.Dex_mapping_filename) != "" {
1361 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1362 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1363 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1364 }
1365
1366 if Bool(d.properties.Write_sdk_values) {
1367 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1368 }
1369
Nan Zhang1598a9e2018-09-04 17:14:32 -07001370 if Bool(d.properties.Create_doc_stubs) {
1371 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1372 } else {
1373 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1374 }
1375
1376 return metalavaFlags
1377}
1378
1379func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1380 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001381 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001382 if Bool(d.properties.Annotations_enabled) {
1383 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001384 ctx.PropertyErrorf("metalava_previous_api",
1385 "has to be non-empty if annotations was enabled!")
1386 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001387 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001388 "metalava_previous_api")
1389 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001390
Nan Zhangd05a4362018-08-15 13:28:54 -07001391 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001392
1393 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1394 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1395
Nan Zhangf4936b02018-08-01 15:00:28 -07001396 flags += " --extract-annotations " + d.annotationsZip.String()
1397
Nan Zhang1598a9e2018-09-04 17:14:32 -07001398 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001399 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001400 "has to be non-empty if annotations was enabled!")
1401 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001402 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1403 if t, ok := m.(*ExportedDroiddocDir); ok {
1404 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001405 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001406 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001407 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001408 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1409 }
1410 })
Nan Zhanga40da042018-08-01 12:48:00 -07001411 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1412 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1413 }
Pete Gillin77167902018-09-19 18:16:26 +01001414 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1415 if t, ok := m.(*ExportedDroiddocDir); ok {
1416 *implicits = append(*implicits, t.deps...)
1417 flags += " --merge-inclusion-annotations " + t.dir.String()
1418 } else {
1419 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1420 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1421 }
1422 })
Nan Zhanga40da042018-08-01 12:48:00 -07001423
1424 return flags
1425}
1426
Nan Zhang9c69a122018-08-22 10:22:08 -07001427func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1428 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1429 var flags string
1430 if Bool(d.properties.Api_levels_annotations_enabled) {
1431 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1432 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1433
1434 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1435 ctx.PropertyErrorf("api_levels_annotations_dirs",
1436 "has to be non-empty if api levels annotations was enabled!")
1437 }
1438
1439 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1440 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1441 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1442
1443 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1444 if t, ok := m.(*ExportedDroiddocDir); ok {
1445 var androidJars android.Paths
1446 for _, dep := range t.deps {
1447 if strings.HasSuffix(dep.String(), "android.jar") {
1448 androidJars = append(androidJars, dep)
1449 }
1450 }
1451 *implicits = append(*implicits, androidJars...)
1452 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1453 } else {
1454 ctx.PropertyErrorf("api_levels_annotations_dirs",
1455 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1456 }
1457 })
1458
1459 }
1460
1461 return flags
1462}
1463
Nan Zhang71bbe632018-09-17 14:32:21 -07001464func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1465 implicitOutputs *android.WritablePaths) string {
1466 var flags string
1467 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1468 if d.apiFile.String() == "" {
1469 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1470 }
1471
1472 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1473 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1474
1475 flags = " --api-xml " + d.apiXmlFile.String()
1476
1477 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1478 ctx.PropertyErrorf("check_api.last_released.api_file",
1479 "has to be non-empty if jdiff was enabled!")
1480 }
1481 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1482 "check_api.last_released.api_file")
1483 *implicits = append(*implicits, lastReleasedApi)
1484
1485 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1486 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1487
1488 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1489 d.lastReleasedApiXmlFile.String()
1490 }
1491
1492 return flags
1493}
1494
Nan Zhang1598a9e2018-09-04 17:14:32 -07001495func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1496 implicitOutputs android.WritablePaths, javaVersion,
1497 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001498
Nan Zhang86d2d552018-08-09 15:33:27 -07001499 ctx.Build(pctx, android.BuildParams{
1500 Rule: metalava,
1501 Description: "Metalava",
1502 Output: d.Javadoc.stubsSrcJar,
1503 Inputs: d.Javadoc.srcFiles,
1504 Implicits: implicits,
1505 ImplicitOutputs: implicitOutputs,
1506 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001507 "outDir": android.PathForModuleOut(ctx, "out").String(),
1508 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1509 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1510 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001511 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001512 "bootclasspathArgs": bootclasspathArgs,
1513 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001514 "sourcepathArgs": sourcepathArgs,
1515 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001516 },
1517 })
1518}
1519
Nan Zhang1598a9e2018-09-04 17:14:32 -07001520func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1521 apiFile, removedApiFile android.Path, implicits android.Paths,
1522 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001523 output android.WritablePath) {
1524 ctx.Build(pctx, android.BuildParams{
1525 Rule: metalavaApiCheck,
1526 Description: "Metalava Check API",
1527 Output: output,
1528 Inputs: d.Javadoc.srcFiles,
1529 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1530 implicits...),
1531 Args: map[string]string{
1532 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1533 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1534 "javaVersion": javaVersion,
1535 "bootclasspathArgs": bootclasspathArgs,
1536 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001537 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001538 "opts": opts,
1539 "msg": msg,
1540 },
1541 })
1542}
1543
Nan Zhang71bbe632018-09-17 14:32:21 -07001544func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1545 implicitOutputs android.WritablePaths,
1546 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1547 ctx.Build(pctx, android.BuildParams{
1548 Rule: javadoc,
1549 Description: "Jdiff",
1550 Output: d.jdiffStubsSrcJar,
1551 Inputs: d.Javadoc.srcFiles,
1552 Implicits: implicits,
1553 ImplicitOutputs: implicitOutputs,
1554 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001555 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1556 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1557 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001558 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1559 "opts": opts,
1560 "bootclasspathArgs": bootclasspathArgs,
1561 "classpathArgs": classpathArgs,
1562 "sourcepathArgs": sourcepathArgs,
1563 "docZip": d.jdiffDocZip.String(),
1564 },
1565 })
1566}
1567
Nan Zhang1598a9e2018-09-04 17:14:32 -07001568func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001569 deps := d.Javadoc.collectDeps(ctx)
1570
1571 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001572
Nan Zhanga40da042018-08-01 12:48:00 -07001573 var implicits android.Paths
1574 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001575 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001576
1577 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001578 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001579 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1580 }
1581
1582 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001583 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001584 jdiffImplicits := implicits
1585
Nan Zhanga40da042018-08-01 12:48:00 -07001586 if err != nil {
1587 return
1588 }
1589
Nan Zhang1598a9e2018-09-04 17:14:32 -07001590 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1591 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001592 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001593 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1594
Nan Zhang1598a9e2018-09-04 17:14:32 -07001595 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1596 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1597 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1598 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1599 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001600 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001601 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1602 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Nan Zhang9c69a122018-08-22 10:22:08 -07001603 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001604 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001605
Nan Zhang1598a9e2018-09-04 17:14:32 -07001606 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1607 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001608 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1609 "check_api.current.api_file")
1610 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1611 "check_api.current_removed_api_file")
1612
Nan Zhang2760dfc2018-08-24 17:32:54 +00001613 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001614 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1615 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001616
Nan Zhang1598a9e2018-09-04 17:14:32 -07001617 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1618 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1619 fmt.Sprintf(`\n******************************\n`+
1620 `You have tried to change the API from what has been previously approved.\n\n`+
1621 `To make these errors go away, you have two choices:\n`+
1622 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1623 ` errors above.\n\n`+
1624 ` 2. You can update current.txt by executing the following command:\n`+
1625 ` make %s-update-current-api\n\n`+
1626 ` To submit the revised current.txt to the main Android repository,\n`+
1627 ` you will need approval.\n`+
1628 `******************************\n`, ctx.ModuleName()),
1629 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001630
1631 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001632 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1633 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001634 }
Nan Zhanga40da042018-08-01 12:48:00 -07001635
Nan Zhang1598a9e2018-09-04 17:14:32 -07001636 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1637 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001638 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1639 "check_api.last_released.api_file")
1640 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1641 "check_api.last_released.removed_api_file")
1642
Nan Zhang2760dfc2018-08-24 17:32:54 +00001643 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001644 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1645 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001646
Nan Zhang1598a9e2018-09-04 17:14:32 -07001647 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1648 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1649 `\n******************************\n`+
1650 `You have tried to change the API from what has been previously released in\n`+
1651 `an SDK. Please fix the errors listed above.\n`+
1652 `******************************\n`,
1653 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001654 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001655
1656 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1657
Nan Zhang86b06202018-09-21 17:09:21 -07001658 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1659 // since there's cron job downstream that fetch this .zip file periodically.
1660 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001661 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1662 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1663
1664 var jdiffImplicitOutputs android.WritablePaths
1665 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1666
1667 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1668 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1669
1670 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1671 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1672 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1673 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1674 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1675 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1676
1677 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1678 flags.sourcepathArgs, opts)
1679 }
Nan Zhang581fd212018-01-10 16:06:12 -08001680}
Dan Willemsencc090972018-02-26 14:33:31 -08001681
Nan Zhanga40da042018-08-01 12:48:00 -07001682//
Nan Zhangf4936b02018-08-01 15:00:28 -07001683// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001684//
Dan Willemsencc090972018-02-26 14:33:31 -08001685var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001686var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001687var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001688var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001689
Nan Zhangf4936b02018-08-01 15:00:28 -07001690type ExportedDroiddocDirProperties struct {
1691 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001692 Path *string
1693}
1694
Nan Zhangf4936b02018-08-01 15:00:28 -07001695type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001696 android.ModuleBase
1697
Nan Zhangf4936b02018-08-01 15:00:28 -07001698 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001699
1700 deps android.Paths
1701 dir android.Path
1702}
1703
Nan Zhangf4936b02018-08-01 15:00:28 -07001704func ExportedDroiddocDirFactory() android.Module {
1705 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001706 module.AddProperties(&module.properties)
1707 android.InitAndroidModule(module)
1708 return module
1709}
1710
Nan Zhangf4936b02018-08-01 15:00:28 -07001711func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001712
Nan Zhangf4936b02018-08-01 15:00:28 -07001713func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001714 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1715 d.dir = path
1716 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1717}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001718
1719//
1720// Defaults
1721//
1722type DocDefaults struct {
1723 android.ModuleBase
1724 android.DefaultsModuleBase
1725}
1726
1727func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1728}
1729
1730func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1731}
1732
1733func DocDefaultsFactory() android.Module {
1734 module := &DocDefaults{}
1735
1736 module.AddProperties(
1737 &JavadocProperties{},
1738 &DroiddocProperties{},
1739 )
1740
1741 android.InitDefaultsModule(module)
1742
1743 return module
1744}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001745
1746func StubsDefaultsFactory() android.Module {
1747 module := &DocDefaults{}
1748
1749 module.AddProperties(
1750 &JavadocProperties{},
1751 &DroidstubsProperties{},
1752 )
1753
1754 android.InitDefaultsModule(module)
1755
1756 return module
1757}