blob: 3b7f772d71666886afd9fed2aeba92a5673249d6 [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
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000030 RegisterDocsBuildComponents(android.InitRegistrationContext)
31 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000032
33 // Register sdk member type.
34 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
35 SdkMemberTypeBase: android.SdkMemberTypeBase{
36 PropertyName: "stubs_sources",
37 },
38 })
Nan Zhang581fd212018-01-10 16:06:12 -080039}
40
Paul Duffin884363e2019-12-19 10:21:09 +000041func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
43
44 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
45 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
46 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
47 ctx.RegisterModuleType("javadoc", JavadocFactory)
48 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
49}
50
51func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
52 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
53
54 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
55 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
56
57 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
58}
59
Colin Crossa1ce2a02018-06-20 15:19:39 -070060var (
61 srcsLibTag = dependencyTag{name: "sources from javalib"}
62)
63
Nan Zhang581fd212018-01-10 16:06:12 -080064type JavadocProperties struct {
65 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
66 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080067 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080068
69 // list of directories rooted at the Android.bp file that will
70 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080071 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080072
73 // list of source files that should not be used to build the Java module.
74 // This is most useful in the arch/multilib variants to remove non-common files
75 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080076 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080077
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090078 // list of package names that should actually be used. If this property is left unspecified,
79 // all the sources from the srcs property is used.
80 Filter_packages []string
81
Nan Zhangb2b33de2018-02-23 11:18:47 -080082 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080083 Libs []string `android:"arch_variant"`
84
85 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080086 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080087
Paul Duffine25c6442019-10-11 13:50:28 +010088 // if not blank, set to the version of the sdk to compile against.
89 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080090 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090091
Paul Duffine25c6442019-10-11 13:50:28 +010092 // When targeting 1.9 and above, override the modules to use with --system,
93 // otherwise provides defaults libraries to add to the bootclasspath.
94 // Defaults to "none"
95 System_modules *string
96
Jiyong Park1e440682018-05-23 18:42:04 +090097 Aidl struct {
98 // Top level directories to pass to aidl tool
99 Include_dirs []string
100
101 // Directories rooted at the Android.bp file to pass to aidl tool
102 Local_include_dirs []string
103 }
Nan Zhang357466b2018-04-17 17:38:36 -0700104
105 // If not blank, set the java version passed to javadoc as -source
106 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700107
108 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800109 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
111 // user customized droiddoc args.
112 // Available variables for substitution:
113 //
114 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700115 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700116 Args *string
117
118 // names of the output files used in args that will be generated
119 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800120}
121
Nan Zhang61819ce2018-05-04 18:49:16 -0700122type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900123 // path to the API txt file that the new API extracted from source code is checked
124 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800125 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700126
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900127 // path to the API txt file that the new @removed API extractd from source code is
128 // checked against. The path can be local to the module or from other module (via
129 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800130 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700131
Adrian Roos14f75a92019-08-12 17:54:09 +0200132 // If not blank, path to the baseline txt file for approved API check violations.
133 Baseline_file *string `android:"path"`
134
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900135 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700136 Args *string
137}
138
Nan Zhang581fd212018-01-10 16:06:12 -0800139type DroiddocProperties struct {
140 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800141 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800142
Nan Zhanga40da042018-08-01 12:48:00 -0700143 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800144 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800145
146 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800147 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800148
149 // proofread file contains all of the text content of the javadocs concatenated into one file,
150 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700151 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800152
153 // a todo file lists the program elements that are missing documentation.
154 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800155 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800156
157 // directory under current module source that provide additional resources (images).
158 Resourcesdir *string
159
160 // resources output directory under out/soong/.intermediates.
161 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800162
Nan Zhange2ba5d42018-07-11 15:16:55 -0700163 // if set to true, collect the values used by the Dev tools and
164 // write them in files packaged with the SDK. Defaults to false.
165 Write_sdk_values *bool
166
167 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800168 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700169
170 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700172
Nan Zhang581fd212018-01-10 16:06:12 -0800173 // a list of files under current module source dir which contains known tags in Java sources.
174 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700176
177 // the tag name used to distinguish if the API files belong to public/system/test.
178 Api_tag_name *string
179
180 // the generated public API filename by Doclava.
181 Api_filename *string
182
David Brazdilfbe4cc32018-05-31 13:56:46 +0100183 // the generated public Dex API filename by Doclava.
184 Dex_api_filename *string
185
Nan Zhang28c68b92018-03-13 16:17:01 -0700186 // the generated private API filename by Doclava.
187 Private_api_filename *string
188
189 // the generated private Dex API filename by Doclava.
190 Private_dex_api_filename *string
191
192 // the generated removed API filename by Doclava.
193 Removed_api_filename *string
194
David Brazdilaac0c3c2018-04-24 16:23:29 +0100195 // the generated removed Dex API filename by Doclava.
196 Removed_dex_api_filename *string
197
Mathew Inwood76c3de12018-06-22 15:28:11 +0100198 // mapping of dex signatures to source file and line number. This is a temporary property and
199 // will be deleted; you probably shouldn't be using it.
200 Dex_mapping_filename *string
201
Nan Zhang28c68b92018-03-13 16:17:01 -0700202 // the generated exact API filename by Doclava.
203 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700204
Nan Zhang66dc2362018-08-14 20:41:04 -0700205 // the generated proguard filename by Doclava.
206 Proguard_filename *string
207
Nan Zhang853f4202018-04-12 16:55:56 -0700208 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
209 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700210
211 Check_api struct {
212 Last_released ApiToCheck
213
214 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900215
216 // do not perform API check against Last_released, in the case that both two specified API
217 // files by Last_released are modules which don't exist.
218 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700219 }
Nan Zhang79614d12018-04-19 18:03:39 -0700220
Nan Zhang1598a9e2018-09-04 17:14:32 -0700221 // if set to true, generate docs through Dokka instead of Doclava.
222 Dokka_enabled *bool
223}
224
225type DroidstubsProperties struct {
226 // the tag name used to distinguish if the API files belong to public/system/test.
227 Api_tag_name *string
228
Nan Zhang199645c2018-09-19 12:40:06 -0700229 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700230 Api_filename *string
231
Nan Zhang199645c2018-09-19 12:40:06 -0700232 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700233 Dex_api_filename *string
234
Nan Zhang199645c2018-09-19 12:40:06 -0700235 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700236 Private_api_filename *string
237
Nan Zhang199645c2018-09-19 12:40:06 -0700238 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700239 Private_dex_api_filename *string
240
Nan Zhang199645c2018-09-19 12:40:06 -0700241 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700242 Removed_api_filename *string
243
Nan Zhang199645c2018-09-19 12:40:06 -0700244 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700245 Removed_dex_api_filename *string
246
Nan Zhang9c69a122018-08-22 10:22:08 -0700247 // mapping of dex signatures to source file and line number. This is a temporary property and
248 // will be deleted; you probably shouldn't be using it.
249 Dex_mapping_filename *string
250
Nan Zhang199645c2018-09-19 12:40:06 -0700251 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700252 Exact_api_filename *string
253
Nan Zhang199645c2018-09-19 12:40:06 -0700254 // the generated proguard filename by Metalava.
255 Proguard_filename *string
256
Nan Zhang1598a9e2018-09-04 17:14:32 -0700257 Check_api struct {
258 Last_released ApiToCheck
259
260 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900261
262 // do not perform API check against Last_released, in the case that both two specified API
263 // files by Last_released are modules which don't exist.
264 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200265
266 Api_lint struct {
267 Enabled *bool
268
269 // If set, performs api_lint on any new APIs not found in the given signature file
270 New_since *string `android:"path"`
271
272 // If not blank, path to the baseline txt file for approved API lint violations.
273 Baseline_file *string `android:"path"`
274 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700275 }
Nan Zhang79614d12018-04-19 18:03:39 -0700276
277 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800278 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700279
280 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700281 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700282
Pete Gillin77167902018-09-19 18:16:26 +0100283 // 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 -0700284 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700285
Pete Gillin77167902018-09-19 18:16:26 +0100286 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
287 Merge_inclusion_annotations_dirs []string
288
Pete Gillinc382a562018-11-14 18:45:46 +0000289 // a file containing a list of classes to do nullability validation for.
290 Validate_nullability_from_list *string
291
Pete Gillin581d6082018-10-22 15:55:04 +0100292 // a file containing expected warnings produced by validation of nullability annotations.
293 Check_nullability_warnings *string
294
Nan Zhang1598a9e2018-09-04 17:14:32 -0700295 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
296 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700297
298 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
299 Api_levels_annotations_enabled *bool
300
301 // the dirs which Metalava extracts API levels annotations from.
302 Api_levels_annotations_dirs []string
303
304 // if set to true, collect the values used by the Dev tools and
305 // write them in files packaged with the SDK. Defaults to false.
306 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700307
308 // If set to true, .xml based public API file will be also generated, and
309 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
310 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800311}
312
Nan Zhanga40da042018-08-01 12:48:00 -0700313//
314// Common flags passed down to build rule
315//
316type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700317 bootClasspathArgs string
318 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700319 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700320 dokkaClasspathArgs string
321 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700322 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700323
Nan Zhanga40da042018-08-01 12:48:00 -0700324 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700325 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700326 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700327}
328
329func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
330 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
331 android.InitDefaultableModule(module)
332}
333
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200334func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
335 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
336 return false
337 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338 return true
339 } else if String(apiToCheck.Api_file) != "" {
340 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
341 } else if String(apiToCheck.Removed_api_file) != "" {
342 panic("for " + apiVersionTag + " api_file has to be non-empty!")
343 }
344
345 return false
346}
347
Inseob Kim38449af2019-02-28 14:24:05 +0900348func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
349 api_file := String(apiToCheck.Api_file)
350 removed_api_file := String(apiToCheck.Removed_api_file)
351
352 api_module := android.SrcIsModule(api_file)
353 removed_api_module := android.SrcIsModule(removed_api_file)
354
355 if api_module == "" || removed_api_module == "" {
356 return
357 }
358
359 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
360 return
361 }
362
363 apiToCheck.Api_file = nil
364 apiToCheck.Removed_api_file = nil
365}
366
Nan Zhang1598a9e2018-09-04 17:14:32 -0700367type ApiFilePath interface {
368 ApiFilePath() android.Path
369}
370
Nan Zhanga40da042018-08-01 12:48:00 -0700371//
372// Javadoc
373//
Nan Zhang581fd212018-01-10 16:06:12 -0800374type Javadoc struct {
375 android.ModuleBase
376 android.DefaultableModuleBase
377
378 properties JavadocProperties
379
380 srcJars android.Paths
381 srcFiles android.Paths
382 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700383 argFiles android.Paths
384
385 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800386
Nan Zhangccff0f72018-03-08 17:26:16 -0800387 docZip android.WritablePath
388 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800389}
390
Colin Cross41955e82019-05-29 14:40:35 -0700391func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
392 switch tag {
393 case "":
394 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700395 case ".docs.zip":
396 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700397 default:
398 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
399 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800400}
401
Colin Crossa3002fc2019-07-08 16:48:04 -0700402// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800403func JavadocFactory() android.Module {
404 module := &Javadoc{}
405
406 module.AddProperties(&module.properties)
407
408 InitDroiddocModule(module, android.HostAndDeviceSupported)
409 return module
410}
411
Colin Crossa3002fc2019-07-08 16:48:04 -0700412// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800413func JavadocHostFactory() android.Module {
414 module := &Javadoc{}
415
416 module.AddProperties(&module.properties)
417
418 InitDroiddocModule(module, android.HostSupported)
419 return module
420}
421
Colin Cross41955e82019-05-29 14:40:35 -0700422var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800423
Colin Cross83bb3162018-06-25 15:48:06 -0700424func (j *Javadoc) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900425 return String(j.properties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700426}
427
Paul Duffine25c6442019-10-11 13:50:28 +0100428func (j *Javadoc) systemModules() string {
429 return proptools.String(j.properties.System_modules)
430}
431
Colin Cross83bb3162018-06-25 15:48:06 -0700432func (j *Javadoc) minSdkVersion() string {
433 return j.sdkVersion()
434}
435
Dan Willemsen419290a2018-10-31 15:28:47 -0700436func (j *Javadoc) targetSdkVersion() string {
437 return j.sdkVersion()
438}
439
Nan Zhang581fd212018-01-10 16:06:12 -0800440func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
441 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100442 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700443 if sdkDep.useDefaultLibs {
444 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
445 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
446 if sdkDep.hasFrameworkLibs() {
447 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700448 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700449 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700450 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100451 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700452 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800453 }
454 }
455
Colin Cross42d48b72018-08-29 14:10:52 -0700456 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800457}
458
Nan Zhanga40da042018-08-01 12:48:00 -0700459func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
460 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900461
Colin Cross3047fa22019-04-18 10:56:44 -0700462 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900463
464 return flags
465}
466
467func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700468 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900469
470 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
471 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
472
473 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700474 var deps android.Paths
475
Jiyong Park1e440682018-05-23 18:42:04 +0900476 if aidlPreprocess.Valid() {
477 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700478 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900479 } else {
480 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
481 }
482
483 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
484 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
485 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
486 flags = append(flags, "-I"+src.String())
487 }
488
Colin Cross3047fa22019-04-18 10:56:44 -0700489 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900490}
491
Jiyong Parkd90d7412019-08-20 22:49:19 +0900492// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900493func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700494 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900495
496 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700497 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900498
Jiyong Park1112c4c2019-08-16 21:12:10 +0900499 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
500
Jiyong Park1e440682018-05-23 18:42:04 +0900501 for _, srcFile := range srcFiles {
502 switch srcFile.Ext() {
503 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700504 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900505 case ".logtags":
506 javaFile := genLogtags(ctx, srcFile)
507 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900508 default:
509 outSrcFiles = append(outSrcFiles, srcFile)
510 }
511 }
512
Colin Crossc0806172019-06-14 18:51:47 -0700513 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
514 if len(aidlSrcs) > 0 {
515 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
516 outSrcFiles = append(outSrcFiles, srcJarFiles...)
517 }
518
Jiyong Park1e440682018-05-23 18:42:04 +0900519 return outSrcFiles
520}
521
Nan Zhang581fd212018-01-10 16:06:12 -0800522func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
523 var deps deps
524
Colin Cross83bb3162018-06-25 15:48:06 -0700525 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800526 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700527 ctx.AddMissingDependencies(sdkDep.bootclasspath)
528 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800529 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700530 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800531 }
532
533 ctx.VisitDirectDeps(func(module android.Module) {
534 otherName := ctx.OtherModuleName(module)
535 tag := ctx.OtherModuleDependencyTag(module)
536
Colin Cross2d24c1b2018-05-23 10:59:18 -0700537 switch tag {
538 case bootClasspathTag:
539 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800540 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffine25c6442019-10-11 13:50:28 +0100541 } else if sm, ok := module.(*SystemModules); ok {
542 // A system modules dependency has been added to the bootclasspath
543 // so add its libs to the bootclasspath.
544 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700545 } else {
546 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
547 }
548 case libTag:
549 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800550 case SdkLibraryDependency:
551 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700552 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900553 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900554 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700555 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800556 checkProducesJars(ctx, dep)
557 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800558 default:
559 ctx.ModuleErrorf("depends on non-java module %q", otherName)
560 }
Colin Cross6cef4812019-10-17 14:23:50 -0700561 case java9LibTag:
562 switch dep := module.(type) {
563 case Dependency:
564 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
565 default:
566 ctx.ModuleErrorf("depends on non-java module %q", otherName)
567 }
Nan Zhang357466b2018-04-17 17:38:36 -0700568 case systemModulesTag:
569 if deps.systemModules != nil {
570 panic("Found two system module dependencies")
571 }
572 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000573 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700574 panic("Missing directory for system module dependency")
575 }
Colin Crossb77043e2019-07-16 13:57:13 -0700576 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800577 }
578 })
579 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
580 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800581 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900582
583 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
584 if filterPackages == nil {
585 return srcs
586 }
587 filtered := []android.Path{}
588 for _, src := range srcs {
589 if src.Ext() != ".java" {
590 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
591 // but otherwise metalava emits stub sources having references to the generated AIDL classes
592 // in filtered-out pacages (e.g. com.android.internal.*).
593 // TODO(b/141149570) We need to fix this by introducing default private constructors or
594 // fixing metalava to not emit constructors having references to unknown classes.
595 filtered = append(filtered, src)
596 continue
597 }
598 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
599 for _, pkg := range filterPackages {
600 if strings.HasPrefix(packageName, pkg) {
601 filtered = append(filtered, src)
602 break
603 }
604 }
605 }
606 return filtered
607 }
608 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
609
Nan Zhanga40da042018-08-01 12:48:00 -0700610 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900611 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800612
613 // srcs may depend on some genrule output.
614 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800615 j.srcJars = append(j.srcJars, deps.srcJars...)
616
Nan Zhang581fd212018-01-10 16:06:12 -0800617 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800618 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800619
Nan Zhang9c69a122018-08-22 10:22:08 -0700620 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800621 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
622 }
623 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800624
Colin Cross8a497952019-03-05 22:25:09 -0800625 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000626 argFilesMap := map[string]string{}
627 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700628
Paul Duffin99e4a502019-02-11 15:38:42 +0000629 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800630 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000631 if _, exists := argFilesMap[label]; !exists {
632 argFilesMap[label] = strings.Join(paths.Strings(), " ")
633 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 } else {
635 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000636 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700637 }
638 }
639
640 var err error
Colin Cross15638152019-07-11 11:11:35 -0700641 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700642 if strings.HasPrefix(name, "location ") {
643 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000644 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700645 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700646 } else {
Colin Cross15638152019-07-11 11:11:35 -0700647 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000648 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700649 }
650 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700651 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700652 }
Colin Cross15638152019-07-11 11:11:35 -0700653 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700654 })
655
656 if err != nil {
657 ctx.PropertyErrorf("args", "%s", err.Error())
658 }
659
Nan Zhang581fd212018-01-10 16:06:12 -0800660 return deps
661}
662
663func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
664 j.addDeps(ctx)
665}
666
667func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
668 deps := j.collectDeps(ctx)
669
Colin Crossdaa4c672019-07-15 22:53:46 -0700670 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800671
Colin Crossdaa4c672019-07-15 22:53:46 -0700672 outDir := android.PathForModuleOut(ctx, "out")
673 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
674
675 j.stubsSrcJar = nil
676
677 rule := android.NewRuleBuilder()
678
679 rule.Command().Text("rm -rf").Text(outDir.String())
680 rule.Command().Text("mkdir -p").Text(outDir.String())
681
682 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700683
Colin Cross83bb3162018-06-25 15:48:06 -0700684 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800685
Colin Crossdaa4c672019-07-15 22:53:46 -0700686 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
687 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800688
Colin Cross1e743852019-10-28 11:37:20 -0700689 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700690 Flag("-J-Xmx1024m").
691 Flag("-XDignore.symbol.file").
692 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800693
Colin Crossdaa4c672019-07-15 22:53:46 -0700694 rule.Command().
695 BuiltTool(ctx, "soong_zip").
696 Flag("-write_if_changed").
697 Flag("-d").
698 FlagWithOutput("-o ", j.docZip).
699 FlagWithArg("-C ", outDir.String()).
700 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700701
Colin Crossdaa4c672019-07-15 22:53:46 -0700702 rule.Restat()
703
704 zipSyncCleanupCmd(rule, srcJarDir)
705
706 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800707}
708
Nan Zhanga40da042018-08-01 12:48:00 -0700709//
710// Droiddoc
711//
712type Droiddoc struct {
713 Javadoc
714
715 properties DroiddocProperties
716 apiFile android.WritablePath
717 dexApiFile android.WritablePath
718 privateApiFile android.WritablePath
719 privateDexApiFile android.WritablePath
720 removedApiFile android.WritablePath
721 removedDexApiFile android.WritablePath
722 exactApiFile android.WritablePath
723 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700724 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700725
726 checkCurrentApiTimestamp android.WritablePath
727 updateCurrentApiTimestamp android.WritablePath
728 checkLastReleasedApiTimestamp android.WritablePath
729
Nan Zhanga40da042018-08-01 12:48:00 -0700730 apiFilePath android.Path
731}
732
Colin Crossa3002fc2019-07-08 16:48:04 -0700733// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700734func DroiddocFactory() android.Module {
735 module := &Droiddoc{}
736
737 module.AddProperties(&module.properties,
738 &module.Javadoc.properties)
739
740 InitDroiddocModule(module, android.HostAndDeviceSupported)
741 return module
742}
743
Colin Crossa3002fc2019-07-08 16:48:04 -0700744// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700745func DroiddocHostFactory() android.Module {
746 module := &Droiddoc{}
747
748 module.AddProperties(&module.properties,
749 &module.Javadoc.properties)
750
751 InitDroiddocModule(module, android.HostSupported)
752 return module
753}
754
755func (d *Droiddoc) ApiFilePath() android.Path {
756 return d.apiFilePath
757}
758
Nan Zhang581fd212018-01-10 16:06:12 -0800759func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
760 d.Javadoc.addDeps(ctx)
761
Inseob Kim38449af2019-02-28 14:24:05 +0900762 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
763 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
764 }
765
Nan Zhang79614d12018-04-19 18:03:39 -0700766 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800767 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
768 }
Nan Zhang581fd212018-01-10 16:06:12 -0800769}
770
Colin Crossab054432019-07-15 16:13:59 -0700771func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Nan Zhang443fa522018-08-20 20:58:28 -0700772 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
773 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
774 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700775 cmd.FlagWithArg("-source ", "1.8").
776 Flag("-J-Xmx1600m").
777 Flag("-J-XX:-OmitStackTraceInFastThrow").
778 Flag("-XDignore.symbol.file").
779 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
780 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
781 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
Elliott Hughes26bce342019-09-12 15:05:13 -0700782 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 -0700783
Nan Zhanga40da042018-08-01 12:48:00 -0700784 if String(d.properties.Custom_template) == "" {
785 // TODO: This is almost always droiddoc-templates-sdk
786 ctx.PropertyErrorf("custom_template", "must specify a template")
787 }
788
789 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700790 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700791 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700792 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000793 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700794 }
795 })
796
797 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700798 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
799 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
800 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700801 }
802
803 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700804 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
805 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
806 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700807 }
808
809 if len(d.properties.Html_dirs) > 2 {
810 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
811 }
812
Colin Cross8a497952019-03-05 22:25:09 -0800813 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700814 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700815
Colin Crossab054432019-07-15 16:13:59 -0700816 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700817
818 if String(d.properties.Proofread_file) != "" {
819 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700820 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700821 }
822
823 if String(d.properties.Todo_file) != "" {
824 // tricky part:
825 // we should not compute full path for todo_file through PathForModuleOut().
826 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700827 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
828 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700829 }
830
831 if String(d.properties.Resourcesdir) != "" {
832 // TODO: should we add files under resourcesDir to the implicits? It seems that
833 // resourcesDir is one sub dir of htmlDir
834 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700835 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700836 }
837
838 if String(d.properties.Resourcesoutdir) != "" {
839 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700840 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700841 }
Nan Zhanga40da042018-08-01 12:48:00 -0700842}
843
Colin Crossab054432019-07-15 16:13:59 -0700844func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200845 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
846 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700847 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700848
Nan Zhanga40da042018-08-01 12:48:00 -0700849 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700850 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700851 d.apiFilePath = d.apiFile
852 }
853
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200854 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
855 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700856 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700857 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700858 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700859 }
860
861 if String(d.properties.Private_api_filename) != "" {
862 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700863 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700864 }
865
866 if String(d.properties.Dex_api_filename) != "" {
867 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700868 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700869 }
870
871 if String(d.properties.Private_dex_api_filename) != "" {
872 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700873 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700874 }
875
876 if String(d.properties.Removed_dex_api_filename) != "" {
877 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700878 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700879 }
880
881 if String(d.properties.Exact_api_filename) != "" {
882 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700883 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700884 }
885
886 if String(d.properties.Dex_mapping_filename) != "" {
887 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700888 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700889 }
890
Nan Zhang66dc2362018-08-14 20:41:04 -0700891 if String(d.properties.Proguard_filename) != "" {
892 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700893 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700894 }
895
Nan Zhanga40da042018-08-01 12:48:00 -0700896 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700897 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700898 }
899
900 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700901 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
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 (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700906 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700907 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
908 rule.Command().Text("cp").
909 Input(staticDocIndexRedirect).
910 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700911 }
912
913 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700914 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
915 rule.Command().Text("cp").
916 Input(staticDocProperties).
917 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700918 }
Nan Zhanga40da042018-08-01 12:48:00 -0700919}
920
Colin Crossab054432019-07-15 16:13:59 -0700921func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700922 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700923
924 cmd := rule.Command().
925 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
926 Flag(config.JavacVmFlags).
927 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700928 FlagWithRspFileInputList("@", srcs).
929 FlagWithInput("@", srcJarList)
930
Colin Crossab054432019-07-15 16:13:59 -0700931 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
932 // based stubs generation.
933 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
934 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
935 // the correct package name base path.
936 if len(sourcepaths) > 0 {
937 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
938 } else {
939 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
940 }
941
942 cmd.FlagWithArg("-d ", outDir.String()).
943 Flag("-quiet")
944
945 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700946}
947
Colin Crossdaa4c672019-07-15 22:53:46 -0700948func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
949 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
950 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
951
952 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
953
954 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
955 cmd.Flag(flag).Implicits(deps)
956
957 cmd.FlagWithArg("--patch-module ", "java.base=.")
958
959 if len(classpath) > 0 {
960 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
961 }
962
963 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700964}
965
Colin Crossdaa4c672019-07-15 22:53:46 -0700966func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
967 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
968 sourcepaths android.Paths) *android.RuleBuilderCommand {
969
970 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
971
972 if len(bootclasspath) == 0 && ctx.Device() {
973 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
974 // ensure java does not fall back to the default bootclasspath.
975 cmd.FlagWithArg("-bootclasspath ", `""`)
976 } else if len(bootclasspath) > 0 {
977 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
978 }
979
980 if len(classpath) > 0 {
981 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
982 }
983
984 return cmd
985}
986
Colin Crossab054432019-07-15 16:13:59 -0700987func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
988 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700989
Colin Crossab054432019-07-15 16:13:59 -0700990 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
991 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
992
993 return rule.Command().
994 BuiltTool(ctx, "dokka").
995 Flag(config.JavacVmFlags).
996 Flag(srcJarDir.String()).
997 FlagWithInputList("-classpath ", dokkaClasspath, ":").
998 FlagWithArg("-format ", "dac").
999 FlagWithArg("-dacRoot ", "/reference/kotlin").
1000 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001}
1002
1003func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1004 deps := d.Javadoc.collectDeps(ctx)
1005
Colin Crossdaa4c672019-07-15 22:53:46 -07001006 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
1007 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1008
Nan Zhang1598a9e2018-09-04 17:14:32 -07001009 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1010 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1011 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1012 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1013
Colin Crossab054432019-07-15 16:13:59 -07001014 outDir := android.PathForModuleOut(ctx, "out")
1015 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1016 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001017
Colin Crossab054432019-07-15 16:13:59 -07001018 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001019
Colin Crossab054432019-07-15 16:13:59 -07001020 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1021 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001022
Colin Crossab054432019-07-15 16:13:59 -07001023 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1024
1025 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001026 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001027 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001028 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001029 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001030 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001031 }
1032
Colin Crossab054432019-07-15 16:13:59 -07001033 d.stubsFlags(ctx, cmd, stubsDir)
1034
1035 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1036
1037 var desc string
1038 if Bool(d.properties.Dokka_enabled) {
1039 desc = "dokka"
1040 } else {
1041 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1042
1043 for _, o := range d.Javadoc.properties.Out {
1044 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1045 }
1046
1047 d.postDoclavaCmds(ctx, rule)
1048 desc = "doclava"
1049 }
1050
1051 rule.Command().
1052 BuiltTool(ctx, "soong_zip").
1053 Flag("-write_if_changed").
1054 Flag("-d").
1055 FlagWithOutput("-o ", d.docZip).
1056 FlagWithArg("-C ", outDir.String()).
1057 FlagWithArg("-D ", outDir.String())
1058
1059 rule.Command().
1060 BuiltTool(ctx, "soong_zip").
1061 Flag("-write_if_changed").
1062 Flag("-jar").
1063 FlagWithOutput("-o ", d.stubsSrcJar).
1064 FlagWithArg("-C ", stubsDir.String()).
1065 FlagWithArg("-D ", stubsDir.String())
1066
1067 rule.Restat()
1068
1069 zipSyncCleanupCmd(rule, srcJarDir)
1070
1071 rule.Build(pctx, ctx, "javadoc", desc)
1072
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001073 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001074 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001075
1076 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1077 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001078
1079 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001080
1081 rule := android.NewRuleBuilder()
1082
1083 rule.Command().Text("( true")
1084
1085 rule.Command().
1086 BuiltTool(ctx, "apicheck").
1087 Flag("-JXmx1024m").
1088 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1089 OptionalFlag(d.properties.Check_api.Current.Args).
1090 Input(apiFile).
1091 Input(d.apiFile).
1092 Input(removedApiFile).
1093 Input(d.removedApiFile)
1094
1095 msg := fmt.Sprintf(`\n******************************\n`+
1096 `You have tried to change the API from what has been previously approved.\n\n`+
1097 `To make these errors go away, you have two choices:\n`+
1098 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1099 ` errors above.\n\n`+
1100 ` 2. You can update current.txt by executing the following command:\n`+
1101 ` make %s-update-current-api\n\n`+
1102 ` To submit the revised current.txt to the main Android repository,\n`+
1103 ` you will need approval.\n`+
1104 `******************************\n`, ctx.ModuleName())
1105
1106 rule.Command().
1107 Text("touch").Output(d.checkCurrentApiTimestamp).
1108 Text(") || (").
1109 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1110 Text("; exit 38").
1111 Text(")")
1112
1113 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001114
1115 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001116
1117 // update API rule
1118 rule = android.NewRuleBuilder()
1119
1120 rule.Command().Text("( true")
1121
1122 rule.Command().
1123 Text("cp").Flag("-f").
1124 Input(d.apiFile).Flag(apiFile.String())
1125
1126 rule.Command().
1127 Text("cp").Flag("-f").
1128 Input(d.removedApiFile).Flag(removedApiFile.String())
1129
1130 msg = "failed to update public API"
1131
1132 rule.Command().
1133 Text("touch").Output(d.updateCurrentApiTimestamp).
1134 Text(") || (").
1135 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1136 Text("; exit 38").
1137 Text(")")
1138
1139 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001140 }
1141
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001142 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001143 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001144
1145 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1146 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001147
1148 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001149
1150 rule := android.NewRuleBuilder()
1151
1152 rule.Command().
1153 Text("(").
1154 BuiltTool(ctx, "apicheck").
1155 Flag("-JXmx1024m").
1156 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1157 OptionalFlag(d.properties.Check_api.Last_released.Args).
1158 Input(apiFile).
1159 Input(d.apiFile).
1160 Input(removedApiFile).
1161 Input(d.removedApiFile)
1162
1163 msg := `\n******************************\n` +
1164 `You have tried to change the API from what has been previously released in\n` +
1165 `an SDK. Please fix the errors listed above.\n` +
1166 `******************************\n`
1167
1168 rule.Command().
1169 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1170 Text(") || (").
1171 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1172 Text("; exit 38").
1173 Text(")")
1174
1175 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001176 }
1177}
1178
1179//
1180// Droidstubs
1181//
1182type Droidstubs struct {
1183 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001184 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001185
Pete Gillin581d6082018-10-22 15:55:04 +01001186 properties DroidstubsProperties
1187 apiFile android.WritablePath
1188 apiXmlFile android.WritablePath
1189 lastReleasedApiXmlFile android.WritablePath
1190 dexApiFile android.WritablePath
1191 privateApiFile android.WritablePath
1192 privateDexApiFile android.WritablePath
1193 removedApiFile android.WritablePath
1194 removedDexApiFile android.WritablePath
1195 apiMappingFile android.WritablePath
1196 exactApiFile android.WritablePath
1197 proguardFile android.WritablePath
1198 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001199
1200 checkCurrentApiTimestamp android.WritablePath
1201 updateCurrentApiTimestamp android.WritablePath
1202 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001203 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001204 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001205
Pete Gillin581d6082018-10-22 15:55:04 +01001206 checkNullabilityWarningsTimestamp android.WritablePath
1207
Nan Zhang1598a9e2018-09-04 17:14:32 -07001208 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001209 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001210
1211 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001212
1213 jdiffDocZip android.WritablePath
1214 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001215
1216 metadataZip android.WritablePath
1217 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001218}
1219
Colin Crossa3002fc2019-07-08 16:48:04 -07001220// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1221// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1222// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001223func DroidstubsFactory() android.Module {
1224 module := &Droidstubs{}
1225
1226 module.AddProperties(&module.properties,
1227 &module.Javadoc.properties)
1228
1229 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001230 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001231 return module
1232}
1233
Colin Crossa3002fc2019-07-08 16:48:04 -07001234// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1235// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1236// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1237// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001238func DroidstubsHostFactory() android.Module {
1239 module := &Droidstubs{}
1240
1241 module.AddProperties(&module.properties,
1242 &module.Javadoc.properties)
1243
1244 InitDroiddocModule(module, android.HostSupported)
1245 return module
1246}
1247
1248func (d *Droidstubs) ApiFilePath() android.Path {
1249 return d.apiFilePath
1250}
1251
1252func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1253 d.Javadoc.addDeps(ctx)
1254
Inseob Kim38449af2019-02-28 14:24:05 +09001255 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1256 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1257 }
1258
Nan Zhang1598a9e2018-09-04 17:14:32 -07001259 if len(d.properties.Merge_annotations_dirs) != 0 {
1260 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1261 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1262 }
1263 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001264
Pete Gillin77167902018-09-19 18:16:26 +01001265 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1266 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1267 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1268 }
1269 }
1270
Nan Zhang9c69a122018-08-22 10:22:08 -07001271 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1272 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1273 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1274 }
1275 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001276}
1277
Colin Cross33961b52019-07-11 11:01:22 -07001278func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001279 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1280 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001281 String(d.properties.Api_filename) != "" {
1282 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001283 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001284 d.apiFilePath = d.apiFile
1285 }
1286
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001287 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1288 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001289 String(d.properties.Removed_api_filename) != "" {
1290 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001291 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001292 }
1293
1294 if String(d.properties.Private_api_filename) != "" {
1295 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001296 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001297 }
1298
1299 if String(d.properties.Dex_api_filename) != "" {
1300 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001301 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001302 }
1303
1304 if String(d.properties.Private_dex_api_filename) != "" {
1305 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001306 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001307 }
1308
1309 if String(d.properties.Removed_dex_api_filename) != "" {
1310 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001311 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001312 }
1313
1314 if String(d.properties.Exact_api_filename) != "" {
1315 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001316 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001317 }
1318
Nan Zhang9c69a122018-08-22 10:22:08 -07001319 if String(d.properties.Dex_mapping_filename) != "" {
1320 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001321 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001322 }
1323
Nan Zhang199645c2018-09-19 12:40:06 -07001324 if String(d.properties.Proguard_filename) != "" {
1325 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001326 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001327 }
1328
Nan Zhang9c69a122018-08-22 10:22:08 -07001329 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001330 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1331 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001332 }
1333
Nan Zhang1598a9e2018-09-04 17:14:32 -07001334 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001335 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001336 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001337 cmd.FlagWithArg("--stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001338 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001339}
1340
Colin Cross33961b52019-07-11 11:01:22 -07001341func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001342 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001343 cmd.Flag("--include-annotations")
1344
Pete Gillinc382a562018-11-14 18:45:46 +00001345 validatingNullability :=
1346 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1347 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001348
Pete Gillina262c052018-09-14 14:25:48 +01001349 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001350 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001351 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001352 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001353 }
Colin Cross33961b52019-07-11 11:01:22 -07001354
Pete Gillinc382a562018-11-14 18:45:46 +00001355 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001356 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001357 }
Colin Cross33961b52019-07-11 11:01:22 -07001358
Pete Gillina262c052018-09-14 14:25:48 +01001359 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001360 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001361 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001362 }
Nan Zhanga40da042018-08-01 12:48:00 -07001363
1364 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001365 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001366
Nan Zhang1598a9e2018-09-04 17:14:32 -07001367 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001368 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001369 "has to be non-empty if annotations was enabled!")
1370 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001371
Colin Cross33961b52019-07-11 11:01:22 -07001372 d.mergeAnnoDirFlags(ctx, cmd)
1373
1374 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1375 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1376 FlagWithArg("--hide ", "SuperfluousPrefix").
1377 FlagWithArg("--hide ", "AnnotationExtraction")
1378 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001379}
1380
Colin Cross33961b52019-07-11 11:01:22 -07001381func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1382 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1383 if t, ok := m.(*ExportedDroiddocDir); ok {
1384 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1385 } else {
1386 ctx.PropertyErrorf("merge_annotations_dirs",
1387 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1388 }
1389 })
1390}
1391
1392func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001393 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1394 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001395 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001396 } else {
1397 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1398 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1399 }
1400 })
Nan Zhanga40da042018-08-01 12:48:00 -07001401}
1402
Colin Cross33961b52019-07-11 11:01:22 -07001403func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001404 if Bool(d.properties.Api_levels_annotations_enabled) {
1405 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001406
1407 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1408 ctx.PropertyErrorf("api_levels_annotations_dirs",
1409 "has to be non-empty if api levels annotations was enabled!")
1410 }
1411
Colin Cross33961b52019-07-11 11:01:22 -07001412 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1413 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1414 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1415 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001416
1417 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1418 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001419 for _, dep := range t.deps {
1420 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001421 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001422 }
1423 }
Colin Cross33961b52019-07-11 11:01:22 -07001424 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001425 } else {
1426 ctx.PropertyErrorf("api_levels_annotations_dirs",
1427 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1428 }
1429 })
1430
1431 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001432}
1433
Colin Cross33961b52019-07-11 11:01:22 -07001434func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001435 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1436 if d.apiFile.String() == "" {
1437 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1438 }
1439
1440 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001441 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001442
1443 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1444 ctx.PropertyErrorf("check_api.last_released.api_file",
1445 "has to be non-empty if jdiff was enabled!")
1446 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001447
Colin Cross33961b52019-07-11 11:01:22 -07001448 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001449 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001450 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1451 }
1452}
Nan Zhang71bbe632018-09-17 14:32:21 -07001453
Colin Cross1e743852019-10-28 11:37:20 -07001454func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001455 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
1456 cmd := rule.Command().BuiltTool(ctx, "metalava").
1457 Flag(config.JavacVmFlags).
1458 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001459 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001460 FlagWithRspFileInputList("@", srcs).
1461 FlagWithInput("@", srcJarList)
1462
1463 if len(bootclasspath) > 0 {
1464 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001465 }
1466
Colin Cross33961b52019-07-11 11:01:22 -07001467 if len(classpath) > 0 {
1468 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1469 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001470
Colin Cross33961b52019-07-11 11:01:22 -07001471 if len(sourcepaths) > 0 {
1472 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1473 } else {
1474 cmd.FlagWithArg("-sourcepath ", `""`)
1475 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001476
Colin Cross33961b52019-07-11 11:01:22 -07001477 cmd.Flag("--no-banner").
1478 Flag("--color").
1479 Flag("--quiet").
1480 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001481
Colin Cross33961b52019-07-11 11:01:22 -07001482 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001483}
1484
Nan Zhang1598a9e2018-09-04 17:14:32 -07001485func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001486 deps := d.Javadoc.collectDeps(ctx)
1487
1488 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001489
Colin Cross33961b52019-07-11 11:01:22 -07001490 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001491
Colin Crossdaa4c672019-07-15 22:53:46 -07001492 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001493
Colin Cross33961b52019-07-11 11:01:22 -07001494 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1495 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001496
Colin Cross33961b52019-07-11 11:01:22 -07001497 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001498
Colin Cross33961b52019-07-11 11:01:22 -07001499 rule.Command().Text("rm -rf").Text(stubsDir.String())
1500 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001501
Colin Cross33961b52019-07-11 11:01:22 -07001502 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1503
1504 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1505 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1506
1507 d.stubsFlags(ctx, cmd, stubsDir)
1508
1509 d.annotationsFlags(ctx, cmd)
1510 d.inclusionAnnotationsFlags(ctx, cmd)
1511 d.apiLevelsAnnotationsFlags(ctx, cmd)
1512 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001513
Nan Zhang1598a9e2018-09-04 17:14:32 -07001514 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1515 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1516 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1517 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1518 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001519 }
Colin Cross33961b52019-07-11 11:01:22 -07001520
1521 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1522 for _, o := range d.Javadoc.properties.Out {
1523 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1524 }
1525
1526 rule.Command().
1527 BuiltTool(ctx, "soong_zip").
1528 Flag("-write_if_changed").
1529 Flag("-jar").
1530 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1531 FlagWithArg("-C ", stubsDir.String()).
1532 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001533
1534 if Bool(d.properties.Write_sdk_values) {
1535 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1536 rule.Command().
1537 BuiltTool(ctx, "soong_zip").
1538 Flag("-write_if_changed").
1539 Flag("-d").
1540 FlagWithOutput("-o ", d.metadataZip).
1541 FlagWithArg("-C ", d.metadataDir.String()).
1542 FlagWithArg("-D ", d.metadataDir.String())
1543 }
1544
Colin Cross33961b52019-07-11 11:01:22 -07001545 rule.Restat()
1546
1547 zipSyncCleanupCmd(rule, srcJarDir)
1548
1549 rule.Build(pctx, ctx, "metalava", "metalava")
1550
1551 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001552
Adrian Roos075eedc2019-10-10 12:07:03 +02001553 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1554 rule := android.NewRuleBuilder()
1555 rule.Command().Text("( true")
1556
1557 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1558 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1559
1560 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1561 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1562
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001563 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1564
Adrian Roos075eedc2019-10-10 12:07:03 +02001565 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1566 if newSince.Valid() {
1567 cmd.FlagWithInput("--api-lint ", newSince.Path())
1568 } else {
1569 cmd.Flag("--api-lint")
1570 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001571 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1572 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001573
1574 d.inclusionAnnotationsFlags(ctx, cmd)
1575 d.mergeAnnoDirFlags(ctx, cmd)
1576
1577 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1578 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1579 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1580
1581 if baselineFile.Valid() {
1582 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1583 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1584 }
1585
1586 zipSyncCleanupCmd(rule, srcJarDir)
1587
1588 msg := fmt.Sprintf(`\n******************************\n`+
1589 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1590 `To make these errors go away, you have two choices:\n`+
1591 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1592 ` 2. You can update the baseline by executing the following command:\n`+
1593 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1594 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1595 rule.Command().
1596 Text("touch").Output(d.apiLintTimestamp).
1597 Text(") || (").
1598 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1599 Text("; exit 38").
1600 Text(")")
1601
1602 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1603
1604 }
1605
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001606 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001607 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001608
1609 if len(d.Javadoc.properties.Out) > 0 {
1610 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1611 }
1612
1613 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1614 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001615 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1616 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001617
Nan Zhang2760dfc2018-08-24 17:32:54 +00001618 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001619
Colin Cross33961b52019-07-11 11:01:22 -07001620 rule := android.NewRuleBuilder()
1621
1622 rule.Command().Text("( true")
1623
1624 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1625 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1626
1627 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1628 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1629
1630 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1631 FlagWithInput("--check-compatibility:api:current ", apiFile).
1632 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1633
1634 d.inclusionAnnotationsFlags(ctx, cmd)
1635 d.mergeAnnoDirFlags(ctx, cmd)
1636
Adrian Roos14f75a92019-08-12 17:54:09 +02001637 if baselineFile.Valid() {
1638 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1639 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1640 }
1641
Colin Cross33961b52019-07-11 11:01:22 -07001642 zipSyncCleanupCmd(rule, srcJarDir)
1643
1644 msg := fmt.Sprintf(`\n******************************\n`+
1645 `You have tried to change the API from what has been previously approved.\n\n`+
1646 `To make these errors go away, you have two choices:\n`+
1647 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1648 ` errors above.\n\n`+
1649 ` 2. You can update current.txt by executing the following command:\n`+
1650 ` make %s-update-current-api\n\n`+
1651 ` To submit the revised current.txt to the main Android repository,\n`+
1652 ` you will need approval.\n`+
1653 `******************************\n`, ctx.ModuleName())
1654
1655 rule.Command().
1656 Text("touch").Output(d.checkCurrentApiTimestamp).
1657 Text(") || (").
1658 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1659 Text("; exit 38").
1660 Text(")")
1661
1662 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001663
1664 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001665
1666 // update API rule
1667 rule = android.NewRuleBuilder()
1668
1669 rule.Command().Text("( true")
1670
1671 rule.Command().
1672 Text("cp").Flag("-f").
1673 Input(d.apiFile).Flag(apiFile.String())
1674
1675 rule.Command().
1676 Text("cp").Flag("-f").
1677 Input(d.removedApiFile).Flag(removedApiFile.String())
1678
1679 msg = "failed to update public API"
1680
1681 rule.Command().
1682 Text("touch").Output(d.updateCurrentApiTimestamp).
1683 Text(") || (").
1684 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1685 Text("; exit 38").
1686 Text(")")
1687
1688 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001689 }
Nan Zhanga40da042018-08-01 12:48:00 -07001690
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001691 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001692 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001693
1694 if len(d.Javadoc.properties.Out) > 0 {
1695 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1696 }
1697
1698 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1699 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001700 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1701 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001702
Nan Zhang2760dfc2018-08-24 17:32:54 +00001703 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001704
Colin Cross33961b52019-07-11 11:01:22 -07001705 rule := android.NewRuleBuilder()
1706
1707 rule.Command().Text("( true")
1708
1709 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1710 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1711
1712 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1713 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1714
1715 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1716 FlagWithInput("--check-compatibility:api:released ", apiFile)
1717
1718 d.inclusionAnnotationsFlags(ctx, cmd)
1719
1720 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1721
1722 d.mergeAnnoDirFlags(ctx, cmd)
1723
Adrian Roos14f75a92019-08-12 17:54:09 +02001724 if baselineFile.Valid() {
1725 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1726 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1727 }
1728
Colin Cross33961b52019-07-11 11:01:22 -07001729 zipSyncCleanupCmd(rule, srcJarDir)
1730
1731 msg := `\n******************************\n` +
1732 `You have tried to change the API from what has been previously released in\n` +
1733 `an SDK. Please fix the errors listed above.\n` +
1734 `******************************\n`
1735 rule.Command().
1736 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1737 Text(") || (").
1738 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1739 Text("; exit 38").
1740 Text(")")
1741
1742 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001743 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001744
Pete Gillin581d6082018-10-22 15:55:04 +01001745 if String(d.properties.Check_nullability_warnings) != "" {
1746 if d.nullabilityWarningsFile == nil {
1747 ctx.PropertyErrorf("check_nullability_warnings",
1748 "Cannot specify check_nullability_warnings unless validating nullability")
1749 }
Colin Cross33961b52019-07-11 11:01:22 -07001750
1751 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1752
Pete Gillin581d6082018-10-22 15:55:04 +01001753 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001754
Pete Gillin581d6082018-10-22 15:55:04 +01001755 msg := fmt.Sprintf(`\n******************************\n`+
1756 `The warnings encountered during nullability annotation validation did\n`+
1757 `not match the checked in file of expected warnings. The diffs are shown\n`+
1758 `above. You have two options:\n`+
1759 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1760 ` 2. Update the file of expected warnings by running:\n`+
1761 ` cp %s %s\n`+
1762 ` and submitting the updated file as part of your change.`,
1763 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001764
1765 rule := android.NewRuleBuilder()
1766
1767 rule.Command().
1768 Text("(").
1769 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1770 Text("&&").
1771 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1772 Text(") || (").
1773 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1774 Text("; exit 38").
1775 Text(")")
1776
1777 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001778 }
1779
Nan Zhang71bbe632018-09-17 14:32:21 -07001780 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001781 if len(d.Javadoc.properties.Out) > 0 {
1782 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1783 }
1784
1785 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1786 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1787 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1788
1789 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001790
Nan Zhang86b06202018-09-21 17:09:21 -07001791 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1792 // since there's cron job downstream that fetch this .zip file periodically.
1793 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001794 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1795 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1796
Nan Zhang71bbe632018-09-17 14:32:21 -07001797 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001798
Colin Cross33961b52019-07-11 11:01:22 -07001799 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1800 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001801
Colin Cross33961b52019-07-11 11:01:22 -07001802 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1803
Colin Crossdaa4c672019-07-15 22:53:46 -07001804 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001805 deps.bootClasspath, deps.classpath, d.sourcepaths)
1806
1807 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001808 Flag("-XDignore.symbol.file").
1809 FlagWithArg("-doclet ", "jdiff.JDiff").
1810 FlagWithInput("-docletpath ", jdiff).
1811 Flag("-quiet").
1812 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1813 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1814 Implicit(d.apiXmlFile).
1815 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1816 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1817 Implicit(d.lastReleasedApiXmlFile)
1818
Colin Cross33961b52019-07-11 11:01:22 -07001819 rule.Command().
1820 BuiltTool(ctx, "soong_zip").
1821 Flag("-write_if_changed").
1822 Flag("-d").
1823 FlagWithOutput("-o ", d.jdiffDocZip).
1824 FlagWithArg("-C ", outDir.String()).
1825 FlagWithArg("-D ", outDir.String())
1826
1827 rule.Command().
1828 BuiltTool(ctx, "soong_zip").
1829 Flag("-write_if_changed").
1830 Flag("-jar").
1831 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1832 FlagWithArg("-C ", stubsDir.String()).
1833 FlagWithArg("-D ", stubsDir.String())
1834
1835 rule.Restat()
1836
1837 zipSyncCleanupCmd(rule, srcJarDir)
1838
1839 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001840 }
Nan Zhang581fd212018-01-10 16:06:12 -08001841}
Dan Willemsencc090972018-02-26 14:33:31 -08001842
Nan Zhanga40da042018-08-01 12:48:00 -07001843//
Nan Zhangf4936b02018-08-01 15:00:28 -07001844// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001845//
Dan Willemsencc090972018-02-26 14:33:31 -08001846var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001847var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001848var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001849var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001850
Nan Zhangf4936b02018-08-01 15:00:28 -07001851type ExportedDroiddocDirProperties struct {
1852 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001853 Path *string
1854}
1855
Nan Zhangf4936b02018-08-01 15:00:28 -07001856type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001857 android.ModuleBase
1858
Nan Zhangf4936b02018-08-01 15:00:28 -07001859 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001860
1861 deps android.Paths
1862 dir android.Path
1863}
1864
Colin Crossa3002fc2019-07-08 16:48:04 -07001865// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001866func ExportedDroiddocDirFactory() android.Module {
1867 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001868 module.AddProperties(&module.properties)
1869 android.InitAndroidModule(module)
1870 return module
1871}
1872
Nan Zhangf4936b02018-08-01 15:00:28 -07001873func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001874
Nan Zhangf4936b02018-08-01 15:00:28 -07001875func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001876 path := String(d.properties.Path)
1877 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001878 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001879}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001880
1881//
1882// Defaults
1883//
1884type DocDefaults struct {
1885 android.ModuleBase
1886 android.DefaultsModuleBase
1887}
1888
Nan Zhangb2b33de2018-02-23 11:18:47 -08001889func DocDefaultsFactory() android.Module {
1890 module := &DocDefaults{}
1891
1892 module.AddProperties(
1893 &JavadocProperties{},
1894 &DroiddocProperties{},
1895 )
1896
1897 android.InitDefaultsModule(module)
1898
1899 return module
1900}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001901
1902func StubsDefaultsFactory() android.Module {
1903 module := &DocDefaults{}
1904
1905 module.AddProperties(
1906 &JavadocProperties{},
1907 &DroidstubsProperties{},
1908 )
1909
1910 android.InitDefaultsModule(module)
1911
1912 return module
1913}
Colin Cross33961b52019-07-11 11:01:22 -07001914
1915func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1916 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1917
1918 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1919 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1920 srcJarList := srcJarDir.Join(ctx, "list")
1921
1922 rule.Temporary(srcJarList)
1923
1924 rule.Command().BuiltTool(ctx, "zipsync").
1925 FlagWithArg("-d ", srcJarDir.String()).
1926 FlagWithOutput("-l ", srcJarList).
1927 FlagWithArg("-f ", `"*.java"`).
1928 Inputs(srcJars)
1929
1930 return srcJarList
1931}
1932
1933func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1934 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1935}
Paul Duffin91547182019-11-12 19:39:36 +00001936
1937var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1938
1939type PrebuiltStubsSourcesProperties struct {
1940 Srcs []string `android:"path"`
1941}
1942
1943type PrebuiltStubsSources struct {
1944 android.ModuleBase
1945 android.DefaultableModuleBase
1946 prebuilt android.Prebuilt
1947 android.SdkBase
1948
1949 properties PrebuiltStubsSourcesProperties
1950
1951 srcs android.Paths
1952 stubsSrcJar android.ModuleOutPath
1953}
1954
1955func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1956 p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1957}
1958
1959func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1960 return &p.prebuilt
1961}
1962
1963func (p *PrebuiltStubsSources) Name() string {
1964 return p.prebuilt.Name(p.ModuleBase.Name())
1965}
1966
1967func (p *PrebuiltStubsSources) Srcs() android.Paths {
1968 return append(android.Paths{}, p.srcs...)
1969}
1970
1971// prebuilt_stubs_sources imports a set of java source files as if they were
1972// generated by droidstubs.
1973//
1974// By default, a prebuilt_stubs_sources has a single variant that expects a
1975// set of `.java` files generated by droidstubs.
1976//
1977// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1978// for host modules.
1979//
1980// Intended only for use by sdk snapshots.
1981func PrebuiltStubsSourcesFactory() android.Module {
1982 module := &PrebuiltStubsSources{}
1983
1984 module.AddProperties(&module.properties)
1985
1986 android.InitPrebuiltModule(module, &module.properties.Srcs)
1987 android.InitSdkAwareModule(module)
1988 InitDroiddocModule(module, android.HostAndDeviceSupported)
1989 return module
1990}
1991
Paul Duffin13879572019-11-28 14:31:38 +00001992type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001993 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001994}
1995
1996func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1997 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1998}
1999
2000func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
2001 _, ok := module.(*Droidstubs)
2002 return ok
2003}
2004
2005func (mt *droidStubsSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
2006 variants := member.Variants()
2007 if len(variants) != 1 {
2008 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2009 }
2010 variant := variants[0]
2011 d, _ := variant.(*Droidstubs)
Paul Duffin91547182019-11-12 19:39:36 +00002012 stubsSrcJar := d.stubsSrcJar
2013
2014 snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
2015 builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
2016
Paul Duffin9d8d6092019-12-05 18:19:29 +00002017 pbm := builder.AddPrebuiltModule(member, "prebuilt_stubs_sources")
Paul Duffinb645ec82019-11-27 17:43:54 +00002018 pbm.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin91547182019-11-12 19:39:36 +00002019}