blob: a4050d552e4d9382abe6d5aff8bfada198b009fb [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 Zhange66c7272018-03-06 12:59:27 -0800163 // don't build against the framework libraries (legacy-test, core-junit,
164 // ext, and framework for device targets)
165 No_framework_libs *bool
166
Nan Zhangb2b33de2018-02-23 11:18:47 -0800167 // the java library (in classpath) for documentation that provides java srcs and srcjars.
168 Srcs_lib *string
169
170 // the base dirs under srcs_lib will be scanned for java srcs.
171 Srcs_lib_whitelist_dirs []string
172
173 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
174 Srcs_lib_whitelist_pkgs []string
175
Nan Zhang581fd212018-01-10 16:06:12 -0800176 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800177 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800178
179 // if not blank, set to the version of the sdk to compile against
180 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900181
182 Aidl struct {
183 // Top level directories to pass to aidl tool
184 Include_dirs []string
185
186 // Directories rooted at the Android.bp file to pass to aidl tool
187 Local_include_dirs []string
188 }
Nan Zhang357466b2018-04-17 17:38:36 -0700189
190 // If not blank, set the java version passed to javadoc as -source
191 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700192
193 // local files that are used within user customized droiddoc options.
194 Arg_files []string
195
196 // user customized droiddoc args.
197 // Available variables for substitution:
198 //
199 // $(location <label>): the path to the arg_files with name <label>
200 Args *string
201
202 // names of the output files used in args that will be generated
203 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800204}
205
Nan Zhang61819ce2018-05-04 18:49:16 -0700206type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900207 // path to the API txt file that the new API extracted from source code is checked
208 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700209 Api_file *string
210
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900211 // path to the API txt file that the new @removed API extractd from source code is
212 // checked against. The path can be local to the module or from other module (via
213 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700214 Removed_api_file *string
215
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900216 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700217 Args *string
218}
219
Nan Zhang581fd212018-01-10 16:06:12 -0800220type DroiddocProperties struct {
221 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800222 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800223
Nan Zhanga40da042018-08-01 12:48:00 -0700224 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800225 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800226
227 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800228 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800229
230 // proofread file contains all of the text content of the javadocs concatenated into one file,
231 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800232 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800233
234 // a todo file lists the program elements that are missing documentation.
235 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800236 Todo_file *string
237
238 // directory under current module source that provide additional resources (images).
239 Resourcesdir *string
240
241 // resources output directory under out/soong/.intermediates.
242 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800243
Nan Zhange2ba5d42018-07-11 15:16:55 -0700244 // if set to true, collect the values used by the Dev tools and
245 // write them in files packaged with the SDK. Defaults to false.
246 Write_sdk_values *bool
247
248 // index.html under current module will be copied to docs out dir, if not null.
249 Static_doc_index_redirect *string
250
251 // source.properties under current module will be copied to docs out dir, if not null.
252 Static_doc_properties *string
253
Nan Zhang581fd212018-01-10 16:06:12 -0800254 // a list of files under current module source dir which contains known tags in Java sources.
255 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800256 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700257
258 // the tag name used to distinguish if the API files belong to public/system/test.
259 Api_tag_name *string
260
261 // the generated public API filename by Doclava.
262 Api_filename *string
263
David Brazdilfbe4cc32018-05-31 13:56:46 +0100264 // the generated public Dex API filename by Doclava.
265 Dex_api_filename *string
266
Nan Zhang28c68b92018-03-13 16:17:01 -0700267 // the generated private API filename by Doclava.
268 Private_api_filename *string
269
270 // the generated private Dex API filename by Doclava.
271 Private_dex_api_filename *string
272
273 // the generated removed API filename by Doclava.
274 Removed_api_filename *string
275
David Brazdilaac0c3c2018-04-24 16:23:29 +0100276 // the generated removed Dex API filename by Doclava.
277 Removed_dex_api_filename *string
278
Mathew Inwood76c3de12018-06-22 15:28:11 +0100279 // mapping of dex signatures to source file and line number. This is a temporary property and
280 // will be deleted; you probably shouldn't be using it.
281 Dex_mapping_filename *string
282
Nan Zhang28c68b92018-03-13 16:17:01 -0700283 // the generated exact API filename by Doclava.
284 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700285
Nan Zhang66dc2362018-08-14 20:41:04 -0700286 // the generated proguard filename by Doclava.
287 Proguard_filename *string
288
Nan Zhang853f4202018-04-12 16:55:56 -0700289 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
290 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700291
292 Check_api struct {
293 Last_released ApiToCheck
294
295 Current ApiToCheck
296 }
Nan Zhang79614d12018-04-19 18:03:39 -0700297
Nan Zhang1598a9e2018-09-04 17:14:32 -0700298 // if set to true, generate docs through Dokka instead of Doclava.
299 Dokka_enabled *bool
300}
301
302type DroidstubsProperties struct {
303 // the tag name used to distinguish if the API files belong to public/system/test.
304 Api_tag_name *string
305
306 // the generated public API filename by Doclava.
307 Api_filename *string
308
309 // the generated public Dex API filename by Doclava.
310 Dex_api_filename *string
311
312 // the generated private API filename by Doclava.
313 Private_api_filename *string
314
315 // the generated private Dex API filename by Doclava.
316 Private_dex_api_filename *string
317
318 // the generated removed API filename by Doclava.
319 Removed_api_filename *string
320
321 // the generated removed Dex API filename by Doclava.
322 Removed_dex_api_filename *string
323
Nan Zhang9c69a122018-08-22 10:22:08 -0700324 // mapping of dex signatures to source file and line number. This is a temporary property and
325 // will be deleted; you probably shouldn't be using it.
326 Dex_mapping_filename *string
327
Nan Zhang1598a9e2018-09-04 17:14:32 -0700328 // the generated exact API filename by Doclava.
329 Exact_api_filename *string
330
331 Check_api struct {
332 Last_released ApiToCheck
333
334 Current ApiToCheck
335 }
Nan Zhang79614d12018-04-19 18:03:39 -0700336
337 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700339
340 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700341 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700342
Pete Gillinb13a0152018-07-19 17:56:49 +0100343 // a list of top-level directories containing files to merge annotations from.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700344 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700345
Nan Zhang1598a9e2018-09-04 17:14:32 -0700346 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
347 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700348
349 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
350 Api_levels_annotations_enabled *bool
351
352 // the dirs which Metalava extracts API levels annotations from.
353 Api_levels_annotations_dirs []string
354
355 // if set to true, collect the values used by the Dev tools and
356 // write them in files packaged with the SDK. Defaults to false.
357 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700358
359 // If set to true, .xml based public API file will be also generated, and
360 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
361 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800362}
363
Nan Zhanga40da042018-08-01 12:48:00 -0700364//
365// Common flags passed down to build rule
366//
367type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700368 bootClasspathArgs string
369 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700370 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700371 dokkaClasspathArgs string
372 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700373
Nan Zhanga40da042018-08-01 12:48:00 -0700374 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700375 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700376 postDoclavaCmds string
377
Nan Zhang9c69a122018-08-22 10:22:08 -0700378 metalavaStubsFlags string
379 metalavaAnnotationsFlags string
380 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700381
Nan Zhang71bbe632018-09-17 14:32:21 -0700382 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700383}
384
385func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
386 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
387 android.InitDefaultableModule(module)
388}
389
Nan Zhang1598a9e2018-09-04 17:14:32 -0700390func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
391 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
392 return true
393 } else if String(apiToCheck.Api_file) != "" {
394 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
395 } else if String(apiToCheck.Removed_api_file) != "" {
396 panic("for " + apiVersionTag + " api_file has to be non-empty!")
397 }
398
399 return false
400}
401
402type ApiFilePath interface {
403 ApiFilePath() android.Path
404}
405
406func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
407 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
408 ctx.Build(pctx, android.BuildParams{
409 Rule: updateApi,
410 Description: "Update API",
411 Output: output,
412 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
413 destApiFile, destRemovedApiFile),
414 Args: map[string]string{
415 "destApiFile": destApiFile.String(),
416 "srcApiFile": srcApiFile.String(),
417 "destRemovedApiFile": destRemovedApiFile.String(),
418 "srcRemovedApiFile": srcRemovedApiFile.String(),
419 },
420 })
421}
422
Nan Zhanga40da042018-08-01 12:48:00 -0700423//
424// Javadoc
425//
Nan Zhang581fd212018-01-10 16:06:12 -0800426type Javadoc struct {
427 android.ModuleBase
428 android.DefaultableModuleBase
429
430 properties JavadocProperties
431
432 srcJars android.Paths
433 srcFiles android.Paths
434 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700435 argFiles android.Paths
436
437 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800438
Nan Zhangccff0f72018-03-08 17:26:16 -0800439 docZip android.WritablePath
440 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800441}
442
Nan Zhangb2b33de2018-02-23 11:18:47 -0800443func (j *Javadoc) Srcs() android.Paths {
444 return android.Paths{j.stubsSrcJar}
445}
446
Nan Zhang581fd212018-01-10 16:06:12 -0800447func JavadocFactory() android.Module {
448 module := &Javadoc{}
449
450 module.AddProperties(&module.properties)
451
452 InitDroiddocModule(module, android.HostAndDeviceSupported)
453 return module
454}
455
456func JavadocHostFactory() android.Module {
457 module := &Javadoc{}
458
459 module.AddProperties(&module.properties)
460
461 InitDroiddocModule(module, android.HostSupported)
462 return module
463}
464
Nan Zhanga40da042018-08-01 12:48:00 -0700465var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800466
Colin Cross83bb3162018-06-25 15:48:06 -0700467func (j *Javadoc) sdkVersion() string {
468 return String(j.properties.Sdk_version)
469}
470
471func (j *Javadoc) minSdkVersion() string {
472 return j.sdkVersion()
473}
474
Nan Zhang581fd212018-01-10 16:06:12 -0800475func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
476 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700477 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800478 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700479 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700480 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700481 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700482 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700483 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700484 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800485 }
Nan Zhang581fd212018-01-10 16:06:12 -0800486 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700487 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700488 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700489 }
Colin Cross42d48b72018-08-29 14:10:52 -0700490 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800491 }
492 }
493
Colin Cross42d48b72018-08-29 14:10:52 -0700494 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700495 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700496 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700497 }
Nan Zhang581fd212018-01-10 16:06:12 -0800498
499 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
500
501 // exclude_srcs may contain filegroup or genrule.
502 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700503
504 // arg_files may contains filegroup or genrule.
505 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800506}
507
Nan Zhangb2b33de2018-02-23 11:18:47 -0800508func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
509 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
510 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900511 // convert foo.bar.baz to foo/bar/baz
512 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
513 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800514 if _, found := whitelistPathPrefixes[prefix]; !found {
515 whitelistPathPrefixes[prefix] = true
516 }
517 }
518 }
519}
520
Nan Zhanga40da042018-08-01 12:48:00 -0700521func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
522 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900523
524 // aidl flags.
525 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
526 if len(aidlFlags) > 0 {
527 // optimization.
528 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
529 flags.aidlFlags = "$aidlFlags"
530 }
531
532 return flags
533}
534
535func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
536 aidlIncludeDirs android.Paths) []string {
537
538 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
539 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
540
541 var flags []string
542 if aidlPreprocess.Valid() {
543 flags = append(flags, "-p"+aidlPreprocess.String())
544 } else {
545 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
546 }
547
548 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
549 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
550 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
551 flags = append(flags, "-I"+src.String())
552 }
553
554 return flags
555}
556
557func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700558 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900559
560 outSrcFiles := make(android.Paths, 0, len(srcFiles))
561
562 for _, srcFile := range srcFiles {
563 switch srcFile.Ext() {
564 case ".aidl":
565 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
566 outSrcFiles = append(outSrcFiles, javaFile)
567 default:
568 outSrcFiles = append(outSrcFiles, srcFile)
569 }
570 }
571
572 return outSrcFiles
573}
574
Nan Zhang581fd212018-01-10 16:06:12 -0800575func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
576 var deps deps
577
Colin Cross83bb3162018-06-25 15:48:06 -0700578 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800579 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700580 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800581 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700582 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800583 }
584
585 ctx.VisitDirectDeps(func(module android.Module) {
586 otherName := ctx.OtherModuleName(module)
587 tag := ctx.OtherModuleDependencyTag(module)
588
Colin Cross2d24c1b2018-05-23 10:59:18 -0700589 switch tag {
590 case bootClasspathTag:
591 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800592 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700593 } else {
594 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
595 }
596 case libTag:
597 switch dep := module.(type) {
598 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800599 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700600 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700601 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900602 linkType := javaSdk
603 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
604 linkType = javaSystem
605 } else if sdkVersion == "" {
606 linkType = javaPlatform
607 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900608 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700609 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800610 checkProducesJars(ctx, dep)
611 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800612 default:
613 ctx.ModuleErrorf("depends on non-java module %q", otherName)
614 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700615 case srcsLibTag:
616 switch dep := module.(type) {
617 case Dependency:
618 srcs := dep.(SrcDependency).CompiledSrcs()
619 whitelistPathPrefixes := make(map[string]bool)
620 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
621 for _, src := range srcs {
622 if _, ok := src.(android.WritablePath); ok { // generated sources
623 deps.srcs = append(deps.srcs, src)
624 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700625 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700626 if strings.HasPrefix(src.Rel(), k) {
627 deps.srcs = append(deps.srcs, src)
628 break
629 }
630 }
631 }
632 }
633 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
634 default:
635 ctx.ModuleErrorf("depends on non-java module %q", otherName)
636 }
Nan Zhang357466b2018-04-17 17:38:36 -0700637 case systemModulesTag:
638 if deps.systemModules != nil {
639 panic("Found two system module dependencies")
640 }
641 sm := module.(*SystemModules)
642 if sm.outputFile == nil {
643 panic("Missing directory for system module dependency")
644 }
645 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800646 }
647 })
648 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
649 // may contain filegroup or genrule.
650 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700651 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900652 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800653
654 // srcs may depend on some genrule output.
655 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800656 j.srcJars = append(j.srcJars, deps.srcJars...)
657
Nan Zhang581fd212018-01-10 16:06:12 -0800658 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800659 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800660
661 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800662 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800663
Nan Zhang9c69a122018-08-22 10:22:08 -0700664 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800665 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
666 }
667 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800668
Nan Zhang1598a9e2018-09-04 17:14:32 -0700669 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
670 argFilesMap := map[string]android.Path{}
671
672 for _, f := range j.argFiles {
673 if _, exists := argFilesMap[f.Rel()]; !exists {
674 argFilesMap[f.Rel()] = f
675 } else {
676 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
677 f, argFilesMap[f.Rel()], f.Rel())
678 }
679 }
680
681 var err error
682 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
683 if strings.HasPrefix(name, "location ") {
684 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
685 if f, ok := argFilesMap[label]; ok {
686 return f.String(), nil
687 } else {
688 return "", fmt.Errorf("unknown location label %q", label)
689 }
690 } else if name == "genDir" {
691 return android.PathForModuleGen(ctx).String(), nil
692 }
693 return "", fmt.Errorf("unknown variable '$(%s)'", name)
694 })
695
696 if err != nil {
697 ctx.PropertyErrorf("args", "%s", err.Error())
698 }
699
Nan Zhang581fd212018-01-10 16:06:12 -0800700 return deps
701}
702
703func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
704 j.addDeps(ctx)
705}
706
707func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
708 deps := j.collectDeps(ctx)
709
710 var implicits android.Paths
711 implicits = append(implicits, deps.bootClasspath...)
712 implicits = append(implicits, deps.classpath...)
713
Nan Zhang1598a9e2018-09-04 17:14:32 -0700714 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700715
Colin Cross83bb3162018-06-25 15:48:06 -0700716 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700717 if len(deps.bootClasspath) > 0 {
718 var systemModules classpath
719 if deps.systemModules != nil {
720 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800721 }
Colin Cross997262f2018-06-19 22:49:39 -0700722 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
723 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800724 }
725 if len(deps.classpath.Strings()) > 0 {
726 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
727 }
728
729 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700730 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800731
Nan Zhangaf322cc2018-06-19 15:15:38 -0700732 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800733
Nan Zhang1598a9e2018-09-04 17:14:32 -0700734 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
735
Nan Zhang581fd212018-01-10 16:06:12 -0800736 ctx.Build(pctx, android.BuildParams{
737 Rule: javadoc,
738 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800739 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800740 ImplicitOutput: j.docZip,
741 Inputs: j.srcFiles,
742 Implicits: implicits,
743 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700744 "outDir": android.PathForModuleOut(ctx, "out").String(),
745 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
746 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800747 "srcJars": strings.Join(j.srcJars.Strings(), " "),
748 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700749 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800750 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700751 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800752 "docZip": j.docZip.String(),
753 },
754 })
755}
756
Nan Zhanga40da042018-08-01 12:48:00 -0700757//
758// Droiddoc
759//
760type Droiddoc struct {
761 Javadoc
762
763 properties DroiddocProperties
764 apiFile android.WritablePath
765 dexApiFile android.WritablePath
766 privateApiFile android.WritablePath
767 privateDexApiFile android.WritablePath
768 removedApiFile android.WritablePath
769 removedDexApiFile android.WritablePath
770 exactApiFile android.WritablePath
771 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700772 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700773
774 checkCurrentApiTimestamp android.WritablePath
775 updateCurrentApiTimestamp android.WritablePath
776 checkLastReleasedApiTimestamp android.WritablePath
777
Nan Zhanga40da042018-08-01 12:48:00 -0700778 apiFilePath android.Path
779}
780
Nan Zhanga40da042018-08-01 12:48:00 -0700781func DroiddocFactory() android.Module {
782 module := &Droiddoc{}
783
784 module.AddProperties(&module.properties,
785 &module.Javadoc.properties)
786
787 InitDroiddocModule(module, android.HostAndDeviceSupported)
788 return module
789}
790
791func DroiddocHostFactory() android.Module {
792 module := &Droiddoc{}
793
794 module.AddProperties(&module.properties,
795 &module.Javadoc.properties)
796
797 InitDroiddocModule(module, android.HostSupported)
798 return module
799}
800
801func (d *Droiddoc) ApiFilePath() android.Path {
802 return d.apiFilePath
803}
804
Nan Zhang581fd212018-01-10 16:06:12 -0800805func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
806 d.Javadoc.addDeps(ctx)
807
Nan Zhang79614d12018-04-19 18:03:39 -0700808 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800809 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
810 }
811
Nan Zhang581fd212018-01-10 16:06:12 -0800812 // knowntags may contain filegroup or genrule.
813 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700814
Nan Zhange2ba5d42018-07-11 15:16:55 -0700815 if String(d.properties.Static_doc_index_redirect) != "" {
816 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
817 }
818
819 if String(d.properties.Static_doc_properties) != "" {
820 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
821 }
822
Nan Zhang1598a9e2018-09-04 17:14:32 -0700823 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700824 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
825 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
826 }
827
Nan Zhang1598a9e2018-09-04 17:14:32 -0700828 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700829 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
830 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
831 }
Nan Zhang581fd212018-01-10 16:06:12 -0800832}
833
Nan Zhang66dc2362018-08-14 20:41:04 -0700834func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
835 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700836 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800837
Nan Zhanga40da042018-08-01 12:48:00 -0700838 *implicits = append(*implicits, deps.bootClasspath...)
839 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800840
Nan Zhangc94f9d82018-06-26 10:02:26 -0700841 if len(deps.bootClasspath.Strings()) > 0 {
842 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700843 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700844 }
Nan Zhanga40da042018-08-01 12:48:00 -0700845 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700846 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700847 dokkaClasspath := classpath{}
848 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
849 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
850 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700851
Nan Zhang9c69a122018-08-22 10:22:08 -0700852 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
853 // based stubs generation.
854 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
855 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
856 // the correct package name base path.
857 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
858 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
859 } else {
860 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
861 }
Nan Zhang581fd212018-01-10 16:06:12 -0800862
Nan Zhanga40da042018-08-01 12:48:00 -0700863 return flags, nil
864}
Nan Zhang581fd212018-01-10 16:06:12 -0800865
Nan Zhanga40da042018-08-01 12:48:00 -0700866func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700867 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800868
Nan Zhanga40da042018-08-01 12:48:00 -0700869 *implicits = append(*implicits, jsilver)
870 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700871
Nan Zhang46130972018-06-04 11:28:01 -0700872 var date string
873 if runtime.GOOS == "darwin" {
874 date = `date -r`
875 } else {
876 date = `date -d`
877 }
878
Nan Zhang443fa522018-08-20 20:58:28 -0700879 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
880 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
881 // 1.9 language features.
882 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700883 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800884 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700885 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700886
Nan Zhanga40da042018-08-01 12:48:00 -0700887 if String(d.properties.Custom_template) == "" {
888 // TODO: This is almost always droiddoc-templates-sdk
889 ctx.PropertyErrorf("custom_template", "must specify a template")
890 }
891
892 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700893 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700894 *implicits = append(*implicits, t.deps...)
895 args = args + " -templatedir " + t.dir.String()
896 } else {
897 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
898 }
899 })
900
901 if len(d.properties.Html_dirs) > 0 {
902 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
903 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
904 args = args + " -htmldir " + htmlDir.String()
905 }
906
907 if len(d.properties.Html_dirs) > 1 {
908 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
909 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
910 args = args + " -htmldir2 " + htmlDir2.String()
911 }
912
913 if len(d.properties.Html_dirs) > 2 {
914 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
915 }
916
917 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
918 *implicits = append(*implicits, knownTags...)
919
920 for _, kt := range knownTags {
921 args = args + " -knowntags " + kt.String()
922 }
923
924 for _, hdf := range d.properties.Hdf {
925 args = args + " -hdf " + hdf
926 }
927
928 if String(d.properties.Proofread_file) != "" {
929 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
930 args = args + " -proofread " + proofreadFile.String()
931 }
932
933 if String(d.properties.Todo_file) != "" {
934 // tricky part:
935 // we should not compute full path for todo_file through PathForModuleOut().
936 // the non-standard doclet will get the full path relative to "-o".
937 args = args + " -todo " + String(d.properties.Todo_file)
938 }
939
940 if String(d.properties.Resourcesdir) != "" {
941 // TODO: should we add files under resourcesDir to the implicits? It seems that
942 // resourcesDir is one sub dir of htmlDir
943 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
944 args = args + " -resourcesdir " + resourcesDir.String()
945 }
946
947 if String(d.properties.Resourcesoutdir) != "" {
948 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
949 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
950 }
951 return args
952}
953
Nan Zhang1598a9e2018-09-04 17:14:32 -0700954func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
955 implicitOutputs *android.WritablePaths) string {
956 var doclavaFlags string
957 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
958 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
959 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700960 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
961 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700962 *implicitOutputs = append(*implicitOutputs, d.apiFile)
963 d.apiFilePath = d.apiFile
964 }
965
Nan Zhang1598a9e2018-09-04 17:14:32 -0700966 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
967 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
968 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700969 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
970 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700971 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
972 }
973
974 if String(d.properties.Private_api_filename) != "" {
975 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
976 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700977 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
978 }
979
980 if String(d.properties.Dex_api_filename) != "" {
981 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
982 doclavaFlags += " -dexApi " + d.dexApiFile.String()
983 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
984 }
985
986 if String(d.properties.Private_dex_api_filename) != "" {
987 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
988 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700989 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
990 }
991
992 if String(d.properties.Removed_dex_api_filename) != "" {
993 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
994 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700995 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
996 }
997
998 if String(d.properties.Exact_api_filename) != "" {
999 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1000 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001001 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1002 }
1003
1004 if String(d.properties.Dex_mapping_filename) != "" {
1005 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1006 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001007 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1008 }
1009
Nan Zhang66dc2362018-08-14 20:41:04 -07001010 if String(d.properties.Proguard_filename) != "" {
1011 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1012 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001013 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1014 }
1015
Nan Zhanga40da042018-08-01 12:48:00 -07001016 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001017 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001018 }
1019
1020 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001021 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001022 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001023
1024 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001025}
1026
1027func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1028 var cmds string
1029 if String(d.properties.Static_doc_index_redirect) != "" {
1030 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1031 "static_doc_index_redirect")
1032 *implicits = append(*implicits, static_doc_index_redirect)
1033 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001034 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001035 }
1036
1037 if String(d.properties.Static_doc_properties) != "" {
1038 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1039 "static_doc_properties")
1040 *implicits = append(*implicits, static_doc_properties)
1041 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001042 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001043 }
1044 return cmds
1045}
1046
Nan Zhang1598a9e2018-09-04 17:14:32 -07001047func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1048 implicitOutputs android.WritablePaths,
1049 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1050 ctx.Build(pctx, android.BuildParams{
1051 Rule: javadoc,
1052 Description: "Doclava",
1053 Output: d.Javadoc.stubsSrcJar,
1054 Inputs: d.Javadoc.srcFiles,
1055 Implicits: implicits,
1056 ImplicitOutputs: implicitOutputs,
1057 Args: map[string]string{
1058 "outDir": android.PathForModuleOut(ctx, "out").String(),
1059 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1060 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1061 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1062 "opts": opts,
1063 "bootclasspathArgs": bootclasspathArgs,
1064 "classpathArgs": classpathArgs,
1065 "sourcepathArgs": sourcepathArgs,
1066 "docZip": d.Javadoc.docZip.String(),
1067 "postDoclavaCmds": postDoclavaCmds,
1068 },
1069 })
1070}
1071
1072func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1073 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1074 ctx.Build(pctx, android.BuildParams{
1075 Rule: apiCheck,
1076 Description: "Doclava Check API",
1077 Output: output,
1078 Inputs: nil,
1079 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1080 checkApiClasspath...),
1081 Args: map[string]string{
1082 "msg": msg,
1083 "classpath": checkApiClasspath.FormJavaClassPath(""),
1084 "opts": opts,
1085 "apiFile": apiFile.String(),
1086 "apiFileToCheck": d.apiFile.String(),
1087 "removedApiFile": removedApiFile.String(),
1088 "removedApiFileToCheck": d.removedApiFile.String(),
1089 },
1090 })
1091}
1092
1093func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1094 classpathArgs, opts string) {
1095 ctx.Build(pctx, android.BuildParams{
1096 Rule: dokka,
1097 Description: "Dokka",
1098 Output: d.Javadoc.stubsSrcJar,
1099 Inputs: d.Javadoc.srcFiles,
1100 Implicits: implicits,
1101 Args: map[string]string{
1102 "outDir": android.PathForModuleOut(ctx, "out").String(),
1103 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1104 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1105 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1106 "classpathArgs": classpathArgs,
1107 "opts": opts,
1108 "docZip": d.Javadoc.docZip.String(),
1109 },
1110 })
1111}
1112
1113func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1114 deps := d.Javadoc.collectDeps(ctx)
1115
1116 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1117 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1118 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1119 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1120
1121 var implicits android.Paths
1122 implicits = append(implicits, d.Javadoc.srcJars...)
1123 implicits = append(implicits, d.Javadoc.argFiles...)
1124
1125 var implicitOutputs android.WritablePaths
1126 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1127 for _, o := range d.Javadoc.properties.Out {
1128 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1129 }
1130
1131 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1132 if err != nil {
1133 return
1134 }
1135
1136 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1137 if Bool(d.properties.Dokka_enabled) {
1138 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1139 } else {
1140 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1141 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1142 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1143 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1144 flags.postDoclavaCmds)
1145 }
1146
1147 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1148 !ctx.Config().IsPdkBuild() {
1149 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1150 "check_api.current.api_file")
1151 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1152 "check_api.current_removed_api_file")
1153
1154 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1155 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1156 fmt.Sprintf(`\n******************************\n`+
1157 `You have tried to change the API from what has been previously approved.\n\n`+
1158 `To make these errors go away, you have two choices:\n`+
1159 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1160 ` errors above.\n\n`+
1161 ` 2. You can update current.txt by executing the following command:\n`+
1162 ` make %s-update-current-api\n\n`+
1163 ` To submit the revised current.txt to the main Android repository,\n`+
1164 ` you will need approval.\n`+
1165 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1166 d.checkCurrentApiTimestamp)
1167
1168 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1169 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1170 d.updateCurrentApiTimestamp)
1171 }
1172
1173 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1174 !ctx.Config().IsPdkBuild() {
1175 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1176 "check_api.last_released.api_file")
1177 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1178 "check_api.last_released.removed_api_file")
1179
1180 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1181 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1182 `\n******************************\n`+
1183 `You have tried to change the API from what has been previously released in\n`+
1184 `an SDK. Please fix the errors listed above.\n`+
1185 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1186 d.checkLastReleasedApiTimestamp)
1187 }
1188}
1189
1190//
1191// Droidstubs
1192//
1193type Droidstubs struct {
1194 Javadoc
1195
Nan Zhang71bbe632018-09-17 14:32:21 -07001196 properties DroidstubsProperties
1197 apiFile android.WritablePath
1198 apiXmlFile android.WritablePath
1199 lastReleasedApiXmlFile android.WritablePath
1200 dexApiFile android.WritablePath
1201 privateApiFile android.WritablePath
1202 privateDexApiFile android.WritablePath
1203 removedApiFile android.WritablePath
1204 removedDexApiFile android.WritablePath
1205 apiMappingFile android.WritablePath
1206 exactApiFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001207
1208 checkCurrentApiTimestamp android.WritablePath
1209 updateCurrentApiTimestamp android.WritablePath
1210 checkLastReleasedApiTimestamp android.WritablePath
1211
1212 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001213 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001214
1215 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001216
1217 jdiffDocZip android.WritablePath
1218 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001219}
1220
1221func DroidstubsFactory() android.Module {
1222 module := &Droidstubs{}
1223
1224 module.AddProperties(&module.properties,
1225 &module.Javadoc.properties)
1226
1227 InitDroiddocModule(module, android.HostAndDeviceSupported)
1228 return module
1229}
1230
1231func DroidstubsHostFactory() android.Module {
1232 module := &Droidstubs{}
1233
1234 module.AddProperties(&module.properties,
1235 &module.Javadoc.properties)
1236
1237 InitDroiddocModule(module, android.HostSupported)
1238 return module
1239}
1240
1241func (d *Droidstubs) ApiFilePath() android.Path {
1242 return d.apiFilePath
1243}
1244
1245func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1246 d.Javadoc.addDeps(ctx)
1247
1248 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1249 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1250 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1251 }
1252
1253 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1254 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1255 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1256 }
1257
1258 if String(d.properties.Previous_api) != "" {
1259 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1260 }
1261
1262 if len(d.properties.Merge_annotations_dirs) != 0 {
1263 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1264 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1265 }
1266 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001267
1268 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1269 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1270 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1271 }
1272 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001273}
1274
1275func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1276 deps deps) (droiddocBuilderFlags, error) {
1277 var flags droiddocBuilderFlags
1278
1279 *implicits = append(*implicits, deps.bootClasspath...)
1280 *implicits = append(*implicits, deps.classpath...)
1281
1282 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1283 // since it doesn't support system modules yet.
1284 if len(deps.bootClasspath.Strings()) > 0 {
1285 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1286 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1287 }
1288 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1289
1290 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1291
1292 return flags, nil
1293}
1294
1295func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1296 implicitOutputs *android.WritablePaths) string {
1297 var metalavaFlags string
1298 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1299 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1300 String(d.properties.Api_filename) != "" {
1301 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1302 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1303 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1304 d.apiFilePath = d.apiFile
1305 }
1306
1307 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1308 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1309 String(d.properties.Removed_api_filename) != "" {
1310 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1311 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1312 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1313 }
1314
1315 if String(d.properties.Private_api_filename) != "" {
1316 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1317 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1318 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1319 }
1320
1321 if String(d.properties.Dex_api_filename) != "" {
1322 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1323 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1324 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1325 }
1326
1327 if String(d.properties.Private_dex_api_filename) != "" {
1328 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1329 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1330 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1331 }
1332
1333 if String(d.properties.Removed_dex_api_filename) != "" {
1334 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1335 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1336 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1337 }
1338
1339 if String(d.properties.Exact_api_filename) != "" {
1340 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1341 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1342 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1343 }
1344
Nan Zhang9c69a122018-08-22 10:22:08 -07001345 if String(d.properties.Dex_mapping_filename) != "" {
1346 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1347 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1348 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1349 }
1350
1351 if Bool(d.properties.Write_sdk_values) {
1352 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1353 }
1354
Nan Zhang1598a9e2018-09-04 17:14:32 -07001355 if Bool(d.properties.Create_doc_stubs) {
1356 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1357 } else {
1358 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1359 }
1360
1361 return metalavaFlags
1362}
1363
1364func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1365 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001366 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001367 if Bool(d.properties.Annotations_enabled) {
1368 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001369 ctx.PropertyErrorf("metalava_previous_api",
1370 "has to be non-empty if annotations was enabled!")
1371 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001372 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001373 "metalava_previous_api")
1374 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001375
Nan Zhangd05a4362018-08-15 13:28:54 -07001376 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001377
1378 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1379 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1380
Nan Zhangf4936b02018-08-01 15:00:28 -07001381 flags += " --extract-annotations " + d.annotationsZip.String()
1382
Nan Zhang1598a9e2018-09-04 17:14:32 -07001383 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001384 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001385 "has to be non-empty if annotations was enabled!")
1386 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001387 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1388 if t, ok := m.(*ExportedDroiddocDir); ok {
1389 *implicits = append(*implicits, t.deps...)
1390 flags += " --merge-annotations " + t.dir.String()
1391 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001392 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001393 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1394 }
1395 })
Nan Zhanga40da042018-08-01 12:48:00 -07001396 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1397 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1398 }
1399
1400 return flags
1401}
1402
Nan Zhang9c69a122018-08-22 10:22:08 -07001403func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1404 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1405 var flags string
1406 if Bool(d.properties.Api_levels_annotations_enabled) {
1407 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1408 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1409
1410 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1411 ctx.PropertyErrorf("api_levels_annotations_dirs",
1412 "has to be non-empty if api levels annotations was enabled!")
1413 }
1414
1415 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1416 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1417 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1418
1419 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1420 if t, ok := m.(*ExportedDroiddocDir); ok {
1421 var androidJars android.Paths
1422 for _, dep := range t.deps {
1423 if strings.HasSuffix(dep.String(), "android.jar") {
1424 androidJars = append(androidJars, dep)
1425 }
1426 }
1427 *implicits = append(*implicits, androidJars...)
1428 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1429 } else {
1430 ctx.PropertyErrorf("api_levels_annotations_dirs",
1431 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1432 }
1433 })
1434
1435 }
1436
1437 return flags
1438}
1439
Nan Zhang71bbe632018-09-17 14:32:21 -07001440func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1441 implicitOutputs *android.WritablePaths) string {
1442 var flags string
1443 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1444 if d.apiFile.String() == "" {
1445 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1446 }
1447
1448 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1449 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1450
1451 flags = " --api-xml " + d.apiXmlFile.String()
1452
1453 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1454 ctx.PropertyErrorf("check_api.last_released.api_file",
1455 "has to be non-empty if jdiff was enabled!")
1456 }
1457 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1458 "check_api.last_released.api_file")
1459 *implicits = append(*implicits, lastReleasedApi)
1460
1461 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1462 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1463
1464 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1465 d.lastReleasedApiXmlFile.String()
1466 }
1467
1468 return flags
1469}
1470
Nan Zhang1598a9e2018-09-04 17:14:32 -07001471func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1472 implicitOutputs android.WritablePaths, javaVersion,
1473 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001474
Nan Zhang86d2d552018-08-09 15:33:27 -07001475 ctx.Build(pctx, android.BuildParams{
1476 Rule: metalava,
1477 Description: "Metalava",
1478 Output: d.Javadoc.stubsSrcJar,
1479 Inputs: d.Javadoc.srcFiles,
1480 Implicits: implicits,
1481 ImplicitOutputs: implicitOutputs,
1482 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001483 "outDir": android.PathForModuleOut(ctx, "out").String(),
1484 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1485 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1486 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001487 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001488 "bootclasspathArgs": bootclasspathArgs,
1489 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001490 "sourcepathArgs": sourcepathArgs,
1491 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001492 },
1493 })
1494}
1495
Nan Zhang1598a9e2018-09-04 17:14:32 -07001496func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1497 apiFile, removedApiFile android.Path, implicits android.Paths,
1498 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001499 output android.WritablePath) {
1500 ctx.Build(pctx, android.BuildParams{
1501 Rule: metalavaApiCheck,
1502 Description: "Metalava Check API",
1503 Output: output,
1504 Inputs: d.Javadoc.srcFiles,
1505 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1506 implicits...),
1507 Args: map[string]string{
1508 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1509 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1510 "javaVersion": javaVersion,
1511 "bootclasspathArgs": bootclasspathArgs,
1512 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001513 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001514 "opts": opts,
1515 "msg": msg,
1516 },
1517 })
1518}
1519
Nan Zhang71bbe632018-09-17 14:32:21 -07001520func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1521 implicitOutputs android.WritablePaths,
1522 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1523 ctx.Build(pctx, android.BuildParams{
1524 Rule: javadoc,
1525 Description: "Jdiff",
1526 Output: d.jdiffStubsSrcJar,
1527 Inputs: d.Javadoc.srcFiles,
1528 Implicits: implicits,
1529 ImplicitOutputs: implicitOutputs,
1530 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001531 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1532 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1533 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001534 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1535 "opts": opts,
1536 "bootclasspathArgs": bootclasspathArgs,
1537 "classpathArgs": classpathArgs,
1538 "sourcepathArgs": sourcepathArgs,
1539 "docZip": d.jdiffDocZip.String(),
1540 },
1541 })
1542}
1543
Nan Zhang1598a9e2018-09-04 17:14:32 -07001544func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001545 deps := d.Javadoc.collectDeps(ctx)
1546
1547 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001548
Nan Zhanga40da042018-08-01 12:48:00 -07001549 var implicits android.Paths
1550 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001551 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001552
1553 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001554 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001555 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1556 }
1557
1558 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001559 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001560 jdiffImplicits := implicits
1561
Nan Zhanga40da042018-08-01 12:48:00 -07001562 if err != nil {
1563 return
1564 }
1565
Nan Zhang1598a9e2018-09-04 17:14:32 -07001566 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1567 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001568 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001569 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1570
Nan Zhang1598a9e2018-09-04 17:14:32 -07001571 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1572 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1573 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1574 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1575 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001576 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001577 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1578 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Nan Zhang9c69a122018-08-22 10:22:08 -07001579 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001580 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001581
Nan Zhang1598a9e2018-09-04 17:14:32 -07001582 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1583 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001584 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1585 "check_api.current.api_file")
1586 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1587 "check_api.current_removed_api_file")
1588
Nan Zhang2760dfc2018-08-24 17:32:54 +00001589 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001590 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1591 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001592
Nan Zhang1598a9e2018-09-04 17:14:32 -07001593 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1594 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1595 fmt.Sprintf(`\n******************************\n`+
1596 `You have tried to change the API from what has been previously approved.\n\n`+
1597 `To make these errors go away, you have two choices:\n`+
1598 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1599 ` errors above.\n\n`+
1600 ` 2. You can update current.txt by executing the following command:\n`+
1601 ` make %s-update-current-api\n\n`+
1602 ` To submit the revised current.txt to the main Android repository,\n`+
1603 ` you will need approval.\n`+
1604 `******************************\n`, ctx.ModuleName()),
1605 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001606
1607 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001608 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1609 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001610 }
Nan Zhanga40da042018-08-01 12:48:00 -07001611
Nan Zhang1598a9e2018-09-04 17:14:32 -07001612 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1613 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001614 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1615 "check_api.last_released.api_file")
1616 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1617 "check_api.last_released.removed_api_file")
1618
Nan Zhang2760dfc2018-08-24 17:32:54 +00001619 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001620 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1621 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001622
Nan Zhang1598a9e2018-09-04 17:14:32 -07001623 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1624 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1625 `\n******************************\n`+
1626 `You have tried to change the API from what has been previously released in\n`+
1627 `an SDK. Please fix the errors listed above.\n`+
1628 `******************************\n`,
1629 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001630 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001631
1632 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1633
1634 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1635 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1636
1637 var jdiffImplicitOutputs android.WritablePaths
1638 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1639
1640 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1641 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1642
1643 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1644 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1645 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1646 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1647 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1648 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1649
1650 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1651 flags.sourcepathArgs, opts)
1652 }
Nan Zhang581fd212018-01-10 16:06:12 -08001653}
Dan Willemsencc090972018-02-26 14:33:31 -08001654
Nan Zhanga40da042018-08-01 12:48:00 -07001655//
Nan Zhangf4936b02018-08-01 15:00:28 -07001656// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001657//
Dan Willemsencc090972018-02-26 14:33:31 -08001658var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001659var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001660var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001661
Nan Zhangf4936b02018-08-01 15:00:28 -07001662type ExportedDroiddocDirProperties struct {
1663 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001664 Path *string
1665}
1666
Nan Zhangf4936b02018-08-01 15:00:28 -07001667type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001668 android.ModuleBase
1669
Nan Zhangf4936b02018-08-01 15:00:28 -07001670 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001671
1672 deps android.Paths
1673 dir android.Path
1674}
1675
Nan Zhangf4936b02018-08-01 15:00:28 -07001676func ExportedDroiddocDirFactory() android.Module {
1677 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001678 module.AddProperties(&module.properties)
1679 android.InitAndroidModule(module)
1680 return module
1681}
1682
Nan Zhangf4936b02018-08-01 15:00:28 -07001683func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001684
Nan Zhangf4936b02018-08-01 15:00:28 -07001685func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001686 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1687 d.dir = path
1688 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1689}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001690
1691//
1692// Defaults
1693//
1694type DocDefaults struct {
1695 android.ModuleBase
1696 android.DefaultsModuleBase
1697}
1698
1699func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1700}
1701
1702func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1703}
1704
1705func DocDefaultsFactory() android.Module {
1706 module := &DocDefaults{}
1707
1708 module.AddProperties(
1709 &JavadocProperties{},
1710 &DroiddocProperties{},
1711 )
1712
1713 android.InitDefaultsModule(module)
1714
1715 return module
1716}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001717
1718func StubsDefaultsFactory() android.Module {
1719 module := &DocDefaults{}
1720
1721 module.AddProperties(
1722 &JavadocProperties{},
1723 &DroidstubsProperties{},
1724 )
1725
1726 android.InitDefaultsModule(module)
1727
1728 return module
1729}