blob: 16e6921e16b0c019b23efe6faf1f54d8860e48bb [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 (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Jeongik Cha6bd33c12019-06-25 16:26:18 +090022 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080023
Colin Crossab054432019-07-15 16:13:59 -070024 "android/soong/android"
25 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080026)
27
28func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080029 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -070030 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -080031
Nan Zhang581fd212018-01-10 16:06:12 -080032 android.RegisterModuleType("droiddoc", DroiddocFactory)
33 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -070034 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080035 android.RegisterModuleType("javadoc", JavadocFactory)
36 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -070037
38 android.RegisterModuleType("droidstubs", DroidstubsFactory)
39 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Paul Duffin91547182019-11-12 19:39:36 +000040
41 android.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080042}
43
Colin Crossa1ce2a02018-06-20 15:19:39 -070044var (
45 srcsLibTag = dependencyTag{name: "sources from javalib"}
46)
47
Nan Zhang581fd212018-01-10 16:06:12 -080048type JavadocProperties struct {
49 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
50 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080051 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080052
53 // list of directories rooted at the Android.bp file that will
54 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080055 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080056
57 // list of source files that should not be used to build the Java module.
58 // This is most useful in the arch/multilib variants to remove non-common files
59 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080060 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080061
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090062 // list of package names that should actually be used. If this property is left unspecified,
63 // all the sources from the srcs property is used.
64 Filter_packages []string
65
Nan Zhangb2b33de2018-02-23 11:18:47 -080066 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080067 Libs []string `android:"arch_variant"`
68
69 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080070 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080071
Paul Duffine25c6442019-10-11 13:50:28 +010072 // if not blank, set to the version of the sdk to compile against.
73 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080074 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090075
Paul Duffine25c6442019-10-11 13:50:28 +010076 // When targeting 1.9 and above, override the modules to use with --system,
77 // otherwise provides defaults libraries to add to the bootclasspath.
78 // Defaults to "none"
79 System_modules *string
80
Jiyong Park1e440682018-05-23 18:42:04 +090081 Aidl struct {
82 // Top level directories to pass to aidl tool
83 Include_dirs []string
84
85 // Directories rooted at the Android.bp file to pass to aidl tool
86 Local_include_dirs []string
87 }
Nan Zhang357466b2018-04-17 17:38:36 -070088
89 // If not blank, set the java version passed to javadoc as -source
90 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -070091
92 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -080093 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -070094
95 // user customized droiddoc args.
96 // Available variables for substitution:
97 //
98 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -070099 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700100 Args *string
101
102 // names of the output files used in args that will be generated
103 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800104}
105
Nan Zhang61819ce2018-05-04 18:49:16 -0700106type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900107 // path to the API txt file that the new API extracted from source code is checked
108 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800109 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700110
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900111 // path to the API txt file that the new @removed API extractd from source code is
112 // checked against. The path can be local to the module or from other module (via
113 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800114 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700115
Adrian Roos14f75a92019-08-12 17:54:09 +0200116 // If not blank, path to the baseline txt file for approved API check violations.
117 Baseline_file *string `android:"path"`
118
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900119 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700120 Args *string
121}
122
Nan Zhang581fd212018-01-10 16:06:12 -0800123type DroiddocProperties struct {
124 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800125 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800126
Nan Zhanga40da042018-08-01 12:48:00 -0700127 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800128 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800129
130 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800131 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800132
133 // proofread file contains all of the text content of the javadocs concatenated into one file,
134 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700135 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800136
137 // a todo file lists the program elements that are missing documentation.
138 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800139 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800140
141 // directory under current module source that provide additional resources (images).
142 Resourcesdir *string
143
144 // resources output directory under out/soong/.intermediates.
145 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800146
Nan Zhange2ba5d42018-07-11 15:16:55 -0700147 // if set to true, collect the values used by the Dev tools and
148 // write them in files packaged with the SDK. Defaults to false.
149 Write_sdk_values *bool
150
151 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800152 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700153
154 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800155 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700156
Nan Zhang581fd212018-01-10 16:06:12 -0800157 // a list of files under current module source dir which contains known tags in Java sources.
158 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800159 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700160
161 // the tag name used to distinguish if the API files belong to public/system/test.
162 Api_tag_name *string
163
164 // the generated public API filename by Doclava.
165 Api_filename *string
166
David Brazdilfbe4cc32018-05-31 13:56:46 +0100167 // the generated public Dex API filename by Doclava.
168 Dex_api_filename *string
169
Nan Zhang28c68b92018-03-13 16:17:01 -0700170 // the generated private API filename by Doclava.
171 Private_api_filename *string
172
173 // the generated private Dex API filename by Doclava.
174 Private_dex_api_filename *string
175
176 // the generated removed API filename by Doclava.
177 Removed_api_filename *string
178
David Brazdilaac0c3c2018-04-24 16:23:29 +0100179 // the generated removed Dex API filename by Doclava.
180 Removed_dex_api_filename *string
181
Mathew Inwood76c3de12018-06-22 15:28:11 +0100182 // mapping of dex signatures to source file and line number. This is a temporary property and
183 // will be deleted; you probably shouldn't be using it.
184 Dex_mapping_filename *string
185
Nan Zhang28c68b92018-03-13 16:17:01 -0700186 // the generated exact API filename by Doclava.
187 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700188
Nan Zhang66dc2362018-08-14 20:41:04 -0700189 // the generated proguard filename by Doclava.
190 Proguard_filename *string
191
Nan Zhang853f4202018-04-12 16:55:56 -0700192 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
193 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700194
195 Check_api struct {
196 Last_released ApiToCheck
197
198 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900199
200 // do not perform API check against Last_released, in the case that both two specified API
201 // files by Last_released are modules which don't exist.
202 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700203 }
Nan Zhang79614d12018-04-19 18:03:39 -0700204
Nan Zhang1598a9e2018-09-04 17:14:32 -0700205 // if set to true, generate docs through Dokka instead of Doclava.
206 Dokka_enabled *bool
207}
208
209type DroidstubsProperties struct {
210 // the tag name used to distinguish if the API files belong to public/system/test.
211 Api_tag_name *string
212
Nan Zhang199645c2018-09-19 12:40:06 -0700213 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700214 Api_filename *string
215
Nan Zhang199645c2018-09-19 12:40:06 -0700216 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700217 Dex_api_filename *string
218
Nan Zhang199645c2018-09-19 12:40:06 -0700219 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700220 Private_api_filename *string
221
Nan Zhang199645c2018-09-19 12:40:06 -0700222 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700223 Private_dex_api_filename *string
224
Nan Zhang199645c2018-09-19 12:40:06 -0700225 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700226 Removed_api_filename *string
227
Nan Zhang199645c2018-09-19 12:40:06 -0700228 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700229 Removed_dex_api_filename *string
230
Nan Zhang9c69a122018-08-22 10:22:08 -0700231 // mapping of dex signatures to source file and line number. This is a temporary property and
232 // will be deleted; you probably shouldn't be using it.
233 Dex_mapping_filename *string
234
Nan Zhang199645c2018-09-19 12:40:06 -0700235 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700236 Exact_api_filename *string
237
Nan Zhang199645c2018-09-19 12:40:06 -0700238 // the generated proguard filename by Metalava.
239 Proguard_filename *string
240
Nan Zhang1598a9e2018-09-04 17:14:32 -0700241 Check_api struct {
242 Last_released ApiToCheck
243
244 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900245
246 // do not perform API check against Last_released, in the case that both two specified API
247 // files by Last_released are modules which don't exist.
248 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200249
250 Api_lint struct {
251 Enabled *bool
252
253 // If set, performs api_lint on any new APIs not found in the given signature file
254 New_since *string `android:"path"`
255
256 // If not blank, path to the baseline txt file for approved API lint violations.
257 Baseline_file *string `android:"path"`
258 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700259 }
Nan Zhang79614d12018-04-19 18:03:39 -0700260
261 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800262 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700263
264 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700265 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700266
Pete Gillin77167902018-09-19 18:16:26 +0100267 // 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 -0700268 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700269
Pete Gillin77167902018-09-19 18:16:26 +0100270 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
271 Merge_inclusion_annotations_dirs []string
272
Pete Gillinc382a562018-11-14 18:45:46 +0000273 // a file containing a list of classes to do nullability validation for.
274 Validate_nullability_from_list *string
275
Pete Gillin581d6082018-10-22 15:55:04 +0100276 // a file containing expected warnings produced by validation of nullability annotations.
277 Check_nullability_warnings *string
278
Nan Zhang1598a9e2018-09-04 17:14:32 -0700279 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
280 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700281
282 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
283 Api_levels_annotations_enabled *bool
284
285 // the dirs which Metalava extracts API levels annotations from.
286 Api_levels_annotations_dirs []string
287
288 // if set to true, collect the values used by the Dev tools and
289 // write them in files packaged with the SDK. Defaults to false.
290 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700291
292 // If set to true, .xml based public API file will be also generated, and
293 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
294 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800295}
296
Nan Zhanga40da042018-08-01 12:48:00 -0700297//
298// Common flags passed down to build rule
299//
300type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700301 bootClasspathArgs string
302 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700303 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700304 dokkaClasspathArgs string
305 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700306 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700307
Nan Zhanga40da042018-08-01 12:48:00 -0700308 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700309 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700310 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700311}
312
313func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
314 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
315 android.InitDefaultableModule(module)
316}
317
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200318func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
319 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
320 return false
321 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700322 return true
323 } else if String(apiToCheck.Api_file) != "" {
324 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
325 } else if String(apiToCheck.Removed_api_file) != "" {
326 panic("for " + apiVersionTag + " api_file has to be non-empty!")
327 }
328
329 return false
330}
331
Inseob Kim38449af2019-02-28 14:24:05 +0900332func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
333 api_file := String(apiToCheck.Api_file)
334 removed_api_file := String(apiToCheck.Removed_api_file)
335
336 api_module := android.SrcIsModule(api_file)
337 removed_api_module := android.SrcIsModule(removed_api_file)
338
339 if api_module == "" || removed_api_module == "" {
340 return
341 }
342
343 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
344 return
345 }
346
347 apiToCheck.Api_file = nil
348 apiToCheck.Removed_api_file = nil
349}
350
Nan Zhang1598a9e2018-09-04 17:14:32 -0700351type ApiFilePath interface {
352 ApiFilePath() android.Path
353}
354
Nan Zhanga40da042018-08-01 12:48:00 -0700355//
356// Javadoc
357//
Nan Zhang581fd212018-01-10 16:06:12 -0800358type Javadoc struct {
359 android.ModuleBase
360 android.DefaultableModuleBase
361
362 properties JavadocProperties
363
364 srcJars android.Paths
365 srcFiles android.Paths
366 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700367 argFiles android.Paths
368
369 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800370
Nan Zhangccff0f72018-03-08 17:26:16 -0800371 docZip android.WritablePath
372 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800373}
374
Colin Cross41955e82019-05-29 14:40:35 -0700375func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
376 switch tag {
377 case "":
378 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700379 case ".docs.zip":
380 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700381 default:
382 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
383 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800384}
385
Colin Crossa3002fc2019-07-08 16:48:04 -0700386// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800387func JavadocFactory() android.Module {
388 module := &Javadoc{}
389
390 module.AddProperties(&module.properties)
391
392 InitDroiddocModule(module, android.HostAndDeviceSupported)
393 return module
394}
395
Colin Crossa3002fc2019-07-08 16:48:04 -0700396// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800397func JavadocHostFactory() android.Module {
398 module := &Javadoc{}
399
400 module.AddProperties(&module.properties)
401
402 InitDroiddocModule(module, android.HostSupported)
403 return module
404}
405
Colin Cross41955e82019-05-29 14:40:35 -0700406var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800407
Colin Cross83bb3162018-06-25 15:48:06 -0700408func (j *Javadoc) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900409 return String(j.properties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700410}
411
Paul Duffine25c6442019-10-11 13:50:28 +0100412func (j *Javadoc) systemModules() string {
413 return proptools.String(j.properties.System_modules)
414}
415
Colin Cross83bb3162018-06-25 15:48:06 -0700416func (j *Javadoc) minSdkVersion() string {
417 return j.sdkVersion()
418}
419
Dan Willemsen419290a2018-10-31 15:28:47 -0700420func (j *Javadoc) targetSdkVersion() string {
421 return j.sdkVersion()
422}
423
Nan Zhang581fd212018-01-10 16:06:12 -0800424func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
425 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100426 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700427 if sdkDep.useDefaultLibs {
428 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
429 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
430 if sdkDep.hasFrameworkLibs() {
431 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700432 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700433 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700434 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100435 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700436 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800437 }
438 }
439
Colin Cross42d48b72018-08-29 14:10:52 -0700440 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800441}
442
Nan Zhanga40da042018-08-01 12:48:00 -0700443func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
444 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900445
Colin Cross3047fa22019-04-18 10:56:44 -0700446 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900447
448 return flags
449}
450
451func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700452 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900453
454 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
455 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
456
457 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700458 var deps android.Paths
459
Jiyong Park1e440682018-05-23 18:42:04 +0900460 if aidlPreprocess.Valid() {
461 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700462 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900463 } else {
464 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
465 }
466
467 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
468 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
469 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
470 flags = append(flags, "-I"+src.String())
471 }
472
Colin Cross3047fa22019-04-18 10:56:44 -0700473 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900474}
475
Jiyong Parkd90d7412019-08-20 22:49:19 +0900476// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900477func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700478 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900479
480 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700481 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900482
Jiyong Park1112c4c2019-08-16 21:12:10 +0900483 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
484
Jiyong Park1e440682018-05-23 18:42:04 +0900485 for _, srcFile := range srcFiles {
486 switch srcFile.Ext() {
487 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700488 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900489 case ".logtags":
490 javaFile := genLogtags(ctx, srcFile)
491 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900492 default:
493 outSrcFiles = append(outSrcFiles, srcFile)
494 }
495 }
496
Colin Crossc0806172019-06-14 18:51:47 -0700497 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
498 if len(aidlSrcs) > 0 {
499 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
500 outSrcFiles = append(outSrcFiles, srcJarFiles...)
501 }
502
Jiyong Park1e440682018-05-23 18:42:04 +0900503 return outSrcFiles
504}
505
Nan Zhang581fd212018-01-10 16:06:12 -0800506func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
507 var deps deps
508
Colin Cross83bb3162018-06-25 15:48:06 -0700509 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800510 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700511 ctx.AddMissingDependencies(sdkDep.bootclasspath)
512 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800513 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700514 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800515 }
516
517 ctx.VisitDirectDeps(func(module android.Module) {
518 otherName := ctx.OtherModuleName(module)
519 tag := ctx.OtherModuleDependencyTag(module)
520
Colin Cross2d24c1b2018-05-23 10:59:18 -0700521 switch tag {
522 case bootClasspathTag:
523 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800524 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffine25c6442019-10-11 13:50:28 +0100525 } else if sm, ok := module.(*SystemModules); ok {
526 // A system modules dependency has been added to the bootclasspath
527 // so add its libs to the bootclasspath.
528 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700529 } else {
530 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
531 }
532 case libTag:
533 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800534 case SdkLibraryDependency:
535 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700536 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900537 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900538 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700539 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800540 checkProducesJars(ctx, dep)
541 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800542 default:
543 ctx.ModuleErrorf("depends on non-java module %q", otherName)
544 }
Colin Cross6cef4812019-10-17 14:23:50 -0700545 case java9LibTag:
546 switch dep := module.(type) {
547 case Dependency:
548 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
549 default:
550 ctx.ModuleErrorf("depends on non-java module %q", otherName)
551 }
Nan Zhang357466b2018-04-17 17:38:36 -0700552 case systemModulesTag:
553 if deps.systemModules != nil {
554 panic("Found two system module dependencies")
555 }
556 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000557 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700558 panic("Missing directory for system module dependency")
559 }
Colin Crossb77043e2019-07-16 13:57:13 -0700560 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800561 }
562 })
563 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
564 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800565 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900566
567 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
568 if filterPackages == nil {
569 return srcs
570 }
571 filtered := []android.Path{}
572 for _, src := range srcs {
573 if src.Ext() != ".java" {
574 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
575 // but otherwise metalava emits stub sources having references to the generated AIDL classes
576 // in filtered-out pacages (e.g. com.android.internal.*).
577 // TODO(b/141149570) We need to fix this by introducing default private constructors or
578 // fixing metalava to not emit constructors having references to unknown classes.
579 filtered = append(filtered, src)
580 continue
581 }
582 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
583 for _, pkg := range filterPackages {
584 if strings.HasPrefix(packageName, pkg) {
585 filtered = append(filtered, src)
586 break
587 }
588 }
589 }
590 return filtered
591 }
592 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
593
Nan Zhanga40da042018-08-01 12:48:00 -0700594 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900595 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800596
597 // srcs may depend on some genrule output.
598 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800599 j.srcJars = append(j.srcJars, deps.srcJars...)
600
Nan Zhang581fd212018-01-10 16:06:12 -0800601 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800602 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800603
Nan Zhang9c69a122018-08-22 10:22:08 -0700604 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800605 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
606 }
607 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800608
Colin Cross8a497952019-03-05 22:25:09 -0800609 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000610 argFilesMap := map[string]string{}
611 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700612
Paul Duffin99e4a502019-02-11 15:38:42 +0000613 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800614 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000615 if _, exists := argFilesMap[label]; !exists {
616 argFilesMap[label] = strings.Join(paths.Strings(), " ")
617 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700618 } else {
619 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000620 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700621 }
622 }
623
624 var err error
Colin Cross15638152019-07-11 11:11:35 -0700625 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700626 if strings.HasPrefix(name, "location ") {
627 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000628 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700629 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700630 } else {
Colin Cross15638152019-07-11 11:11:35 -0700631 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000632 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700633 }
634 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700635 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700636 }
Colin Cross15638152019-07-11 11:11:35 -0700637 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700638 })
639
640 if err != nil {
641 ctx.PropertyErrorf("args", "%s", err.Error())
642 }
643
Nan Zhang581fd212018-01-10 16:06:12 -0800644 return deps
645}
646
647func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
648 j.addDeps(ctx)
649}
650
651func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
652 deps := j.collectDeps(ctx)
653
Colin Crossdaa4c672019-07-15 22:53:46 -0700654 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800655
Colin Crossdaa4c672019-07-15 22:53:46 -0700656 outDir := android.PathForModuleOut(ctx, "out")
657 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
658
659 j.stubsSrcJar = nil
660
661 rule := android.NewRuleBuilder()
662
663 rule.Command().Text("rm -rf").Text(outDir.String())
664 rule.Command().Text("mkdir -p").Text(outDir.String())
665
666 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700667
Colin Cross83bb3162018-06-25 15:48:06 -0700668 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800669
Colin Crossdaa4c672019-07-15 22:53:46 -0700670 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
671 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800672
Colin Cross1e743852019-10-28 11:37:20 -0700673 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700674 Flag("-J-Xmx1024m").
675 Flag("-XDignore.symbol.file").
676 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800677
Colin Crossdaa4c672019-07-15 22:53:46 -0700678 rule.Command().
679 BuiltTool(ctx, "soong_zip").
680 Flag("-write_if_changed").
681 Flag("-d").
682 FlagWithOutput("-o ", j.docZip).
683 FlagWithArg("-C ", outDir.String()).
684 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700685
Colin Crossdaa4c672019-07-15 22:53:46 -0700686 rule.Restat()
687
688 zipSyncCleanupCmd(rule, srcJarDir)
689
690 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800691}
692
Nan Zhanga40da042018-08-01 12:48:00 -0700693//
694// Droiddoc
695//
696type Droiddoc struct {
697 Javadoc
698
699 properties DroiddocProperties
700 apiFile android.WritablePath
701 dexApiFile android.WritablePath
702 privateApiFile android.WritablePath
703 privateDexApiFile android.WritablePath
704 removedApiFile android.WritablePath
705 removedDexApiFile android.WritablePath
706 exactApiFile android.WritablePath
707 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700708 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700709
710 checkCurrentApiTimestamp android.WritablePath
711 updateCurrentApiTimestamp android.WritablePath
712 checkLastReleasedApiTimestamp android.WritablePath
713
Nan Zhanga40da042018-08-01 12:48:00 -0700714 apiFilePath android.Path
715}
716
Colin Crossa3002fc2019-07-08 16:48:04 -0700717// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700718func DroiddocFactory() android.Module {
719 module := &Droiddoc{}
720
721 module.AddProperties(&module.properties,
722 &module.Javadoc.properties)
723
724 InitDroiddocModule(module, android.HostAndDeviceSupported)
725 return module
726}
727
Colin Crossa3002fc2019-07-08 16:48:04 -0700728// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700729func DroiddocHostFactory() android.Module {
730 module := &Droiddoc{}
731
732 module.AddProperties(&module.properties,
733 &module.Javadoc.properties)
734
735 InitDroiddocModule(module, android.HostSupported)
736 return module
737}
738
739func (d *Droiddoc) ApiFilePath() android.Path {
740 return d.apiFilePath
741}
742
Nan Zhang581fd212018-01-10 16:06:12 -0800743func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
744 d.Javadoc.addDeps(ctx)
745
Inseob Kim38449af2019-02-28 14:24:05 +0900746 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
747 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
748 }
749
Nan Zhang79614d12018-04-19 18:03:39 -0700750 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800751 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
752 }
Nan Zhang581fd212018-01-10 16:06:12 -0800753}
754
Colin Crossab054432019-07-15 16:13:59 -0700755func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Nan Zhang443fa522018-08-20 20:58:28 -0700756 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
757 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
758 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700759 cmd.FlagWithArg("-source ", "1.8").
760 Flag("-J-Xmx1600m").
761 Flag("-J-XX:-OmitStackTraceInFastThrow").
762 Flag("-XDignore.symbol.file").
763 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
764 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
765 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
Elliott Hughes26bce342019-09-12 15:05:13 -0700766 FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `)
Nan Zhang46130972018-06-04 11:28:01 -0700767
Nan Zhanga40da042018-08-01 12:48:00 -0700768 if String(d.properties.Custom_template) == "" {
769 // TODO: This is almost always droiddoc-templates-sdk
770 ctx.PropertyErrorf("custom_template", "must specify a template")
771 }
772
773 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700774 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700775 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700776 } else {
777 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
778 }
779 })
780
781 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700782 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
783 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
784 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700785 }
786
787 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700788 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
789 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
790 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700791 }
792
793 if len(d.properties.Html_dirs) > 2 {
794 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
795 }
796
Colin Cross8a497952019-03-05 22:25:09 -0800797 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700798 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700799
Colin Crossab054432019-07-15 16:13:59 -0700800 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700801
802 if String(d.properties.Proofread_file) != "" {
803 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700804 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700805 }
806
807 if String(d.properties.Todo_file) != "" {
808 // tricky part:
809 // we should not compute full path for todo_file through PathForModuleOut().
810 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700811 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
812 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700813 }
814
815 if String(d.properties.Resourcesdir) != "" {
816 // TODO: should we add files under resourcesDir to the implicits? It seems that
817 // resourcesDir is one sub dir of htmlDir
818 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700819 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700820 }
821
822 if String(d.properties.Resourcesoutdir) != "" {
823 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700824 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700825 }
Nan Zhanga40da042018-08-01 12:48:00 -0700826}
827
Colin Crossab054432019-07-15 16:13:59 -0700828func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200829 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
830 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700831 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700832
Nan Zhanga40da042018-08-01 12:48:00 -0700833 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700834 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700835 d.apiFilePath = d.apiFile
836 }
837
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200838 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
839 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700840 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700841 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700842 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700843 }
844
845 if String(d.properties.Private_api_filename) != "" {
846 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700847 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700848 }
849
850 if String(d.properties.Dex_api_filename) != "" {
851 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700852 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700853 }
854
855 if String(d.properties.Private_dex_api_filename) != "" {
856 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700857 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700858 }
859
860 if String(d.properties.Removed_dex_api_filename) != "" {
861 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700862 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700863 }
864
865 if String(d.properties.Exact_api_filename) != "" {
866 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700867 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700868 }
869
870 if String(d.properties.Dex_mapping_filename) != "" {
871 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700872 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700873 }
874
Nan Zhang66dc2362018-08-14 20:41:04 -0700875 if String(d.properties.Proguard_filename) != "" {
876 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700877 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700878 }
879
Nan Zhanga40da042018-08-01 12:48:00 -0700880 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700881 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700882 }
883
884 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700885 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700886 }
Nan Zhanga40da042018-08-01 12:48:00 -0700887}
888
Colin Crossab054432019-07-15 16:13:59 -0700889func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700890 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700891 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
892 rule.Command().Text("cp").
893 Input(staticDocIndexRedirect).
894 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700895 }
896
897 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700898 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
899 rule.Command().Text("cp").
900 Input(staticDocProperties).
901 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700902 }
Nan Zhanga40da042018-08-01 12:48:00 -0700903}
904
Colin Crossab054432019-07-15 16:13:59 -0700905func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700906 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700907
908 cmd := rule.Command().
909 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
910 Flag(config.JavacVmFlags).
911 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700912 FlagWithRspFileInputList("@", srcs).
913 FlagWithInput("@", srcJarList)
914
Colin Crossab054432019-07-15 16:13:59 -0700915 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
916 // based stubs generation.
917 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
918 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
919 // the correct package name base path.
920 if len(sourcepaths) > 0 {
921 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
922 } else {
923 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
924 }
925
926 cmd.FlagWithArg("-d ", outDir.String()).
927 Flag("-quiet")
928
929 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700930}
931
Colin Crossdaa4c672019-07-15 22:53:46 -0700932func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
933 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
934 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
935
936 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
937
938 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
939 cmd.Flag(flag).Implicits(deps)
940
941 cmd.FlagWithArg("--patch-module ", "java.base=.")
942
943 if len(classpath) > 0 {
944 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
945 }
946
947 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700948}
949
Colin Crossdaa4c672019-07-15 22:53:46 -0700950func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
951 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
952 sourcepaths android.Paths) *android.RuleBuilderCommand {
953
954 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
955
956 if len(bootclasspath) == 0 && ctx.Device() {
957 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
958 // ensure java does not fall back to the default bootclasspath.
959 cmd.FlagWithArg("-bootclasspath ", `""`)
960 } else if len(bootclasspath) > 0 {
961 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
962 }
963
964 if len(classpath) > 0 {
965 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
966 }
967
968 return cmd
969}
970
Colin Crossab054432019-07-15 16:13:59 -0700971func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
972 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700973
Colin Crossab054432019-07-15 16:13:59 -0700974 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
975 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
976
977 return rule.Command().
978 BuiltTool(ctx, "dokka").
979 Flag(config.JavacVmFlags).
980 Flag(srcJarDir.String()).
981 FlagWithInputList("-classpath ", dokkaClasspath, ":").
982 FlagWithArg("-format ", "dac").
983 FlagWithArg("-dacRoot ", "/reference/kotlin").
984 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700985}
986
987func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
988 deps := d.Javadoc.collectDeps(ctx)
989
Colin Crossdaa4c672019-07-15 22:53:46 -0700990 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
991 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
992
Nan Zhang1598a9e2018-09-04 17:14:32 -0700993 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
994 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
995 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
996 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
997
Colin Crossab054432019-07-15 16:13:59 -0700998 outDir := android.PathForModuleOut(ctx, "out")
999 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1000 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001
Colin Crossab054432019-07-15 16:13:59 -07001002 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001003
Colin Crossab054432019-07-15 16:13:59 -07001004 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1005 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001006
Colin Crossab054432019-07-15 16:13:59 -07001007 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1008
1009 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001010 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001011 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001012 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001013 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001014 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001015 }
1016
Colin Crossab054432019-07-15 16:13:59 -07001017 d.stubsFlags(ctx, cmd, stubsDir)
1018
1019 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1020
1021 var desc string
1022 if Bool(d.properties.Dokka_enabled) {
1023 desc = "dokka"
1024 } else {
1025 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1026
1027 for _, o := range d.Javadoc.properties.Out {
1028 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1029 }
1030
1031 d.postDoclavaCmds(ctx, rule)
1032 desc = "doclava"
1033 }
1034
1035 rule.Command().
1036 BuiltTool(ctx, "soong_zip").
1037 Flag("-write_if_changed").
1038 Flag("-d").
1039 FlagWithOutput("-o ", d.docZip).
1040 FlagWithArg("-C ", outDir.String()).
1041 FlagWithArg("-D ", outDir.String())
1042
1043 rule.Command().
1044 BuiltTool(ctx, "soong_zip").
1045 Flag("-write_if_changed").
1046 Flag("-jar").
1047 FlagWithOutput("-o ", d.stubsSrcJar).
1048 FlagWithArg("-C ", stubsDir.String()).
1049 FlagWithArg("-D ", stubsDir.String())
1050
1051 rule.Restat()
1052
1053 zipSyncCleanupCmd(rule, srcJarDir)
1054
1055 rule.Build(pctx, ctx, "javadoc", desc)
1056
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001057 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001058 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001059
1060 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1061 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001062
1063 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001064
1065 rule := android.NewRuleBuilder()
1066
1067 rule.Command().Text("( true")
1068
1069 rule.Command().
1070 BuiltTool(ctx, "apicheck").
1071 Flag("-JXmx1024m").
1072 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1073 OptionalFlag(d.properties.Check_api.Current.Args).
1074 Input(apiFile).
1075 Input(d.apiFile).
1076 Input(removedApiFile).
1077 Input(d.removedApiFile)
1078
1079 msg := fmt.Sprintf(`\n******************************\n`+
1080 `You have tried to change the API from what has been previously approved.\n\n`+
1081 `To make these errors go away, you have two choices:\n`+
1082 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1083 ` errors above.\n\n`+
1084 ` 2. You can update current.txt by executing the following command:\n`+
1085 ` make %s-update-current-api\n\n`+
1086 ` To submit the revised current.txt to the main Android repository,\n`+
1087 ` you will need approval.\n`+
1088 `******************************\n`, ctx.ModuleName())
1089
1090 rule.Command().
1091 Text("touch").Output(d.checkCurrentApiTimestamp).
1092 Text(") || (").
1093 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1094 Text("; exit 38").
1095 Text(")")
1096
1097 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001098
1099 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001100
1101 // update API rule
1102 rule = android.NewRuleBuilder()
1103
1104 rule.Command().Text("( true")
1105
1106 rule.Command().
1107 Text("cp").Flag("-f").
1108 Input(d.apiFile).Flag(apiFile.String())
1109
1110 rule.Command().
1111 Text("cp").Flag("-f").
1112 Input(d.removedApiFile).Flag(removedApiFile.String())
1113
1114 msg = "failed to update public API"
1115
1116 rule.Command().
1117 Text("touch").Output(d.updateCurrentApiTimestamp).
1118 Text(") || (").
1119 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1120 Text("; exit 38").
1121 Text(")")
1122
1123 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001124 }
1125
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001126 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001127 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001128
1129 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1130 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001131
1132 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001133
1134 rule := android.NewRuleBuilder()
1135
1136 rule.Command().
1137 Text("(").
1138 BuiltTool(ctx, "apicheck").
1139 Flag("-JXmx1024m").
1140 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1141 OptionalFlag(d.properties.Check_api.Last_released.Args).
1142 Input(apiFile).
1143 Input(d.apiFile).
1144 Input(removedApiFile).
1145 Input(d.removedApiFile)
1146
1147 msg := `\n******************************\n` +
1148 `You have tried to change the API from what has been previously released in\n` +
1149 `an SDK. Please fix the errors listed above.\n` +
1150 `******************************\n`
1151
1152 rule.Command().
1153 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1154 Text(") || (").
1155 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1156 Text("; exit 38").
1157 Text(")")
1158
1159 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001160 }
1161}
1162
1163//
1164// Droidstubs
1165//
1166type Droidstubs struct {
1167 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001168 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001169
Pete Gillin581d6082018-10-22 15:55:04 +01001170 properties DroidstubsProperties
1171 apiFile android.WritablePath
1172 apiXmlFile android.WritablePath
1173 lastReleasedApiXmlFile android.WritablePath
1174 dexApiFile android.WritablePath
1175 privateApiFile android.WritablePath
1176 privateDexApiFile android.WritablePath
1177 removedApiFile android.WritablePath
1178 removedDexApiFile android.WritablePath
1179 apiMappingFile android.WritablePath
1180 exactApiFile android.WritablePath
1181 proguardFile android.WritablePath
1182 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001183
1184 checkCurrentApiTimestamp android.WritablePath
1185 updateCurrentApiTimestamp android.WritablePath
1186 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001187 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001188 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001189
Pete Gillin581d6082018-10-22 15:55:04 +01001190 checkNullabilityWarningsTimestamp android.WritablePath
1191
Nan Zhang1598a9e2018-09-04 17:14:32 -07001192 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001193 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001194
1195 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001196
1197 jdiffDocZip android.WritablePath
1198 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001199
1200 metadataZip android.WritablePath
1201 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001202}
1203
Colin Crossa3002fc2019-07-08 16:48:04 -07001204// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1205// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1206// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001207func DroidstubsFactory() android.Module {
1208 module := &Droidstubs{}
1209
1210 module.AddProperties(&module.properties,
1211 &module.Javadoc.properties)
1212
1213 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001214 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001215 return module
1216}
1217
Colin Crossa3002fc2019-07-08 16:48:04 -07001218// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1219// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1220// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1221// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001222func DroidstubsHostFactory() android.Module {
1223 module := &Droidstubs{}
1224
1225 module.AddProperties(&module.properties,
1226 &module.Javadoc.properties)
1227
1228 InitDroiddocModule(module, android.HostSupported)
1229 return module
1230}
1231
1232func (d *Droidstubs) ApiFilePath() android.Path {
1233 return d.apiFilePath
1234}
1235
1236func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1237 d.Javadoc.addDeps(ctx)
1238
Inseob Kim38449af2019-02-28 14:24:05 +09001239 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1240 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1241 }
1242
Nan Zhang1598a9e2018-09-04 17:14:32 -07001243 if len(d.properties.Merge_annotations_dirs) != 0 {
1244 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1245 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1246 }
1247 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001248
Pete Gillin77167902018-09-19 18:16:26 +01001249 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1250 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1251 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1252 }
1253 }
1254
Nan Zhang9c69a122018-08-22 10:22:08 -07001255 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1256 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1257 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1258 }
1259 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001260}
1261
Colin Cross33961b52019-07-11 11:01:22 -07001262func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001263 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1264 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001265 String(d.properties.Api_filename) != "" {
1266 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001267 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001268 d.apiFilePath = d.apiFile
1269 }
1270
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001271 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1272 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001273 String(d.properties.Removed_api_filename) != "" {
1274 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001275 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001276 }
1277
1278 if String(d.properties.Private_api_filename) != "" {
1279 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001280 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001281 }
1282
1283 if String(d.properties.Dex_api_filename) != "" {
1284 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001285 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001286 }
1287
1288 if String(d.properties.Private_dex_api_filename) != "" {
1289 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001290 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001291 }
1292
1293 if String(d.properties.Removed_dex_api_filename) != "" {
1294 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001295 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001296 }
1297
1298 if String(d.properties.Exact_api_filename) != "" {
1299 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001300 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001301 }
1302
Nan Zhang9c69a122018-08-22 10:22:08 -07001303 if String(d.properties.Dex_mapping_filename) != "" {
1304 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001305 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001306 }
1307
Nan Zhang199645c2018-09-19 12:40:06 -07001308 if String(d.properties.Proguard_filename) != "" {
1309 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001310 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001311 }
1312
Nan Zhang9c69a122018-08-22 10:22:08 -07001313 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001314 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1315 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001316 }
1317
Nan Zhang1598a9e2018-09-04 17:14:32 -07001318 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001319 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001320 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001321 cmd.FlagWithArg("--stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001322 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001323}
1324
Colin Cross33961b52019-07-11 11:01:22 -07001325func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001327 cmd.Flag("--include-annotations")
1328
Pete Gillinc382a562018-11-14 18:45:46 +00001329 validatingNullability :=
1330 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1331 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001332
Pete Gillina262c052018-09-14 14:25:48 +01001333 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001334 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001335 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001336 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001337 }
Colin Cross33961b52019-07-11 11:01:22 -07001338
Pete Gillinc382a562018-11-14 18:45:46 +00001339 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001340 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001341 }
Colin Cross33961b52019-07-11 11:01:22 -07001342
Pete Gillina262c052018-09-14 14:25:48 +01001343 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001344 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001345 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001346 }
Nan Zhanga40da042018-08-01 12:48:00 -07001347
1348 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001349 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001350
Nan Zhang1598a9e2018-09-04 17:14:32 -07001351 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001352 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001353 "has to be non-empty if annotations was enabled!")
1354 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001355
Colin Cross33961b52019-07-11 11:01:22 -07001356 d.mergeAnnoDirFlags(ctx, cmd)
1357
1358 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1359 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1360 FlagWithArg("--hide ", "SuperfluousPrefix").
1361 FlagWithArg("--hide ", "AnnotationExtraction")
1362 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001363}
1364
Colin Cross33961b52019-07-11 11:01:22 -07001365func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1366 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1367 if t, ok := m.(*ExportedDroiddocDir); ok {
1368 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1369 } else {
1370 ctx.PropertyErrorf("merge_annotations_dirs",
1371 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1372 }
1373 })
1374}
1375
1376func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001377 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1378 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001379 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001380 } else {
1381 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1382 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1383 }
1384 })
Nan Zhanga40da042018-08-01 12:48:00 -07001385}
1386
Colin Cross33961b52019-07-11 11:01:22 -07001387func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001388 if Bool(d.properties.Api_levels_annotations_enabled) {
1389 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001390
1391 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1392 ctx.PropertyErrorf("api_levels_annotations_dirs",
1393 "has to be non-empty if api levels annotations was enabled!")
1394 }
1395
Colin Cross33961b52019-07-11 11:01:22 -07001396 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1397 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1398 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1399 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001400
1401 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1402 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001403 for _, dep := range t.deps {
1404 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001405 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001406 }
1407 }
Colin Cross33961b52019-07-11 11:01:22 -07001408 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001409 } else {
1410 ctx.PropertyErrorf("api_levels_annotations_dirs",
1411 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1412 }
1413 })
1414
1415 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001416}
1417
Colin Cross33961b52019-07-11 11:01:22 -07001418func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001419 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1420 if d.apiFile.String() == "" {
1421 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1422 }
1423
1424 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001425 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001426
1427 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1428 ctx.PropertyErrorf("check_api.last_released.api_file",
1429 "has to be non-empty if jdiff was enabled!")
1430 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001431
Colin Cross33961b52019-07-11 11:01:22 -07001432 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001433 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001434 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1435 }
1436}
Nan Zhang71bbe632018-09-17 14:32:21 -07001437
Colin Cross1e743852019-10-28 11:37:20 -07001438func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001439 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
1440 cmd := rule.Command().BuiltTool(ctx, "metalava").
1441 Flag(config.JavacVmFlags).
1442 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001443 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001444 FlagWithRspFileInputList("@", srcs).
1445 FlagWithInput("@", srcJarList)
1446
1447 if len(bootclasspath) > 0 {
1448 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001449 }
1450
Colin Cross33961b52019-07-11 11:01:22 -07001451 if len(classpath) > 0 {
1452 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1453 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001454
Colin Cross33961b52019-07-11 11:01:22 -07001455 if len(sourcepaths) > 0 {
1456 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1457 } else {
1458 cmd.FlagWithArg("-sourcepath ", `""`)
1459 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001460
Colin Cross33961b52019-07-11 11:01:22 -07001461 cmd.Flag("--no-banner").
1462 Flag("--color").
1463 Flag("--quiet").
1464 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001465
Colin Cross33961b52019-07-11 11:01:22 -07001466 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001467}
1468
Nan Zhang1598a9e2018-09-04 17:14:32 -07001469func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001470 deps := d.Javadoc.collectDeps(ctx)
1471
1472 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001473
Colin Cross33961b52019-07-11 11:01:22 -07001474 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001475
Colin Crossdaa4c672019-07-15 22:53:46 -07001476 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001477
Colin Cross33961b52019-07-11 11:01:22 -07001478 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1479 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001480
Colin Cross33961b52019-07-11 11:01:22 -07001481 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001482
Colin Cross33961b52019-07-11 11:01:22 -07001483 rule.Command().Text("rm -rf").Text(stubsDir.String())
1484 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001485
Colin Cross33961b52019-07-11 11:01:22 -07001486 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1487
1488 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1489 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1490
1491 d.stubsFlags(ctx, cmd, stubsDir)
1492
1493 d.annotationsFlags(ctx, cmd)
1494 d.inclusionAnnotationsFlags(ctx, cmd)
1495 d.apiLevelsAnnotationsFlags(ctx, cmd)
1496 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001497
Nan Zhang1598a9e2018-09-04 17:14:32 -07001498 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1499 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1500 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1501 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1502 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001503 }
Colin Cross33961b52019-07-11 11:01:22 -07001504
1505 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1506 for _, o := range d.Javadoc.properties.Out {
1507 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1508 }
1509
1510 rule.Command().
1511 BuiltTool(ctx, "soong_zip").
1512 Flag("-write_if_changed").
1513 Flag("-jar").
1514 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1515 FlagWithArg("-C ", stubsDir.String()).
1516 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001517
1518 if Bool(d.properties.Write_sdk_values) {
1519 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1520 rule.Command().
1521 BuiltTool(ctx, "soong_zip").
1522 Flag("-write_if_changed").
1523 Flag("-d").
1524 FlagWithOutput("-o ", d.metadataZip).
1525 FlagWithArg("-C ", d.metadataDir.String()).
1526 FlagWithArg("-D ", d.metadataDir.String())
1527 }
1528
Colin Cross33961b52019-07-11 11:01:22 -07001529 rule.Restat()
1530
1531 zipSyncCleanupCmd(rule, srcJarDir)
1532
1533 rule.Build(pctx, ctx, "metalava", "metalava")
1534
1535 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001536
Adrian Roos075eedc2019-10-10 12:07:03 +02001537 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1538 rule := android.NewRuleBuilder()
1539 rule.Command().Text("( true")
1540
1541 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1542 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1543
1544 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1545 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1546
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001547 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1548
Adrian Roos075eedc2019-10-10 12:07:03 +02001549 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1550 if newSince.Valid() {
1551 cmd.FlagWithInput("--api-lint ", newSince.Path())
1552 } else {
1553 cmd.Flag("--api-lint")
1554 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001555 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1556 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001557
1558 d.inclusionAnnotationsFlags(ctx, cmd)
1559 d.mergeAnnoDirFlags(ctx, cmd)
1560
1561 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1562 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1563 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1564
1565 if baselineFile.Valid() {
1566 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1567 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1568 }
1569
1570 zipSyncCleanupCmd(rule, srcJarDir)
1571
1572 msg := fmt.Sprintf(`\n******************************\n`+
1573 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1574 `To make these errors go away, you have two choices:\n`+
1575 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1576 ` 2. You can update the baseline by executing the following command:\n`+
1577 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1578 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1579 rule.Command().
1580 Text("touch").Output(d.apiLintTimestamp).
1581 Text(") || (").
1582 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1583 Text("; exit 38").
1584 Text(")")
1585
1586 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1587
1588 }
1589
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001590 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001591 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001592
1593 if len(d.Javadoc.properties.Out) > 0 {
1594 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1595 }
1596
1597 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1598 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001599 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1600 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001601
Nan Zhang2760dfc2018-08-24 17:32:54 +00001602 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001603
Colin Cross33961b52019-07-11 11:01:22 -07001604 rule := android.NewRuleBuilder()
1605
1606 rule.Command().Text("( true")
1607
1608 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1609 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1610
1611 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1612 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1613
1614 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1615 FlagWithInput("--check-compatibility:api:current ", apiFile).
1616 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1617
1618 d.inclusionAnnotationsFlags(ctx, cmd)
1619 d.mergeAnnoDirFlags(ctx, cmd)
1620
Adrian Roos14f75a92019-08-12 17:54:09 +02001621 if baselineFile.Valid() {
1622 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1623 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1624 }
1625
Colin Cross33961b52019-07-11 11:01:22 -07001626 zipSyncCleanupCmd(rule, srcJarDir)
1627
1628 msg := fmt.Sprintf(`\n******************************\n`+
1629 `You have tried to change the API from what has been previously approved.\n\n`+
1630 `To make these errors go away, you have two choices:\n`+
1631 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1632 ` errors above.\n\n`+
1633 ` 2. You can update current.txt by executing the following command:\n`+
1634 ` make %s-update-current-api\n\n`+
1635 ` To submit the revised current.txt to the main Android repository,\n`+
1636 ` you will need approval.\n`+
1637 `******************************\n`, ctx.ModuleName())
1638
1639 rule.Command().
1640 Text("touch").Output(d.checkCurrentApiTimestamp).
1641 Text(") || (").
1642 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1643 Text("; exit 38").
1644 Text(")")
1645
1646 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001647
1648 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001649
1650 // update API rule
1651 rule = android.NewRuleBuilder()
1652
1653 rule.Command().Text("( true")
1654
1655 rule.Command().
1656 Text("cp").Flag("-f").
1657 Input(d.apiFile).Flag(apiFile.String())
1658
1659 rule.Command().
1660 Text("cp").Flag("-f").
1661 Input(d.removedApiFile).Flag(removedApiFile.String())
1662
1663 msg = "failed to update public API"
1664
1665 rule.Command().
1666 Text("touch").Output(d.updateCurrentApiTimestamp).
1667 Text(") || (").
1668 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1669 Text("; exit 38").
1670 Text(")")
1671
1672 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001673 }
Nan Zhanga40da042018-08-01 12:48:00 -07001674
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001675 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001676 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001677
1678 if len(d.Javadoc.properties.Out) > 0 {
1679 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1680 }
1681
1682 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1683 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001684 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1685 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001686
Nan Zhang2760dfc2018-08-24 17:32:54 +00001687 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001688
Colin Cross33961b52019-07-11 11:01:22 -07001689 rule := android.NewRuleBuilder()
1690
1691 rule.Command().Text("( true")
1692
1693 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1694 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1695
1696 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1697 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1698
1699 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1700 FlagWithInput("--check-compatibility:api:released ", apiFile)
1701
1702 d.inclusionAnnotationsFlags(ctx, cmd)
1703
1704 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1705
1706 d.mergeAnnoDirFlags(ctx, cmd)
1707
Adrian Roos14f75a92019-08-12 17:54:09 +02001708 if baselineFile.Valid() {
1709 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1710 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1711 }
1712
Colin Cross33961b52019-07-11 11:01:22 -07001713 zipSyncCleanupCmd(rule, srcJarDir)
1714
1715 msg := `\n******************************\n` +
1716 `You have tried to change the API from what has been previously released in\n` +
1717 `an SDK. Please fix the errors listed above.\n` +
1718 `******************************\n`
1719 rule.Command().
1720 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1721 Text(") || (").
1722 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1723 Text("; exit 38").
1724 Text(")")
1725
1726 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001727 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001728
Pete Gillin581d6082018-10-22 15:55:04 +01001729 if String(d.properties.Check_nullability_warnings) != "" {
1730 if d.nullabilityWarningsFile == nil {
1731 ctx.PropertyErrorf("check_nullability_warnings",
1732 "Cannot specify check_nullability_warnings unless validating nullability")
1733 }
Colin Cross33961b52019-07-11 11:01:22 -07001734
1735 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1736
Pete Gillin581d6082018-10-22 15:55:04 +01001737 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001738
Pete Gillin581d6082018-10-22 15:55:04 +01001739 msg := fmt.Sprintf(`\n******************************\n`+
1740 `The warnings encountered during nullability annotation validation did\n`+
1741 `not match the checked in file of expected warnings. The diffs are shown\n`+
1742 `above. You have two options:\n`+
1743 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1744 ` 2. Update the file of expected warnings by running:\n`+
1745 ` cp %s %s\n`+
1746 ` and submitting the updated file as part of your change.`,
1747 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001748
1749 rule := android.NewRuleBuilder()
1750
1751 rule.Command().
1752 Text("(").
1753 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1754 Text("&&").
1755 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1756 Text(") || (").
1757 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1758 Text("; exit 38").
1759 Text(")")
1760
1761 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001762 }
1763
Nan Zhang71bbe632018-09-17 14:32:21 -07001764 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001765 if len(d.Javadoc.properties.Out) > 0 {
1766 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1767 }
1768
1769 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1770 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1771 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1772
1773 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001774
Nan Zhang86b06202018-09-21 17:09:21 -07001775 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1776 // since there's cron job downstream that fetch this .zip file periodically.
1777 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001778 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1779 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1780
Nan Zhang71bbe632018-09-17 14:32:21 -07001781 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001782
Colin Cross33961b52019-07-11 11:01:22 -07001783 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1784 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001785
Colin Cross33961b52019-07-11 11:01:22 -07001786 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1787
Colin Crossdaa4c672019-07-15 22:53:46 -07001788 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001789 deps.bootClasspath, deps.classpath, d.sourcepaths)
1790
1791 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001792 Flag("-XDignore.symbol.file").
1793 FlagWithArg("-doclet ", "jdiff.JDiff").
1794 FlagWithInput("-docletpath ", jdiff).
1795 Flag("-quiet").
1796 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1797 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1798 Implicit(d.apiXmlFile).
1799 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1800 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1801 Implicit(d.lastReleasedApiXmlFile)
1802
Colin Cross33961b52019-07-11 11:01:22 -07001803 rule.Command().
1804 BuiltTool(ctx, "soong_zip").
1805 Flag("-write_if_changed").
1806 Flag("-d").
1807 FlagWithOutput("-o ", d.jdiffDocZip).
1808 FlagWithArg("-C ", outDir.String()).
1809 FlagWithArg("-D ", outDir.String())
1810
1811 rule.Command().
1812 BuiltTool(ctx, "soong_zip").
1813 Flag("-write_if_changed").
1814 Flag("-jar").
1815 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1816 FlagWithArg("-C ", stubsDir.String()).
1817 FlagWithArg("-D ", stubsDir.String())
1818
1819 rule.Restat()
1820
1821 zipSyncCleanupCmd(rule, srcJarDir)
1822
1823 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001824 }
Nan Zhang581fd212018-01-10 16:06:12 -08001825}
Dan Willemsencc090972018-02-26 14:33:31 -08001826
Nan Zhanga40da042018-08-01 12:48:00 -07001827//
Nan Zhangf4936b02018-08-01 15:00:28 -07001828// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001829//
Dan Willemsencc090972018-02-26 14:33:31 -08001830var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001831var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001832var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001833var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001834
Nan Zhangf4936b02018-08-01 15:00:28 -07001835type ExportedDroiddocDirProperties struct {
1836 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001837 Path *string
1838}
1839
Nan Zhangf4936b02018-08-01 15:00:28 -07001840type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001841 android.ModuleBase
1842
Nan Zhangf4936b02018-08-01 15:00:28 -07001843 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001844
1845 deps android.Paths
1846 dir android.Path
1847}
1848
Colin Crossa3002fc2019-07-08 16:48:04 -07001849// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001850func ExportedDroiddocDirFactory() android.Module {
1851 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001852 module.AddProperties(&module.properties)
1853 android.InitAndroidModule(module)
1854 return module
1855}
1856
Nan Zhangf4936b02018-08-01 15:00:28 -07001857func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001858
Nan Zhangf4936b02018-08-01 15:00:28 -07001859func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001860 path := String(d.properties.Path)
1861 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001862 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001863}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001864
1865//
1866// Defaults
1867//
1868type DocDefaults struct {
1869 android.ModuleBase
1870 android.DefaultsModuleBase
1871}
1872
Nan Zhangb2b33de2018-02-23 11:18:47 -08001873func DocDefaultsFactory() android.Module {
1874 module := &DocDefaults{}
1875
1876 module.AddProperties(
1877 &JavadocProperties{},
1878 &DroiddocProperties{},
1879 )
1880
1881 android.InitDefaultsModule(module)
1882
1883 return module
1884}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001885
1886func StubsDefaultsFactory() android.Module {
1887 module := &DocDefaults{}
1888
1889 module.AddProperties(
1890 &JavadocProperties{},
1891 &DroidstubsProperties{},
1892 )
1893
1894 android.InitDefaultsModule(module)
1895
1896 return module
1897}
Colin Cross33961b52019-07-11 11:01:22 -07001898
1899func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1900 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1901
1902 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1903 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1904 srcJarList := srcJarDir.Join(ctx, "list")
1905
1906 rule.Temporary(srcJarList)
1907
1908 rule.Command().BuiltTool(ctx, "zipsync").
1909 FlagWithArg("-d ", srcJarDir.String()).
1910 FlagWithOutput("-l ", srcJarList).
1911 FlagWithArg("-f ", `"*.java"`).
1912 Inputs(srcJars)
1913
1914 return srcJarList
1915}
1916
1917func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1918 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1919}
Paul Duffin91547182019-11-12 19:39:36 +00001920
1921var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1922
1923type PrebuiltStubsSourcesProperties struct {
1924 Srcs []string `android:"path"`
1925}
1926
1927type PrebuiltStubsSources struct {
1928 android.ModuleBase
1929 android.DefaultableModuleBase
1930 prebuilt android.Prebuilt
1931 android.SdkBase
1932
1933 properties PrebuiltStubsSourcesProperties
1934
1935 srcs android.Paths
1936 stubsSrcJar android.ModuleOutPath
1937}
1938
1939func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1940 p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1941}
1942
1943func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1944 return &p.prebuilt
1945}
1946
1947func (p *PrebuiltStubsSources) Name() string {
1948 return p.prebuilt.Name(p.ModuleBase.Name())
1949}
1950
1951func (p *PrebuiltStubsSources) Srcs() android.Paths {
1952 return append(android.Paths{}, p.srcs...)
1953}
1954
1955// prebuilt_stubs_sources imports a set of java source files as if they were
1956// generated by droidstubs.
1957//
1958// By default, a prebuilt_stubs_sources has a single variant that expects a
1959// set of `.java` files generated by droidstubs.
1960//
1961// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1962// for host modules.
1963//
1964// Intended only for use by sdk snapshots.
1965func PrebuiltStubsSourcesFactory() android.Module {
1966 module := &PrebuiltStubsSources{}
1967
1968 module.AddProperties(&module.properties)
1969
1970 android.InitPrebuiltModule(module, &module.properties.Srcs)
1971 android.InitSdkAwareModule(module)
1972 InitDroiddocModule(module, android.HostAndDeviceSupported)
1973 return module
1974}
1975
1976func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) {
1977 stubsSrcJar := d.stubsSrcJar
1978
1979 snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
1980 builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
1981
Paul Duffinb645ec82019-11-27 17:43:54 +00001982 pbm := builder.AddPrebuiltModule(sdkModuleContext.OtherModuleName(d), "prebuilt_stubs_sources")
1983 pbm.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin91547182019-11-12 19:39:36 +00001984}