blob: 3123baf567b20522c6ec1f4d283d243a452cb386 [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
324 // the generated exact API filename by Doclava.
325 Exact_api_filename *string
326
327 Check_api struct {
328 Last_released ApiToCheck
329
330 Current ApiToCheck
331 }
Nan Zhang79614d12018-04-19 18:03:39 -0700332
333 // user can specify the version of previous released API file in order to do compatibility check.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700334 Previous_api *string
Nan Zhang79614d12018-04-19 18:03:39 -0700335
336 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700337 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700338
Pete Gillinb13a0152018-07-19 17:56:49 +0100339 // a list of top-level directories containing files to merge annotations from.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700340 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700341
Nan Zhang1598a9e2018-09-04 17:14:32 -0700342 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
343 Create_doc_stubs *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800344}
345
Nan Zhanga40da042018-08-01 12:48:00 -0700346//
347// Common flags passed down to build rule
348//
349type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700350 bootClasspathArgs string
351 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700352 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700353 dokkaClasspathArgs string
354 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700355
Nan Zhanga40da042018-08-01 12:48:00 -0700356 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700357 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700358 postDoclavaCmds string
359
Nan Zhang2760dfc2018-08-24 17:32:54 +0000360 metalavaStubsFlags string
361 metalavaAnnotationsFlags string
362 metalavaJavadocFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700363
Nan Zhang86d2d552018-08-09 15:33:27 -0700364 metalavaDokkaFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700365}
366
367func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
368 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
369 android.InitDefaultableModule(module)
370}
371
Nan Zhang1598a9e2018-09-04 17:14:32 -0700372func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
373 if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
374 return true
375 } else if String(apiToCheck.Api_file) != "" {
376 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
377 } else if String(apiToCheck.Removed_api_file) != "" {
378 panic("for " + apiVersionTag + " api_file has to be non-empty!")
379 }
380
381 return false
382}
383
384type ApiFilePath interface {
385 ApiFilePath() android.Path
386}
387
388func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile,
389 srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) {
390 ctx.Build(pctx, android.BuildParams{
391 Rule: updateApi,
392 Description: "Update API",
393 Output: output,
394 Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile,
395 destApiFile, destRemovedApiFile),
396 Args: map[string]string{
397 "destApiFile": destApiFile.String(),
398 "srcApiFile": srcApiFile.String(),
399 "destRemovedApiFile": destRemovedApiFile.String(),
400 "srcRemovedApiFile": srcRemovedApiFile.String(),
401 },
402 })
403}
404
Nan Zhanga40da042018-08-01 12:48:00 -0700405//
406// Javadoc
407//
Nan Zhang581fd212018-01-10 16:06:12 -0800408type Javadoc struct {
409 android.ModuleBase
410 android.DefaultableModuleBase
411
412 properties JavadocProperties
413
414 srcJars android.Paths
415 srcFiles android.Paths
416 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700417 argFiles android.Paths
418
419 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800420
Nan Zhangccff0f72018-03-08 17:26:16 -0800421 docZip android.WritablePath
422 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800423}
424
Nan Zhangb2b33de2018-02-23 11:18:47 -0800425func (j *Javadoc) Srcs() android.Paths {
426 return android.Paths{j.stubsSrcJar}
427}
428
Nan Zhang581fd212018-01-10 16:06:12 -0800429func JavadocFactory() android.Module {
430 module := &Javadoc{}
431
432 module.AddProperties(&module.properties)
433
434 InitDroiddocModule(module, android.HostAndDeviceSupported)
435 return module
436}
437
438func JavadocHostFactory() android.Module {
439 module := &Javadoc{}
440
441 module.AddProperties(&module.properties)
442
443 InitDroiddocModule(module, android.HostSupported)
444 return module
445}
446
Nan Zhanga40da042018-08-01 12:48:00 -0700447var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800448
Colin Cross83bb3162018-06-25 15:48:06 -0700449func (j *Javadoc) sdkVersion() string {
450 return String(j.properties.Sdk_version)
451}
452
453func (j *Javadoc) minSdkVersion() string {
454 return j.sdkVersion()
455}
456
Nan Zhang581fd212018-01-10 16:06:12 -0800457func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
458 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700459 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800460 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700461 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700462 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700463 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700464 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700465 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700466 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800467 }
Nan Zhang581fd212018-01-10 16:06:12 -0800468 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700469 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700470 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700471 }
Colin Cross42d48b72018-08-29 14:10:52 -0700472 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800473 }
474 }
475
Colin Cross42d48b72018-08-29 14:10:52 -0700476 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700477 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700478 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700479 }
Nan Zhang581fd212018-01-10 16:06:12 -0800480
481 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
482
483 // exclude_srcs may contain filegroup or genrule.
484 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700485
486 // arg_files may contains filegroup or genrule.
487 android.ExtractSourcesDeps(ctx, j.properties.Arg_files)
Nan Zhang581fd212018-01-10 16:06:12 -0800488}
489
Nan Zhangb2b33de2018-02-23 11:18:47 -0800490func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
491 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
492 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900493 // convert foo.bar.baz to foo/bar/baz
494 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
495 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800496 if _, found := whitelistPathPrefixes[prefix]; !found {
497 whitelistPathPrefixes[prefix] = true
498 }
499 }
500 }
501}
502
Nan Zhanga40da042018-08-01 12:48:00 -0700503func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
504 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900505
506 // aidl flags.
507 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
508 if len(aidlFlags) > 0 {
509 // optimization.
510 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
511 flags.aidlFlags = "$aidlFlags"
512 }
513
514 return flags
515}
516
517func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
518 aidlIncludeDirs android.Paths) []string {
519
520 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
521 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
522
523 var flags []string
524 if aidlPreprocess.Valid() {
525 flags = append(flags, "-p"+aidlPreprocess.String())
526 } else {
527 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
528 }
529
530 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
531 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
532 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
533 flags = append(flags, "-I"+src.String())
534 }
535
536 return flags
537}
538
539func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700540 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900541
542 outSrcFiles := make(android.Paths, 0, len(srcFiles))
543
544 for _, srcFile := range srcFiles {
545 switch srcFile.Ext() {
546 case ".aidl":
547 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
548 outSrcFiles = append(outSrcFiles, javaFile)
549 default:
550 outSrcFiles = append(outSrcFiles, srcFile)
551 }
552 }
553
554 return outSrcFiles
555}
556
Nan Zhang581fd212018-01-10 16:06:12 -0800557func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
558 var deps deps
559
Colin Cross83bb3162018-06-25 15:48:06 -0700560 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800561 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700562 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800563 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700564 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800565 }
566
567 ctx.VisitDirectDeps(func(module android.Module) {
568 otherName := ctx.OtherModuleName(module)
569 tag := ctx.OtherModuleDependencyTag(module)
570
Colin Cross2d24c1b2018-05-23 10:59:18 -0700571 switch tag {
572 case bootClasspathTag:
573 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800574 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700575 } else {
576 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
577 }
578 case libTag:
579 switch dep := module.(type) {
580 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800581 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700582 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700583 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900584 linkType := javaSdk
585 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
586 linkType = javaSystem
587 } else if sdkVersion == "" {
588 linkType = javaPlatform
589 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900590 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700591 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800592 checkProducesJars(ctx, dep)
593 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800594 default:
595 ctx.ModuleErrorf("depends on non-java module %q", otherName)
596 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700597 case srcsLibTag:
598 switch dep := module.(type) {
599 case Dependency:
600 srcs := dep.(SrcDependency).CompiledSrcs()
601 whitelistPathPrefixes := make(map[string]bool)
602 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
603 for _, src := range srcs {
604 if _, ok := src.(android.WritablePath); ok { // generated sources
605 deps.srcs = append(deps.srcs, src)
606 } else { // select source path for documentation based on whitelist path prefixs.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700607 for k := range whitelistPathPrefixes {
Colin Crossa1ce2a02018-06-20 15:19:39 -0700608 if strings.HasPrefix(src.Rel(), k) {
609 deps.srcs = append(deps.srcs, src)
610 break
611 }
612 }
613 }
614 }
615 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
616 default:
617 ctx.ModuleErrorf("depends on non-java module %q", otherName)
618 }
Nan Zhang357466b2018-04-17 17:38:36 -0700619 case systemModulesTag:
620 if deps.systemModules != nil {
621 panic("Found two system module dependencies")
622 }
623 sm := module.(*SystemModules)
624 if sm.outputFile == nil {
625 panic("Missing directory for system module dependency")
626 }
627 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800628 }
629 })
630 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
631 // may contain filegroup or genrule.
632 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700633 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900634 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800635
636 // srcs may depend on some genrule output.
637 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800638 j.srcJars = append(j.srcJars, deps.srcJars...)
639
Nan Zhang581fd212018-01-10 16:06:12 -0800640 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800641 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800642
643 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800644 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800645
646 if j.properties.Local_sourcepaths == nil {
647 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
648 }
649 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800650
Nan Zhang1598a9e2018-09-04 17:14:32 -0700651 j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil)
652 argFilesMap := map[string]android.Path{}
653
654 for _, f := range j.argFiles {
655 if _, exists := argFilesMap[f.Rel()]; !exists {
656 argFilesMap[f.Rel()] = f
657 } else {
658 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
659 f, argFilesMap[f.Rel()], f.Rel())
660 }
661 }
662
663 var err error
664 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
665 if strings.HasPrefix(name, "location ") {
666 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
667 if f, ok := argFilesMap[label]; ok {
668 return f.String(), nil
669 } else {
670 return "", fmt.Errorf("unknown location label %q", label)
671 }
672 } else if name == "genDir" {
673 return android.PathForModuleGen(ctx).String(), nil
674 }
675 return "", fmt.Errorf("unknown variable '$(%s)'", name)
676 })
677
678 if err != nil {
679 ctx.PropertyErrorf("args", "%s", err.Error())
680 }
681
Nan Zhang581fd212018-01-10 16:06:12 -0800682 return deps
683}
684
685func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
686 j.addDeps(ctx)
687}
688
689func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
690 deps := j.collectDeps(ctx)
691
692 var implicits android.Paths
693 implicits = append(implicits, deps.bootClasspath...)
694 implicits = append(implicits, deps.classpath...)
695
Nan Zhang1598a9e2018-09-04 17:14:32 -0700696 var bootClasspathArgs, classpathArgs, sourcepathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700697
Colin Cross83bb3162018-06-25 15:48:06 -0700698 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700699 if len(deps.bootClasspath) > 0 {
700 var systemModules classpath
701 if deps.systemModules != nil {
702 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800703 }
Colin Cross997262f2018-06-19 22:49:39 -0700704 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
705 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800706 }
707 if len(deps.classpath.Strings()) > 0 {
708 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
709 }
710
711 implicits = append(implicits, j.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700712 implicits = append(implicits, j.argFiles...)
Nan Zhang581fd212018-01-10 16:06:12 -0800713
Nan Zhangaf322cc2018-06-19 15:15:38 -0700714 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800715
Nan Zhang1598a9e2018-09-04 17:14:32 -0700716 sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":")
717
Nan Zhang581fd212018-01-10 16:06:12 -0800718 ctx.Build(pctx, android.BuildParams{
719 Rule: javadoc,
720 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800721 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800722 ImplicitOutput: j.docZip,
723 Inputs: j.srcFiles,
724 Implicits: implicits,
725 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700726 "outDir": android.PathForModuleOut(ctx, "out").String(),
727 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
728 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800729 "srcJars": strings.Join(j.srcJars.Strings(), " "),
730 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700731 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800732 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -0700733 "sourcepathArgs": sourcepathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800734 "docZip": j.docZip.String(),
735 },
736 })
737}
738
Nan Zhanga40da042018-08-01 12:48:00 -0700739//
740// Droiddoc
741//
742type Droiddoc struct {
743 Javadoc
744
745 properties DroiddocProperties
746 apiFile android.WritablePath
747 dexApiFile android.WritablePath
748 privateApiFile android.WritablePath
749 privateDexApiFile android.WritablePath
750 removedApiFile android.WritablePath
751 removedDexApiFile android.WritablePath
752 exactApiFile android.WritablePath
753 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700754 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700755
756 checkCurrentApiTimestamp android.WritablePath
757 updateCurrentApiTimestamp android.WritablePath
758 checkLastReleasedApiTimestamp android.WritablePath
759
Nan Zhanga40da042018-08-01 12:48:00 -0700760 apiFilePath android.Path
761}
762
Nan Zhanga40da042018-08-01 12:48:00 -0700763func DroiddocFactory() android.Module {
764 module := &Droiddoc{}
765
766 module.AddProperties(&module.properties,
767 &module.Javadoc.properties)
768
769 InitDroiddocModule(module, android.HostAndDeviceSupported)
770 return module
771}
772
773func DroiddocHostFactory() android.Module {
774 module := &Droiddoc{}
775
776 module.AddProperties(&module.properties,
777 &module.Javadoc.properties)
778
779 InitDroiddocModule(module, android.HostSupported)
780 return module
781}
782
783func (d *Droiddoc) ApiFilePath() android.Path {
784 return d.apiFilePath
785}
786
Nan Zhang581fd212018-01-10 16:06:12 -0800787func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
788 d.Javadoc.addDeps(ctx)
789
Nan Zhang79614d12018-04-19 18:03:39 -0700790 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800791 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
792 }
793
Nan Zhang581fd212018-01-10 16:06:12 -0800794 // knowntags may contain filegroup or genrule.
795 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700796
Nan Zhange2ba5d42018-07-11 15:16:55 -0700797 if String(d.properties.Static_doc_index_redirect) != "" {
798 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
799 }
800
801 if String(d.properties.Static_doc_properties) != "" {
802 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
803 }
804
Nan Zhang1598a9e2018-09-04 17:14:32 -0700805 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700806 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
807 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
808 }
809
Nan Zhang1598a9e2018-09-04 17:14:32 -0700810 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
Nan Zhang61819ce2018-05-04 18:49:16 -0700811 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
812 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
813 }
Nan Zhang581fd212018-01-10 16:06:12 -0800814}
815
Nan Zhang66dc2362018-08-14 20:41:04 -0700816func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
817 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700818 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800819
Nan Zhanga40da042018-08-01 12:48:00 -0700820 *implicits = append(*implicits, deps.bootClasspath...)
821 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800822
Nan Zhangc94f9d82018-06-26 10:02:26 -0700823 if len(deps.bootClasspath.Strings()) > 0 {
824 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700825 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700826 }
Nan Zhanga40da042018-08-01 12:48:00 -0700827 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700828 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
Nan Zhang86d2d552018-08-09 15:33:27 -0700829 dokkaClasspath := classpath{}
830 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
831 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
832 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700833
Nan Zhang1598a9e2018-09-04 17:14:32 -0700834 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
Nan Zhang581fd212018-01-10 16:06:12 -0800835
Nan Zhanga40da042018-08-01 12:48:00 -0700836 return flags, nil
837}
Nan Zhang581fd212018-01-10 16:06:12 -0800838
Nan Zhanga40da042018-08-01 12:48:00 -0700839func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700840 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800841
Nan Zhanga40da042018-08-01 12:48:00 -0700842 *implicits = append(*implicits, jsilver)
843 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700844
Nan Zhang46130972018-06-04 11:28:01 -0700845 var date string
846 if runtime.GOOS == "darwin" {
847 date = `date -r`
848 } else {
849 date = `date -d`
850 }
851
Nan Zhang443fa522018-08-20 20:58:28 -0700852 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
853 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
854 // 1.9 language features.
855 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700856 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800857 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700858 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700859
Nan Zhanga40da042018-08-01 12:48:00 -0700860 if String(d.properties.Custom_template) == "" {
861 // TODO: This is almost always droiddoc-templates-sdk
862 ctx.PropertyErrorf("custom_template", "must specify a template")
863 }
864
865 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700866 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhanga40da042018-08-01 12:48:00 -0700867 *implicits = append(*implicits, t.deps...)
868 args = args + " -templatedir " + t.dir.String()
869 } else {
870 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
871 }
872 })
873
874 if len(d.properties.Html_dirs) > 0 {
875 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
876 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
877 args = args + " -htmldir " + htmlDir.String()
878 }
879
880 if len(d.properties.Html_dirs) > 1 {
881 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
882 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
883 args = args + " -htmldir2 " + htmlDir2.String()
884 }
885
886 if len(d.properties.Html_dirs) > 2 {
887 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
888 }
889
890 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
891 *implicits = append(*implicits, knownTags...)
892
893 for _, kt := range knownTags {
894 args = args + " -knowntags " + kt.String()
895 }
896
897 for _, hdf := range d.properties.Hdf {
898 args = args + " -hdf " + hdf
899 }
900
901 if String(d.properties.Proofread_file) != "" {
902 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
903 args = args + " -proofread " + proofreadFile.String()
904 }
905
906 if String(d.properties.Todo_file) != "" {
907 // tricky part:
908 // we should not compute full path for todo_file through PathForModuleOut().
909 // the non-standard doclet will get the full path relative to "-o".
910 args = args + " -todo " + String(d.properties.Todo_file)
911 }
912
913 if String(d.properties.Resourcesdir) != "" {
914 // TODO: should we add files under resourcesDir to the implicits? It seems that
915 // resourcesDir is one sub dir of htmlDir
916 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
917 args = args + " -resourcesdir " + resourcesDir.String()
918 }
919
920 if String(d.properties.Resourcesoutdir) != "" {
921 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
922 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
923 }
924 return args
925}
926
Nan Zhang1598a9e2018-09-04 17:14:32 -0700927func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext,
928 implicitOutputs *android.WritablePaths) string {
929 var doclavaFlags string
930 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
931 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
932 String(d.properties.Api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700933 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
934 doclavaFlags += " -api " + d.apiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700935 *implicitOutputs = append(*implicitOutputs, d.apiFile)
936 d.apiFilePath = d.apiFile
937 }
938
Nan Zhang1598a9e2018-09-04 17:14:32 -0700939 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
940 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
941 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700942 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
943 doclavaFlags += " -removedApi " + d.removedApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700944 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
945 }
946
947 if String(d.properties.Private_api_filename) != "" {
948 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
949 doclavaFlags += " -privateApi " + d.privateApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700950 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
951 }
952
953 if String(d.properties.Dex_api_filename) != "" {
954 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
955 doclavaFlags += " -dexApi " + d.dexApiFile.String()
956 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
957 }
958
959 if String(d.properties.Private_dex_api_filename) != "" {
960 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
961 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700962 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
963 }
964
965 if String(d.properties.Removed_dex_api_filename) != "" {
966 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
967 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700968 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
969 }
970
971 if String(d.properties.Exact_api_filename) != "" {
972 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
973 doclavaFlags += " -exactApi " + d.exactApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700974 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
975 }
976
977 if String(d.properties.Dex_mapping_filename) != "" {
978 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
979 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700980 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
981 }
982
Nan Zhang66dc2362018-08-14 20:41:04 -0700983 if String(d.properties.Proguard_filename) != "" {
984 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
985 doclavaFlags += " -proguard " + d.proguardFile.String()
Nan Zhang66dc2362018-08-14 20:41:04 -0700986 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
987 }
988
Nan Zhanga40da042018-08-01 12:48:00 -0700989 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -0700990 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700991 }
992
993 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -0700994 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700995 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700996
997 return doclavaFlags
Nan Zhanga40da042018-08-01 12:48:00 -0700998}
999
1000func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
1001 var cmds string
1002 if String(d.properties.Static_doc_index_redirect) != "" {
1003 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
1004 "static_doc_index_redirect")
1005 *implicits = append(*implicits, static_doc_index_redirect)
1006 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001007 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001008 }
1009
1010 if String(d.properties.Static_doc_properties) != "" {
1011 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
1012 "static_doc_properties")
1013 *implicits = append(*implicits, static_doc_properties)
1014 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -07001015 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -07001016 }
1017 return cmds
1018}
1019
Nan Zhang1598a9e2018-09-04 17:14:32 -07001020func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1021 implicitOutputs android.WritablePaths,
1022 bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) {
1023 ctx.Build(pctx, android.BuildParams{
1024 Rule: javadoc,
1025 Description: "Doclava",
1026 Output: d.Javadoc.stubsSrcJar,
1027 Inputs: d.Javadoc.srcFiles,
1028 Implicits: implicits,
1029 ImplicitOutputs: implicitOutputs,
1030 Args: map[string]string{
1031 "outDir": android.PathForModuleOut(ctx, "out").String(),
1032 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1033 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1034 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1035 "opts": opts,
1036 "bootclasspathArgs": bootclasspathArgs,
1037 "classpathArgs": classpathArgs,
1038 "sourcepathArgs": sourcepathArgs,
1039 "docZip": d.Javadoc.docZip.String(),
1040 "postDoclavaCmds": postDoclavaCmds,
1041 },
1042 })
1043}
1044
1045func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1046 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1047 ctx.Build(pctx, android.BuildParams{
1048 Rule: apiCheck,
1049 Description: "Doclava Check API",
1050 Output: output,
1051 Inputs: nil,
1052 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1053 checkApiClasspath...),
1054 Args: map[string]string{
1055 "msg": msg,
1056 "classpath": checkApiClasspath.FormJavaClassPath(""),
1057 "opts": opts,
1058 "apiFile": apiFile.String(),
1059 "apiFileToCheck": d.apiFile.String(),
1060 "removedApiFile": removedApiFile.String(),
1061 "removedApiFileToCheck": d.removedApiFile.String(),
1062 },
1063 })
1064}
1065
1066func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths,
1067 classpathArgs, opts string) {
1068 ctx.Build(pctx, android.BuildParams{
1069 Rule: dokka,
1070 Description: "Dokka",
1071 Output: d.Javadoc.stubsSrcJar,
1072 Inputs: d.Javadoc.srcFiles,
1073 Implicits: implicits,
1074 Args: map[string]string{
1075 "outDir": android.PathForModuleOut(ctx, "out").String(),
1076 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1077 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1078 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1079 "classpathArgs": classpathArgs,
1080 "opts": opts,
1081 "docZip": d.Javadoc.docZip.String(),
1082 },
1083 })
1084}
1085
1086func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1087 deps := d.Javadoc.collectDeps(ctx)
1088
1089 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1090 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1091 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1092 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1093
1094 var implicits android.Paths
1095 implicits = append(implicits, d.Javadoc.srcJars...)
1096 implicits = append(implicits, d.Javadoc.argFiles...)
1097
1098 var implicitOutputs android.WritablePaths
1099 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1100 for _, o := range d.Javadoc.properties.Out {
1101 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1102 }
1103
1104 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
1105 if err != nil {
1106 return
1107 }
1108
1109 flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1110 if Bool(d.properties.Dokka_enabled) {
1111 d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args)
1112 } else {
1113 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
1114 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
1115 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1116 flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args,
1117 flags.postDoclavaCmds)
1118 }
1119
1120 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1121 !ctx.Config().IsPdkBuild() {
1122 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1123 "check_api.current.api_file")
1124 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1125 "check_api.current_removed_api_file")
1126
1127 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
1128 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1129 fmt.Sprintf(`\n******************************\n`+
1130 `You have tried to change the API from what has been previously approved.\n\n`+
1131 `To make these errors go away, you have two choices:\n`+
1132 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1133 ` errors above.\n\n`+
1134 ` 2. You can update current.txt by executing the following command:\n`+
1135 ` make %s-update-current-api\n\n`+
1136 ` To submit the revised current.txt to the main Android repository,\n`+
1137 ` you will need approval.\n`+
1138 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1139 d.checkCurrentApiTimestamp)
1140
1141 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
1142 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1143 d.updateCurrentApiTimestamp)
1144 }
1145
1146 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1147 !ctx.Config().IsPdkBuild() {
1148 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1149 "check_api.last_released.api_file")
1150 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1151 "check_api.last_released.removed_api_file")
1152
1153 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1154 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1155 `\n******************************\n`+
1156 `You have tried to change the API from what has been previously released in\n`+
1157 `an SDK. Please fix the errors listed above.\n`+
1158 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1159 d.checkLastReleasedApiTimestamp)
1160 }
1161}
1162
1163//
1164// Droidstubs
1165//
1166type Droidstubs struct {
1167 Javadoc
1168
1169 properties DroidstubsProperties
1170 apiFile android.WritablePath
1171 dexApiFile android.WritablePath
1172 privateApiFile android.WritablePath
1173 privateDexApiFile android.WritablePath
1174 removedApiFile android.WritablePath
1175 removedDexApiFile android.WritablePath
1176 exactApiFile android.WritablePath
1177
1178 checkCurrentApiTimestamp android.WritablePath
1179 updateCurrentApiTimestamp android.WritablePath
1180 checkLastReleasedApiTimestamp android.WritablePath
1181
1182 annotationsZip android.WritablePath
1183
1184 apiFilePath android.Path
1185}
1186
1187func DroidstubsFactory() android.Module {
1188 module := &Droidstubs{}
1189
1190 module.AddProperties(&module.properties,
1191 &module.Javadoc.properties)
1192
1193 InitDroiddocModule(module, android.HostAndDeviceSupported)
1194 return module
1195}
1196
1197func DroidstubsHostFactory() android.Module {
1198 module := &Droidstubs{}
1199
1200 module.AddProperties(&module.properties,
1201 &module.Javadoc.properties)
1202
1203 InitDroiddocModule(module, android.HostSupported)
1204 return module
1205}
1206
1207func (d *Droidstubs) ApiFilePath() android.Path {
1208 return d.apiFilePath
1209}
1210
1211func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1212 d.Javadoc.addDeps(ctx)
1213
1214 if apiCheckEnabled(d.properties.Check_api.Current, "current") {
1215 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
1216 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
1217 }
1218
1219 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") {
1220 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
1221 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
1222 }
1223
1224 if String(d.properties.Previous_api) != "" {
1225 android.ExtractSourceDeps(ctx, d.properties.Previous_api)
1226 }
1227
1228 if len(d.properties.Merge_annotations_dirs) != 0 {
1229 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1230 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1231 }
1232 }
1233}
1234
1235func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
1236 deps deps) (droiddocBuilderFlags, error) {
1237 var flags droiddocBuilderFlags
1238
1239 *implicits = append(*implicits, deps.bootClasspath...)
1240 *implicits = append(*implicits, deps.classpath...)
1241
1242 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
1243 // since it doesn't support system modules yet.
1244 if len(deps.bootClasspath.Strings()) > 0 {
1245 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
1246 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
1247 }
1248 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
1249
1250 flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":")
1251
1252 return flags, nil
1253}
1254
1255func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext,
1256 implicitOutputs *android.WritablePaths) string {
1257 var metalavaFlags string
1258 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1259 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1260 String(d.properties.Api_filename) != "" {
1261 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
1262 metalavaFlags = metalavaFlags + " --api " + d.apiFile.String()
1263 *implicitOutputs = append(*implicitOutputs, d.apiFile)
1264 d.apiFilePath = d.apiFile
1265 }
1266
1267 if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
1268 apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
1269 String(d.properties.Removed_api_filename) != "" {
1270 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
1271 metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String()
1272 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
1273 }
1274
1275 if String(d.properties.Private_api_filename) != "" {
1276 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
1277 metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String()
1278 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
1279 }
1280
1281 if String(d.properties.Dex_api_filename) != "" {
1282 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
1283 metalavaFlags += " --dex-api " + d.dexApiFile.String()
1284 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
1285 }
1286
1287 if String(d.properties.Private_dex_api_filename) != "" {
1288 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
1289 metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
1290 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
1291 }
1292
1293 if String(d.properties.Removed_dex_api_filename) != "" {
1294 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
1295 metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
1296 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
1297 }
1298
1299 if String(d.properties.Exact_api_filename) != "" {
1300 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
1301 metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String()
1302 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
1303 }
1304
1305 if Bool(d.properties.Create_doc_stubs) {
1306 metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1307 } else {
1308 metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
1309 }
1310
1311 return metalavaFlags
1312}
1313
1314func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext,
1315 implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
Nan Zhanga40da042018-08-01 12:48:00 -07001316 var flags string
Nan Zhang1598a9e2018-09-04 17:14:32 -07001317 if Bool(d.properties.Annotations_enabled) {
1318 if String(d.properties.Previous_api) == "" {
Nan Zhanga40da042018-08-01 12:48:00 -07001319 ctx.PropertyErrorf("metalava_previous_api",
1320 "has to be non-empty if annotations was enabled!")
1321 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001322 previousApi := ctx.ExpandSource(String(d.properties.Previous_api),
Nan Zhangde860a42018-08-08 16:32:21 -07001323 "metalava_previous_api")
1324 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -07001325
Nan Zhangd05a4362018-08-15 13:28:54 -07001326 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -07001327
1328 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
1329 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
1330
Nan Zhangf4936b02018-08-01 15:00:28 -07001331 flags += " --extract-annotations " + d.annotationsZip.String()
1332
Nan Zhang1598a9e2018-09-04 17:14:32 -07001333 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhanga40da042018-08-01 12:48:00 -07001334 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
1335 "has to be non-empty if annotations was enabled!")
1336 }
Nan Zhangf4936b02018-08-01 15:00:28 -07001337 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1338 if t, ok := m.(*ExportedDroiddocDir); ok {
1339 *implicits = append(*implicits, t.deps...)
1340 flags += " --merge-annotations " + t.dir.String()
1341 } else {
1342 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
1343 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1344 }
1345 })
Nan Zhanga40da042018-08-01 12:48:00 -07001346 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1347 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1348 }
1349
1350 return flags
1351}
1352
Nan Zhang1598a9e2018-09-04 17:14:32 -07001353func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1354 implicitOutputs android.WritablePaths, javaVersion,
1355 bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) {
Nan Zhang86d2d552018-08-09 15:33:27 -07001356 ctx.Build(pctx, android.BuildParams{
1357 Rule: metalava,
1358 Description: "Metalava",
1359 Output: d.Javadoc.stubsSrcJar,
1360 Inputs: d.Javadoc.srcFiles,
1361 Implicits: implicits,
1362 ImplicitOutputs: implicitOutputs,
1363 Args: map[string]string{
Nan Zhang86d2d552018-08-09 15:33:27 -07001364 "outDir": android.PathForModuleOut(ctx, "out").String(),
1365 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1366 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1367 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang1598a9e2018-09-04 17:14:32 -07001368 "javaVersion": javaVersion,
Nan Zhang86d2d552018-08-09 15:33:27 -07001369 "bootclasspathArgs": bootclasspathArgs,
1370 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001371 "sourcepathArgs": sourcepathArgs,
1372 "opts": opts,
Nan Zhang86d2d552018-08-09 15:33:27 -07001373 },
1374 })
1375}
1376
Nan Zhang1598a9e2018-09-04 17:14:32 -07001377func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext,
1378 apiFile, removedApiFile android.Path, implicits android.Paths,
1379 javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001380 output android.WritablePath) {
1381 ctx.Build(pctx, android.BuildParams{
1382 Rule: metalavaApiCheck,
1383 Description: "Metalava Check API",
1384 Output: output,
1385 Inputs: d.Javadoc.srcFiles,
1386 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1387 implicits...),
1388 Args: map[string]string{
1389 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1390 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1391 "javaVersion": javaVersion,
1392 "bootclasspathArgs": bootclasspathArgs,
1393 "classpathArgs": classpathArgs,
Nan Zhang1598a9e2018-09-04 17:14:32 -07001394 "sourcepathArgs": sourcepathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001395 "opts": opts,
1396 "msg": msg,
1397 },
1398 })
1399}
1400
Nan Zhang1598a9e2018-09-04 17:14:32 -07001401func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001402 deps := d.Javadoc.collectDeps(ctx)
1403
Nan Zhang1598a9e2018-09-04 17:14:32 -07001404 // always set installable to false for droidstubs, since droidstubs doesn't create doc.zip file.
1405 *d.Javadoc.properties.Installable = false
1406
Nan Zhanga40da042018-08-01 12:48:00 -07001407 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001408
Nan Zhanga40da042018-08-01 12:48:00 -07001409 var implicits android.Paths
1410 implicits = append(implicits, d.Javadoc.srcJars...)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001411 implicits = append(implicits, d.Javadoc.argFiles...)
Nan Zhanga40da042018-08-01 12:48:00 -07001412
1413 var implicitOutputs android.WritablePaths
Nan Zhang1598a9e2018-09-04 17:14:32 -07001414 for _, o := range d.Javadoc.properties.Out {
Nan Zhanga40da042018-08-01 12:48:00 -07001415 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1416 }
1417
1418 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001419 metalavaCheckApiImplicits := implicits
Nan Zhanga40da042018-08-01 12:48:00 -07001420 if err != nil {
1421 return
1422 }
1423
Nan Zhang1598a9e2018-09-04 17:14:32 -07001424 flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1425 flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs)
1426 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1427 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1428 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1429 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1430 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001431 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001432 d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion,
1433 flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs,
1434 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+d.Javadoc.args)
Nan Zhang61819ce2018-05-04 18:49:16 -07001435
Nan Zhang1598a9e2018-09-04 17:14:32 -07001436 if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
1437 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001438 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1439 "check_api.current.api_file")
1440 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1441 "check_api.current_removed_api_file")
1442
Nan Zhang2760dfc2018-08-24 17:32:54 +00001443 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001444 opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() +
1445 " --check-compatibility:removed:current " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001446
Nan Zhang1598a9e2018-09-04 17:14:32 -07001447 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1448 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1449 fmt.Sprintf(`\n******************************\n`+
1450 `You have tried to change the API from what has been previously approved.\n\n`+
1451 `To make these errors go away, you have two choices:\n`+
1452 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1453 ` errors above.\n\n`+
1454 ` 2. You can update current.txt by executing the following command:\n`+
1455 ` make %s-update-current-api\n\n`+
1456 ` To submit the revised current.txt to the main Android repository,\n`+
1457 ` you will need approval.\n`+
1458 `******************************\n`, ctx.ModuleName()),
1459 d.checkCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001460
1461 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001462 transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile,
1463 d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001464 }
Nan Zhanga40da042018-08-01 12:48:00 -07001465
Nan Zhang1598a9e2018-09-04 17:14:32 -07001466 if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
1467 !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001468 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1469 "check_api.last_released.api_file")
1470 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1471 "check_api.last_released.removed_api_file")
1472
Nan Zhang2760dfc2018-08-24 17:32:54 +00001473 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001474 opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() +
1475 " --check-compatibility:removed:released " + removedApiFile.String() + " "
Nan Zhang2760dfc2018-08-24 17:32:54 +00001476
Nan Zhang1598a9e2018-09-04 17:14:32 -07001477 d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1478 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts,
1479 `\n******************************\n`+
1480 `You have tried to change the API from what has been previously released in\n`+
1481 `an SDK. Please fix the errors listed above.\n`+
1482 `******************************\n`,
1483 d.checkLastReleasedApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001484 }
Nan Zhang581fd212018-01-10 16:06:12 -08001485}
Dan Willemsencc090972018-02-26 14:33:31 -08001486
Nan Zhanga40da042018-08-01 12:48:00 -07001487//
Nan Zhangf4936b02018-08-01 15:00:28 -07001488// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001489//
Dan Willemsencc090972018-02-26 14:33:31 -08001490var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001491var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001492
Nan Zhangf4936b02018-08-01 15:00:28 -07001493type ExportedDroiddocDirProperties struct {
1494 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001495 Path *string
1496}
1497
Nan Zhangf4936b02018-08-01 15:00:28 -07001498type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001499 android.ModuleBase
1500
Nan Zhangf4936b02018-08-01 15:00:28 -07001501 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001502
1503 deps android.Paths
1504 dir android.Path
1505}
1506
Nan Zhangf4936b02018-08-01 15:00:28 -07001507func ExportedDroiddocDirFactory() android.Module {
1508 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001509 module.AddProperties(&module.properties)
1510 android.InitAndroidModule(module)
1511 return module
1512}
1513
Nan Zhangf4936b02018-08-01 15:00:28 -07001514func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001515
Nan Zhangf4936b02018-08-01 15:00:28 -07001516func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001517 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1518 d.dir = path
1519 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1520}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001521
1522//
1523// Defaults
1524//
1525type DocDefaults struct {
1526 android.ModuleBase
1527 android.DefaultsModuleBase
1528}
1529
1530func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1531}
1532
1533func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1534}
1535
1536func DocDefaultsFactory() android.Module {
1537 module := &DocDefaults{}
1538
1539 module.AddProperties(
1540 &JavadocProperties{},
1541 &DroiddocProperties{},
1542 )
1543
1544 android.InitDefaultsModule(module)
1545
1546 return module
1547}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001548
1549func StubsDefaultsFactory() android.Module {
1550 module := &DocDefaults{}
1551
1552 module.AddProperties(
1553 &JavadocProperties{},
1554 &DroidstubsProperties{},
1555 )
1556
1557 android.InitDefaultsModule(module)
1558
1559 return module
1560}