blob: 2ab0d312a97cf194a6971bccdcf0b3d0ea37218e [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 Gillin77167902018-09-19 18:16:26 +0100343 // 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 -0700344 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700345
Pete Gillin77167902018-09-19 18:16:26 +0100346 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
347 Merge_inclusion_annotations_dirs []string
348
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
350 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700351
352 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
353 Api_levels_annotations_enabled *bool
354
355 // the dirs which Metalava extracts API levels annotations from.
356 Api_levels_annotations_dirs []string
357
358 // if set to true, collect the values used by the Dev tools and
359 // write them in files packaged with the SDK. Defaults to false.
360 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700361
362 // If set to true, .xml based public API file will be also generated, and
363 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
364 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800365}
366
Nan Zhanga40da042018-08-01 12:48:00 -0700367//
368// Common flags passed down to build rule
369//
370type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700371 bootClasspathArgs string
372 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700373 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700374 dokkaClasspathArgs string
375 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700376
Nan Zhanga40da042018-08-01 12:48:00 -0700377 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700378 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700379 postDoclavaCmds string
380
Nan Zhang9c69a122018-08-22 10:22:08 -0700381 metalavaStubsFlags string
382 metalavaAnnotationsFlags string
383 metalavaApiLevelsAnnotationsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700384
Nan Zhang71bbe632018-09-17 14:32:21 -0700385 metalavaApiToXmlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700386}
387
388func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
389 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
390 android.InitDefaultableModule(module)
391}
392
Nan Zhang1598a9e2018-09-04 17:14:32 -0700393func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
394 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
395 return true
396 } else if String(apiToCheck.Api_file) != "" {
397 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
398 } else if String(apiToCheck.Removed_api_file) != "" {
399 panic("for " + apiVersionTag + " api_file has to be non-empty!")
400 }
401
402 return false
403}
404
405type ApiFilePath interface {
406 ApiFilePath() android.Path
407}
408
409func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
410 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
411 ctx.Build(pctx, android.BuildParams{
412 Rule: updateApi,
413 Description: "Update API",
414 Output: output,
415 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
416 destApiFile, destRemovedApiFile),
417 Args: map[string]string{
418 "destApiFile": destApiFile.String(),
419 "srcApiFile": srcApiFile.String(),
420 "destRemovedApiFile": destRemovedApiFile.String(),
421 "srcRemovedApiFile": srcRemovedApiFile.String(),
422 },
423 })
424}
425
Nan Zhanga40da042018-08-01 12:48:00 -0700426//
427// Javadoc
428//
Nan Zhang581fd212018-01-10 16:06:12 -0800429type Javadoc struct {
430 android.ModuleBase
431 android.DefaultableModuleBase
432
433 properties JavadocProperties
434
435 srcJars android.Paths
436 srcFiles android.Paths
437 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700438 argFiles android.Paths
439
440 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800441
Nan Zhangccff0f72018-03-08 17:26:16 -0800442 docZip android.WritablePath
443 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800444}
445
Nan Zhangb2b33de2018-02-23 11:18:47 -0800446func (j *Javadoc) Srcs() android.Paths {
447 return android.Paths{j.stubsSrcJar}
448}
449
Nan Zhang581fd212018-01-10 16:06:12 -0800450func JavadocFactory() android.Module {
451 module := &Javadoc{}
452
453 module.AddProperties(&module.properties)
454
455 InitDroiddocModule(module, android.HostAndDeviceSupported)
456 return module
457}
458
459func JavadocHostFactory() android.Module {
460 module := &Javadoc{}
461
462 module.AddProperties(&module.properties)
463
464 InitDroiddocModule(module, android.HostSupported)
465 return module
466}
467
Nan Zhanga40da042018-08-01 12:48:00 -0700468var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800469
Colin Cross83bb3162018-06-25 15:48:06 -0700470func (j *Javadoc) sdkVersion() string {
471 return String(j.properties.Sdk_version)
472}
473
474func (j *Javadoc) minSdkVersion() string {
475 return j.sdkVersion()
476}
477
Nan Zhang581fd212018-01-10 16:06:12 -0800478func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
479 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700480 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800481 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700482 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700483 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700484 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700485 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700486 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700487 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800488 }
Nan Zhang581fd212018-01-10 16:06:12 -0800489 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700490 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700491 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700492 }
Colin Cross42d48b72018-08-29 14:10:52 -0700493 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800494 }
495 }
496
Colin Cross42d48b72018-08-29 14:10:52 -0700497 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700498 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700499 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700500 }
Nan Zhang581fd212018-01-10 16:06:12 -0800501
502 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
503
504 // exclude_srcs may contain filegroup or genrule.
505 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700506
507 // arg_files may contains filegroup or genrule.
508 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800509}
510
Nan Zhangb2b33de2018-02-23 11:18:47 -0800511func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
512 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
513 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900514 // convert foo.bar.baz to foo/bar/baz
515 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
516 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800517 if _, found := whitelistPathPrefixes[prefix]; !found {
518 whitelistPathPrefixes[prefix] = true
519 }
520 }
521 }
522}
523
Nan Zhanga40da042018-08-01 12:48:00 -0700524func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
525 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900526
527 // aidl flags.
528 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
529 if len(aidlFlags) > 0 {
530 // optimization.
531 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
532 flags.aidlFlags = "$aidlFlags"
533 }
534
535 return flags
536}
537
538func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
539 aidlIncludeDirs android.Paths) []string {
540
541 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
542 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
543
544 var flags []string
545 if aidlPreprocess.Valid() {
546 flags = append(flags, "-p"+aidlPreprocess.String())
547 } else {
548 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
549 }
550
551 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
552 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
553 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
554 flags = append(flags, "-I"+src.String())
555 }
556
557 return flags
558}
559
560func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700561 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900562
563 outSrcFiles := make(android.Paths, 0, len(srcFiles))
564
565 for _, srcFile := range srcFiles {
566 switch srcFile.Ext() {
567 case ".aidl":
568 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
569 outSrcFiles = append(outSrcFiles, javaFile)
570 default:
571 outSrcFiles = append(outSrcFiles, srcFile)
572 }
573 }
574
575 return outSrcFiles
576}
577
Nan Zhang581fd212018-01-10 16:06:12 -0800578func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
579 var deps deps
580
Colin Cross83bb3162018-06-25 15:48:06 -0700581 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800582 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700583 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800584 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700585 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800586 }
587
588 ctx.VisitDirectDeps(func(module android.Module) {
589 otherName := ctx.OtherModuleName(module)
590 tag := ctx.OtherModuleDependencyTag(module)
591
Colin Cross2d24c1b2018-05-23 10:59:18 -0700592 switch tag {
593 case bootClasspathTag:
594 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800595 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700596 } else {
597 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
598 }
599 case libTag:
600 switch dep := module.(type) {
601 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800602 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700603 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700604 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900605 linkType := javaSdk
606 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
607 linkType = javaSystem
608 } else if sdkVersion == "" {
609 linkType = javaPlatform
610 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900611 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700612 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800613 checkProducesJars(ctx, dep)
614 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800615 default:
616 ctx.ModuleErrorf("depends on non-java module %q", otherName)
617 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700618 case srcsLibTag:
619 switch dep := module.(type) {
620 case Dependency:
621 srcs := dep.(SrcDependency).CompiledSrcs()
622 whitelistPathPrefixes := make(map[string]bool)
623 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
624 for _, src := range srcs {
625 if _, ok := src.(android.WritablePath); ok { // generated sources
626 deps.srcs = append(deps.srcs, src)
627 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700628 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700629 if strings.HasPrefix(src.Rel(), k) {
630 deps.srcs = append(deps.srcs, src)
631 break
632 }
633 }
634 }
635 }
636 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
637 default:
638 ctx.ModuleErrorf("depends on non-java module %q", otherName)
639 }
Nan Zhang357466b2018-04-17 17:38:36 -0700640 case systemModulesTag:
641 if deps.systemModules != nil {
642 panic("Found two system module dependencies")
643 }
644 sm := module.(*SystemModules)
645 if sm.outputFile == nil {
646 panic("Missing directory for system module dependency")
647 }
648 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800649 }
650 })
651 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
652 // may contain filegroup or genrule.
653 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700654 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900655 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800656
657 // srcs may depend on some genrule output.
658 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800659 j.srcJars = append(j.srcJars, deps.srcJars...)
660
Nan Zhang581fd212018-01-10 16:06:12 -0800661 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800662 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800663
664 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800665 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800666
Nan Zhang9c69a122018-08-22 10:22:08 -0700667 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800668 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
669 }
670 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800671
Nan Zhang1598a9e2018-09-04 17:14:32 -0700672 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
673 argFilesMap := map[string]android.Path{}
674
675 for _, f := range j.argFiles {
676 if _, exists := argFilesMap[f.Rel()]; !exists {
677 argFilesMap[f.Rel()] = f
678 } else {
679 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
680 f, argFilesMap[f.Rel()], f.Rel())
681 }
682 }
683
684 var err error
685 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
686 if strings.HasPrefix(name, "location ") {
687 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
688 if f, ok := argFilesMap[label]; ok {
689 return f.String(), nil
690 } else {
691 return "", fmt.Errorf("unknown location label %q", label)
692 }
693 } else if name == "genDir" {
694 return android.PathForModuleGen(ctx).String(), nil
695 }
696 return "", fmt.Errorf("unknown variable '$(%s)'", name)
697 })
698
699 if err != nil {
700 ctx.PropertyErrorf("args", "%s", err.Error())
701 }
702
Nan Zhang581fd212018-01-10 16:06:12 -0800703 return deps
704}
705
706func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
707 j.addDeps(ctx)
708}
709
710func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
711 deps := j.collectDeps(ctx)
712
713 var implicits android.Paths
714 implicits = append(implicits, deps.bootClasspath...)
715 implicits = append(implicits, deps.classpath...)
716
Nan Zhang1598a9e2018-09-04 17:14:32 -0700717 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700718
Colin Cross83bb3162018-06-25 15:48:06 -0700719 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700720 if len(deps.bootClasspath) > 0 {
721 var systemModules classpath
722 if deps.systemModules != nil {
723 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800724 }
Colin Cross997262f2018-06-19 22:49:39 -0700725 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
726 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800727 }
728 if len(deps.classpath.Strings()) > 0 {
729 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
730 }
731
732 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700733 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800734
Nan Zhangaf322cc2018-06-19 15:15:38 -0700735 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800736
Nan Zhang1598a9e2018-09-04 17:14:32 -0700737 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
738
Nan Zhang581fd212018-01-10 16:06:12 -0800739 ctx.Build(pctx, android.BuildParams{
740 Rule: javadoc,
741 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800742 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800743 ImplicitOutput: j.docZip,
744 Inputs: j.srcFiles,
745 Implicits: implicits,
746 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700747 "outDir": android.PathForModuleOut(ctx, "out").String(),
748 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
749 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800750 "srcJars": strings.Join(j.srcJars.Strings(), " "),
751 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700752 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800753 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700754 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800755 "docZip": j.docZip.String(),
756 },
757 })
758}
759
Nan Zhanga40da042018-08-01 12:48:00 -0700760//
761// Droiddoc
762//
763type Droiddoc struct {
764 Javadoc
765
766 properties DroiddocProperties
767 apiFile android.WritablePath
768 dexApiFile android.WritablePath
769 privateApiFile android.WritablePath
770 privateDexApiFile android.WritablePath
771 removedApiFile android.WritablePath
772 removedDexApiFile android.WritablePath
773 exactApiFile android.WritablePath
774 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700775 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700776
777 checkCurrentApiTimestamp android.WritablePath
778 updateCurrentApiTimestamp android.WritablePath
779 checkLastReleasedApiTimestamp android.WritablePath
780
Nan Zhanga40da042018-08-01 12:48:00 -0700781 apiFilePath android.Path
782}
783
Nan Zhanga40da042018-08-01 12:48:00 -0700784func DroiddocFactory() android.Module {
785 module := &Droiddoc{}
786
787 module.AddProperties(&module.properties,
788 &module.Javadoc.properties)
789
790 InitDroiddocModule(module, android.HostAndDeviceSupported)
791 return module
792}
793
794func DroiddocHostFactory() android.Module {
795 module := &Droiddoc{}
796
797 module.AddProperties(&module.properties,
798 &module.Javadoc.properties)
799
800 InitDroiddocModule(module, android.HostSupported)
801 return module
802}
803
804func (d *Droiddoc) ApiFilePath() android.Path {
805 return d.apiFilePath
806}
807
Nan Zhang581fd212018-01-10 16:06:12 -0800808func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
809 d.Javadoc.addDeps(ctx)
810
Nan Zhang79614d12018-04-19 18:03:39 -0700811 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800812 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
813 }
814
Nan Zhang581fd212018-01-10 16:06:12 -0800815 // knowntags may contain filegroup or genrule.
816 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700817
Nan Zhange2ba5d42018-07-11 15:16:55 -0700818 if String(d.properties.Static_doc_index_redirect) != "" {
819 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
820 }
821
822 if String(d.properties.Static_doc_properties) != "" {
823 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
824 }
825
Nan Zhang1598a9e2018-09-04 17:14:32 -0700826 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700827 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
828 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
829 }
830
Nan Zhang1598a9e2018-09-04 17:14:32 -0700831 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700832 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
833 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
834 }
Nan Zhang581fd212018-01-10 16:06:12 -0800835}
836
Nan Zhang66dc2362018-08-14 20:41:04 -0700837func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
838 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700839 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800840
Nan Zhanga40da042018-08-01 12:48:00 -0700841 *implicits = append(*implicits, deps.bootClasspath...)
842 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800843
Nan Zhangc94f9d82018-06-26 10:02:26 -0700844 if len(deps.bootClasspath.Strings()) > 0 {
845 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700846 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700847 }
Nan Zhanga40da042018-08-01 12:48:00 -0700848 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700849 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700850 dokkaClasspath := classpath{}
851 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
852 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
853 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700854
Nan Zhang9c69a122018-08-22 10:22:08 -0700855 // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava
856 // based stubs generation.
857 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
858 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
859 // the correct package name base path.
860 if len(d.Javadoc.properties.Local_sourcepaths) > 0 {
861 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
862 } else {
863 flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String()
864 }
Nan Zhang581fd212018-01-10 16:06:12 -0800865
Nan Zhanga40da042018-08-01 12:48:00 -0700866 return flags, nil
867}
Nan Zhang581fd212018-01-10 16:06:12 -0800868
Nan Zhanga40da042018-08-01 12:48:00 -0700869func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700870 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800871
Nan Zhanga40da042018-08-01 12:48:00 -0700872 *implicits = append(*implicits, jsilver)
873 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700874
Nan Zhang46130972018-06-04 11:28:01 -0700875 var date string
876 if runtime.GOOS == "darwin" {
877 date = `date -r`
878 } else {
879 date = `date -d`
880 }
881
Nan Zhang443fa522018-08-20 20:58:28 -0700882 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
883 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
884 // 1.9 language features.
885 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700886 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800887 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700888 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700889
Nan Zhanga40da042018-08-01 12:48:00 -0700890 if String(d.properties.Custom_template) == "" {
891 // TODO: This is almost always droiddoc-templates-sdk
892 ctx.PropertyErrorf("custom_template", "must specify a template")
893 }
894
895 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700896 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700897 *implicits = append(*implicits, t.deps...)
898 args = args + " -templatedir " + t.dir.String()
899 } else {
900 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
901 }
902 })
903
904 if len(d.properties.Html_dirs) > 0 {
905 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
906 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
907 args = args + " -htmldir " + htmlDir.String()
908 }
909
910 if len(d.properties.Html_dirs) > 1 {
911 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
912 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
913 args = args + " -htmldir2 " + htmlDir2.String()
914 }
915
916 if len(d.properties.Html_dirs) > 2 {
917 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
918 }
919
920 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
921 *implicits = append(*implicits, knownTags...)
922
923 for _, kt := range knownTags {
924 args = args + " -knowntags " + kt.String()
925 }
926
927 for _, hdf := range d.properties.Hdf {
928 args = args + " -hdf " + hdf
929 }
930
931 if String(d.properties.Proofread_file) != "" {
932 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
933 args = args + " -proofread " + proofreadFile.String()
934 }
935
936 if String(d.properties.Todo_file) != "" {
937 // tricky part:
938 // we should not compute full path for todo_file through PathForModuleOut().
939 // the non-standard doclet will get the full path relative to "-o".
940 args = args + " -todo " + String(d.properties.Todo_file)
941 }
942
943 if String(d.properties.Resourcesdir) != "" {
944 // TODO: should we add files under resourcesDir to the implicits? It seems that
945 // resourcesDir is one sub dir of htmlDir
946 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
947 args = args + " -resourcesdir " + resourcesDir.String()
948 }
949
950 if String(d.properties.Resourcesoutdir) != "" {
951 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
952 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
953 }
954 return args
955}
956
Nan Zhang1598a9e2018-09-04 17:14:32 -0700957func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
958 implicitOutputs *android.WritablePaths) string {
959 var doclavaFlags string
960 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
961 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
962 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700963 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
964 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700965 *implicitOutputs = append(*implicitOutputs, d.apiFile)
966 d.apiFilePath = d.apiFile
967 }
968
Nan Zhang1598a9e2018-09-04 17:14:32 -0700969 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
970 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
971 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700972 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
973 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700974 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
975 }
976
977 if String(d.properties.Private_api_filename) != "" {
978 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
979 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700980 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
981 }
982
983 if String(d.properties.Dex_api_filename) != "" {
984 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
985 doclavaFlags += " -dexApi " + d.dexApiFile.String()
986 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
987 }
988
989 if String(d.properties.Private_dex_api_filename) != "" {
990 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
991 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700992 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
993 }
994
995 if String(d.properties.Removed_dex_api_filename) != "" {
996 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
997 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700998 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
999 }
1000
1001 if String(d.properties.Exact_api_filename) != "" {
1002 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1003 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001004 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1005 }
1006
1007 if String(d.properties.Dex_mapping_filename) != "" {
1008 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1009 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001010 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1011 }
1012
Nan Zhang66dc2362018-08-14 20:41:04 -07001013 if String(d.properties.Proguard_filename) != "" {
1014 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
1015 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -07001016 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
1017 }
1018
Nan Zhanga40da042018-08-01 12:48:00 -07001019 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -07001020 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001021 }
1022
1023 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -07001024 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001025 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001026
1027 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -07001028}
1029
1030func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1031 var cmds string
1032 if String(d.properties.Static_doc_index_redirect) != "" {
1033 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1034 "static_doc_index_redirect")
1035 *implicits = append(*implicits, static_doc_index_redirect)
1036 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001037 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001038 }
1039
1040 if String(d.properties.Static_doc_properties) != "" {
1041 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1042 "static_doc_properties")
1043 *implicits = append(*implicits, static_doc_properties)
1044 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001045 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001046 }
1047 return cmds
1048}
1049
Nan Zhang1598a9e2018-09-04 17:14:32 -07001050func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1051 implicitOutputs android.WritablePaths,
1052 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1053 ctx.Build(pctx, android.BuildParams{
1054 Rule: javadoc,
1055 Description: "Doclava",
1056 Output: d.Javadoc.stubsSrcJar,
1057 Inputs: d.Javadoc.srcFiles,
1058 Implicits: implicits,
1059 ImplicitOutputs: implicitOutputs,
1060 Args: map[string]string{
1061 "outDir": android.PathForModuleOut(ctx, "out").String(),
1062 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1063 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1064 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1065 "opts": opts,
1066 "bootclasspathArgs": bootclasspathArgs,
1067 "classpathArgs": classpathArgs,
1068 "sourcepathArgs": sourcepathArgs,
1069 "docZip": d.Javadoc.docZip.String(),
1070 "postDoclavaCmds": postDoclavaCmds,
1071 },
1072 })
1073}
1074
1075func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1076 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1077 ctx.Build(pctx, android.BuildParams{
1078 Rule: apiCheck,
1079 Description: "Doclava Check API",
1080 Output: output,
1081 Inputs: nil,
1082 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1083 checkApiClasspath...),
1084 Args: map[string]string{
1085 "msg": msg,
1086 "classpath": checkApiClasspath.FormJavaClassPath(""),
1087 "opts": opts,
1088 "apiFile": apiFile.String(),
1089 "apiFileToCheck": d.apiFile.String(),
1090 "removedApiFile": removedApiFile.String(),
1091 "removedApiFileToCheck": d.removedApiFile.String(),
1092 },
1093 })
1094}
1095
1096func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1097 classpathArgs, opts string) {
1098 ctx.Build(pctx, android.BuildParams{
1099 Rule: dokka,
1100 Description: "Dokka",
1101 Output: d.Javadoc.stubsSrcJar,
1102 Inputs: d.Javadoc.srcFiles,
1103 Implicits: implicits,
1104 Args: map[string]string{
1105 "outDir": android.PathForModuleOut(ctx, "out").String(),
1106 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1107 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1108 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1109 "classpathArgs": classpathArgs,
1110 "opts": opts,
1111 "docZip": d.Javadoc.docZip.String(),
1112 },
1113 })
1114}
1115
1116func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1117 deps := d.Javadoc.collectDeps(ctx)
1118
1119 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1120 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1121 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1122 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1123
1124 var implicits android.Paths
1125 implicits = append(implicits, d.Javadoc.srcJars...)
1126 implicits = append(implicits, d.Javadoc.argFiles...)
1127
1128 var implicitOutputs android.WritablePaths
1129 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1130 for _, o := range d.Javadoc.properties.Out {
1131 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1132 }
1133
1134 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1135 if err != nil {
1136 return
1137 }
1138
1139 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1140 if Bool(d.properties.Dokka_enabled) {
1141 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1142 } else {
1143 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1144 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1145 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1146 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1147 flags.postDoclavaCmds)
1148 }
1149
1150 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1151 !ctx.Config().IsPdkBuild() {
1152 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1153 "check_api.current.api_file")
1154 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1155 "check_api.current_removed_api_file")
1156
1157 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1158 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1159 fmt.Sprintf(`\n******************************\n`+
1160 `You have tried to change the API from what has been previously approved.\n\n`+
1161 `To make these errors go away, you have two choices:\n`+
1162 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1163 ` errors above.\n\n`+
1164 ` 2. You can update current.txt by executing the following command:\n`+
1165 ` make %s-update-current-api\n\n`+
1166 ` To submit the revised current.txt to the main Android repository,\n`+
1167 ` you will need approval.\n`+
1168 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1169 d.checkCurrentApiTimestamp)
1170
1171 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1172 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1173 d.updateCurrentApiTimestamp)
1174 }
1175
1176 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1177 !ctx.Config().IsPdkBuild() {
1178 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1179 "check_api.last_released.api_file")
1180 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1181 "check_api.last_released.removed_api_file")
1182
1183 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1184 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1185 `\n******************************\n`+
1186 `You have tried to change the API from what has been previously released in\n`+
1187 `an SDK. Please fix the errors listed above.\n`+
1188 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1189 d.checkLastReleasedApiTimestamp)
1190 }
1191}
1192
1193//
1194// Droidstubs
1195//
1196type Droidstubs struct {
1197 Javadoc
1198
Nan Zhang71bbe632018-09-17 14:32:21 -07001199 properties DroidstubsProperties
1200 apiFile android.WritablePath
1201 apiXmlFile android.WritablePath
1202 lastReleasedApiXmlFile android.WritablePath
1203 dexApiFile android.WritablePath
1204 privateApiFile android.WritablePath
1205 privateDexApiFile android.WritablePath
1206 removedApiFile android.WritablePath
1207 removedDexApiFile android.WritablePath
1208 apiMappingFile android.WritablePath
1209 exactApiFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001210
1211 checkCurrentApiTimestamp android.WritablePath
1212 updateCurrentApiTimestamp android.WritablePath
1213 checkLastReleasedApiTimestamp android.WritablePath
1214
1215 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001216 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001217
1218 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001219
1220 jdiffDocZip android.WritablePath
1221 jdiffStubsSrcJar android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001222}
1223
1224func DroidstubsFactory() android.Module {
1225 module := &Droidstubs{}
1226
1227 module.AddProperties(&module.properties,
1228 &module.Javadoc.properties)
1229
1230 InitDroiddocModule(module, android.HostAndDeviceSupported)
1231 return module
1232}
1233
1234func DroidstubsHostFactory() android.Module {
1235 module := &Droidstubs{}
1236
1237 module.AddProperties(&module.properties,
1238 &module.Javadoc.properties)
1239
1240 InitDroiddocModule(module, android.HostSupported)
1241 return module
1242}
1243
1244func (d *Droidstubs) ApiFilePath() android.Path {
1245 return d.apiFilePath
1246}
1247
1248func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1249 d.Javadoc.addDeps(ctx)
1250
1251 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1252 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1253 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1254 }
1255
1256 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1257 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1258 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1259 }
1260
1261 if String(d.properties.Previous_api) != "" {
1262 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1263 }
1264
1265 if len(d.properties.Merge_annotations_dirs) != 0 {
1266 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1267 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1268 }
1269 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001270
Pete Gillin77167902018-09-19 18:16:26 +01001271 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1272 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1273 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1274 }
1275 }
1276
Nan Zhang9c69a122018-08-22 10:22:08 -07001277 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1278 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1279 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1280 }
1281 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001282}
1283
1284func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1285 deps deps) (droiddocBuilderFlags, error) {
1286 var flags droiddocBuilderFlags
1287
1288 *implicits = append(*implicits, deps.bootClasspath...)
1289 *implicits = append(*implicits, deps.classpath...)
1290
1291 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1292 // since it doesn't support system modules yet.
1293 if len(deps.bootClasspath.Strings()) > 0 {
1294 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1295 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1296 }
1297 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1298
1299 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1300
1301 return flags, nil
1302}
1303
1304func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1305 implicitOutputs *android.WritablePaths) string {
1306 var metalavaFlags string
1307 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1308 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1309 String(d.properties.Api_filename) != "" {
1310 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1311 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1312 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1313 d.apiFilePath = d.apiFile
1314 }
1315
1316 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1317 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1318 String(d.properties.Removed_api_filename) != "" {
1319 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1320 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1321 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1322 }
1323
1324 if String(d.properties.Private_api_filename) != "" {
1325 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1326 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1327 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1328 }
1329
1330 if String(d.properties.Dex_api_filename) != "" {
1331 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1332 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1333 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1334 }
1335
1336 if String(d.properties.Private_dex_api_filename) != "" {
1337 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1338 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1339 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1340 }
1341
1342 if String(d.properties.Removed_dex_api_filename) != "" {
1343 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1344 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1345 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1346 }
1347
1348 if String(d.properties.Exact_api_filename) != "" {
1349 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1350 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1351 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1352 }
1353
Nan Zhang9c69a122018-08-22 10:22:08 -07001354 if String(d.properties.Dex_mapping_filename) != "" {
1355 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
1356 metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String()
1357 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
1358 }
1359
1360 if Bool(d.properties.Write_sdk_values) {
1361 metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String()
1362 }
1363
Nan Zhang1598a9e2018-09-04 17:14:32 -07001364 if Bool(d.properties.Create_doc_stubs) {
1365 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1366 } else {
1367 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1368 }
1369
1370 return metalavaFlags
1371}
1372
1373func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1374 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001375 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001376 if Bool(d.properties.Annotations_enabled) {
1377 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001378 ctx.PropertyErrorf("metalava_previous_api",
1379 "has to be non-empty if annotations was enabled!")
1380 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001381 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001382 "metalava_previous_api")
1383 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001384
Nan Zhangd05a4362018-08-15 13:28:54 -07001385 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001386
1387 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1388 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1389
Nan Zhangf4936b02018-08-01 15:00:28 -07001390 flags += " --extract-annotations " + d.annotationsZip.String()
1391
Nan Zhang1598a9e2018-09-04 17:14:32 -07001392 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001393 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001394 "has to be non-empty if annotations was enabled!")
1395 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001396 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1397 if t, ok := m.(*ExportedDroiddocDir); ok {
1398 *implicits = append(*implicits, t.deps...)
Pete Gillin77167902018-09-19 18:16:26 +01001399 flags += " --merge-qualifier-annotations " + t.dir.String()
Nan Zhangf4936b02018-08-01 15:00:28 -07001400 } else {
Nan Zhang9c69a122018-08-22 10:22:08 -07001401 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhangf4936b02018-08-01 15:00:28 -07001402 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1403 }
1404 })
Nan Zhanga40da042018-08-01 12:48:00 -07001405 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1406 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1407 }
Pete Gillin77167902018-09-19 18:16:26 +01001408 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1409 if t, ok := m.(*ExportedDroiddocDir); ok {
1410 *implicits = append(*implicits, t.deps...)
1411 flags += " --merge-inclusion-annotations " + t.dir.String()
1412 } else {
1413 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1414 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1415 }
1416 })
Nan Zhanga40da042018-08-01 12:48:00 -07001417
1418 return flags
1419}
1420
Nan Zhang9c69a122018-08-22 10:22:08 -07001421func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext,
1422 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
1423 var flags string
1424 if Bool(d.properties.Api_levels_annotations_enabled) {
1425 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1426 *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml)
1427
1428 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1429 ctx.PropertyErrorf("api_levels_annotations_dirs",
1430 "has to be non-empty if api levels annotations was enabled!")
1431 }
1432
1433 flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " +
1434 d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() +
1435 " --current-codename " + ctx.Config().PlatformSdkCodename() + " "
1436
1437 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1438 if t, ok := m.(*ExportedDroiddocDir); ok {
1439 var androidJars android.Paths
1440 for _, dep := range t.deps {
1441 if strings.HasSuffix(dep.String(), "android.jar") {
1442 androidJars = append(androidJars, dep)
1443 }
1444 }
1445 *implicits = append(*implicits, androidJars...)
1446 flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar "
1447 } else {
1448 ctx.PropertyErrorf("api_levels_annotations_dirs",
1449 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1450 }
1451 })
1452
1453 }
1454
1455 return flags
1456}
1457
Nan Zhang71bbe632018-09-17 14:32:21 -07001458func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths,
1459 implicitOutputs *android.WritablePaths) string {
1460 var flags string
1461 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1462 if d.apiFile.String() == "" {
1463 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1464 }
1465
1466 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
1467 *implicitOutputs = append(*implicitOutputs, d.apiXmlFile)
1468
1469 flags = " --api-xml " + d.apiXmlFile.String()
1470
1471 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1472 ctx.PropertyErrorf("check_api.last_released.api_file",
1473 "has to be non-empty if jdiff was enabled!")
1474 }
1475 lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1476 "check_api.last_released.api_file")
1477 *implicits = append(*implicits, lastReleasedApi)
1478
1479 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
1480 *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile)
1481
1482 flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " +
1483 d.lastReleasedApiXmlFile.String()
1484 }
1485
1486 return flags
1487}
1488
Nan Zhang1598a9e2018-09-04 17:14:32 -07001489func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1490 implicitOutputs android.WritablePaths, javaVersion,
1491 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001492
Nan Zhang86d2d552018-08-09 15:33:27 -07001493 ctx.Build(pctx, android.BuildParams{
1494 Rule: metalava,
1495 Description: "Metalava",
1496 Output: d.Javadoc.stubsSrcJar,
1497 Inputs: d.Javadoc.srcFiles,
1498 Implicits: implicits,
1499 ImplicitOutputs: implicitOutputs,
1500 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001501 "outDir": android.PathForModuleOut(ctx, "out").String(),
1502 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1503 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1504 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001505 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001506 "bootclasspathArgs": bootclasspathArgs,
1507 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001508 "sourcepathArgs": sourcepathArgs,
1509 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001510 },
1511 })
1512}
1513
Nan Zhang1598a9e2018-09-04 17:14:32 -07001514func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1515 apiFile, removedApiFile android.Path, implicits android.Paths,
1516 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001517 output android.WritablePath) {
1518 ctx.Build(pctx, android.BuildParams{
1519 Rule: metalavaApiCheck,
1520 Description: "Metalava Check API",
1521 Output: output,
1522 Inputs: d.Javadoc.srcFiles,
1523 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1524 implicits...),
1525 Args: map[string]string{
1526 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1527 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1528 "javaVersion": javaVersion,
1529 "bootclasspathArgs": bootclasspathArgs,
1530 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001531 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001532 "opts": opts,
1533 "msg": msg,
1534 },
1535 })
1536}
1537
Nan Zhang71bbe632018-09-17 14:32:21 -07001538func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths,
1539 implicitOutputs android.WritablePaths,
1540 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
1541 ctx.Build(pctx, android.BuildParams{
1542 Rule: javadoc,
1543 Description: "Jdiff",
1544 Output: d.jdiffStubsSrcJar,
1545 Inputs: d.Javadoc.srcFiles,
1546 Implicits: implicits,
1547 ImplicitOutputs: implicitOutputs,
1548 Args: map[string]string{
Nan Zhang23a1ba62018-09-19 11:19:39 -07001549 "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(),
1550 "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(),
1551 "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(),
Nan Zhang71bbe632018-09-17 14:32:21 -07001552 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1553 "opts": opts,
1554 "bootclasspathArgs": bootclasspathArgs,
1555 "classpathArgs": classpathArgs,
1556 "sourcepathArgs": sourcepathArgs,
1557 "docZip": d.jdiffDocZip.String(),
1558 },
1559 })
1560}
1561
Nan Zhang1598a9e2018-09-04 17:14:32 -07001562func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001563 deps := d.Javadoc.collectDeps(ctx)
1564
1565 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001566
Nan Zhanga40da042018-08-01 12:48:00 -07001567 var implicits android.Paths
1568 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001569 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001570
1571 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001572 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001573 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1574 }
1575
1576 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001577 metalavaCheckApiImplicits := implicits
Nan Zhang71bbe632018-09-17 14:32:21 -07001578 jdiffImplicits := implicits
1579
Nan Zhanga40da042018-08-01 12:48:00 -07001580 if err != nil {
1581 return
1582 }
1583
Nan Zhang1598a9e2018-09-04 17:14:32 -07001584 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1585 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang9c69a122018-08-22 10:22:08 -07001586 flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang71bbe632018-09-17 14:32:21 -07001587 flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs)
1588
Nan Zhang1598a9e2018-09-04 17:14:32 -07001589 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1590 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1591 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1592 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1593 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001594 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001595 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1596 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
Nan Zhang9c69a122018-08-22 10:22:08 -07001597 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+
Nan Zhang71bbe632018-09-17 14:32:21 -07001598 flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001599
Nan Zhang1598a9e2018-09-04 17:14:32 -07001600 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1601 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001602 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1603 "check_api.current.api_file")
1604 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1605 "check_api.current_removed_api_file")
1606
Nan Zhang2760dfc2018-08-24 17:32:54 +00001607 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001608 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1609 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001610
Nan Zhang1598a9e2018-09-04 17:14:32 -07001611 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1612 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1613 fmt.Sprintf(`\n******************************\n`+
1614 `You have tried to change the API from what has been previously approved.\n\n`+
1615 `To make these errors go away, you have two choices:\n`+
1616 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1617 ` errors above.\n\n`+
1618 ` 2. You can update current.txt by executing the following command:\n`+
1619 ` make %s-update-current-api\n\n`+
1620 ` To submit the revised current.txt to the main Android repository,\n`+
1621 ` you will need approval.\n`+
1622 `******************************\n`, ctx.ModuleName()),
1623 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001624
1625 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001626 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1627 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001628 }
Nan Zhanga40da042018-08-01 12:48:00 -07001629
Nan Zhang1598a9e2018-09-04 17:14:32 -07001630 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1631 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001632 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1633 "check_api.last_released.api_file")
1634 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1635 "check_api.last_released.removed_api_file")
1636
Nan Zhang2760dfc2018-08-24 17:32:54 +00001637 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001638 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1639 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001640
Nan Zhang1598a9e2018-09-04 17:14:32 -07001641 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1642 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1643 `\n******************************\n`+
1644 `You have tried to change the API from what has been previously released in\n`+
1645 `an SDK. Please fix the errors listed above.\n`+
1646 `******************************\n`,
1647 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001648 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001649
1650 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1651
Nan Zhang86b06202018-09-21 17:09:21 -07001652 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1653 // since there's cron job downstream that fetch this .zip file periodically.
1654 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001655 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1656 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1657
1658 var jdiffImplicitOutputs android.WritablePaths
1659 jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip)
1660
1661 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
1662 jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...)
1663
1664 opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " +
1665 "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " +
1666 "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) +
1667 " -newapidir " + filepath.Dir(d.apiXmlFile.String()) +
1668 " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) +
1669 " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String())
1670
1671 d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1672 flags.sourcepathArgs, opts)
1673 }
Nan Zhang581fd212018-01-10 16:06:12 -08001674}
Dan Willemsencc090972018-02-26 14:33:31 -08001675
Nan Zhanga40da042018-08-01 12:48:00 -07001676//
Nan Zhangf4936b02018-08-01 15:00:28 -07001677// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001678//
Dan Willemsencc090972018-02-26 14:33:31 -08001679var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001680var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001681var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001682var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001683
Nan Zhangf4936b02018-08-01 15:00:28 -07001684type ExportedDroiddocDirProperties struct {
1685 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001686 Path *string
1687}
1688
Nan Zhangf4936b02018-08-01 15:00:28 -07001689type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001690 android.ModuleBase
1691
Nan Zhangf4936b02018-08-01 15:00:28 -07001692 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001693
1694 deps android.Paths
1695 dir android.Path
1696}
1697
Nan Zhangf4936b02018-08-01 15:00:28 -07001698func ExportedDroiddocDirFactory() android.Module {
1699 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001700 module.AddProperties(&module.properties)
1701 android.InitAndroidModule(module)
1702 return module
1703}
1704
Nan Zhangf4936b02018-08-01 15:00:28 -07001705func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001706
Nan Zhangf4936b02018-08-01 15:00:28 -07001707func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001708 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1709 d.dir = path
1710 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1711}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001712
1713//
1714// Defaults
1715//
1716type DocDefaults struct {
1717 android.ModuleBase
1718 android.DefaultsModuleBase
1719}
1720
1721func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1722}
1723
1724func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1725}
1726
1727func DocDefaultsFactory() android.Module {
1728 module := &DocDefaults{}
1729
1730 module.AddProperties(
1731 &JavadocProperties{},
1732 &DroiddocProperties{},
1733 )
1734
1735 android.InitDefaultsModule(module)
1736
1737 return module
1738}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001739
1740func StubsDefaultsFactory() android.Module {
1741 module := &DocDefaults{}
1742
1743 module.AddProperties(
1744 &JavadocProperties{},
1745 &DroidstubsProperties{},
1746 )
1747
1748 android.InitDefaultsModule(module)
1749
1750 return module
1751}