blob: 92f92465b4647b7299b2c8354dde5175d200da11 [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() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080030 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -070031 android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
Nan Zhangb2b33de2018-02-23 11:18:47 -080032
Nan Zhang581fd212018-01-10 16:06:12 -080033 android.RegisterModuleType("droiddoc", DroiddocFactory)
34 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -070035 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080036 android.RegisterModuleType("javadoc", JavadocFactory)
37 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
Nan Zhang1598a9e2018-09-04 17:14:32 -070038
39 android.RegisterModuleType("droidstubs", DroidstubsFactory)
40 android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
Paul Duffin91547182019-11-12 19:39:36 +000041
42 android.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
Paul Duffin255f18e2019-12-13 11:22:16 +000043
44 // Register sdk member type.
45 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
46 SdkMemberTypeBase: android.SdkMemberTypeBase{
47 PropertyName: "stubs_sources",
48 },
49 })
Nan Zhang581fd212018-01-10 16:06:12 -080050}
51
Colin Crossa1ce2a02018-06-20 15:19:39 -070052var (
53 srcsLibTag = dependencyTag{name: "sources from javalib"}
54)
55
Nan Zhang581fd212018-01-10 16:06:12 -080056type JavadocProperties struct {
57 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
58 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080059 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080060
61 // list of directories rooted at the Android.bp file that will
62 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080063 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080064
65 // list of source files that should not be used to build the Java module.
66 // This is most useful in the arch/multilib variants to remove non-common files
67 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080068 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080069
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090070 // list of package names that should actually be used. If this property is left unspecified,
71 // all the sources from the srcs property is used.
72 Filter_packages []string
73
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080075 Libs []string `android:"arch_variant"`
76
77 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080078 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080079
Paul Duffine25c6442019-10-11 13:50:28 +010080 // if not blank, set to the version of the sdk to compile against.
81 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080082 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090083
Paul Duffine25c6442019-10-11 13:50:28 +010084 // When targeting 1.9 and above, override the modules to use with --system,
85 // otherwise provides defaults libraries to add to the bootclasspath.
86 // Defaults to "none"
87 System_modules *string
88
Jiyong Park1e440682018-05-23 18:42:04 +090089 Aidl struct {
90 // Top level directories to pass to aidl tool
91 Include_dirs []string
92
93 // Directories rooted at the Android.bp file to pass to aidl tool
94 Local_include_dirs []string
95 }
Nan Zhang357466b2018-04-17 17:38:36 -070096
97 // If not blank, set the java version passed to javadoc as -source
98 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -070099
100 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800101 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700102
103 // user customized droiddoc args.
104 // Available variables for substitution:
105 //
106 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700107 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700108 Args *string
109
110 // names of the output files used in args that will be generated
111 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800112}
113
Nan Zhang61819ce2018-05-04 18:49:16 -0700114type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900115 // path to the API txt file that the new API extracted from source code is checked
116 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800117 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700118
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900119 // path to the API txt file that the new @removed API extractd from source code is
120 // checked against. The path can be local to the module or from other module (via
121 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800122 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700123
Adrian Roos14f75a92019-08-12 17:54:09 +0200124 // If not blank, path to the baseline txt file for approved API check violations.
125 Baseline_file *string `android:"path"`
126
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900127 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700128 Args *string
129}
130
Nan Zhang581fd212018-01-10 16:06:12 -0800131type DroiddocProperties struct {
132 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800133 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800134
Nan Zhanga40da042018-08-01 12:48:00 -0700135 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800136 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800137
138 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800139 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800140
141 // proofread file contains all of the text content of the javadocs concatenated into one file,
142 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700143 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800144
145 // a todo file lists the program elements that are missing documentation.
146 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800147 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800148
149 // directory under current module source that provide additional resources (images).
150 Resourcesdir *string
151
152 // resources output directory under out/soong/.intermediates.
153 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800154
Nan Zhange2ba5d42018-07-11 15:16:55 -0700155 // if set to true, collect the values used by the Dev tools and
156 // write them in files packaged with the SDK. Defaults to false.
157 Write_sdk_values *bool
158
159 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800160 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700161
162 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800163 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700164
Nan Zhang581fd212018-01-10 16:06:12 -0800165 // a list of files under current module source dir which contains known tags in Java sources.
166 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800167 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700168
169 // the tag name used to distinguish if the API files belong to public/system/test.
170 Api_tag_name *string
171
172 // the generated public API filename by Doclava.
173 Api_filename *string
174
David Brazdilfbe4cc32018-05-31 13:56:46 +0100175 // the generated public Dex API filename by Doclava.
176 Dex_api_filename *string
177
Nan Zhang28c68b92018-03-13 16:17:01 -0700178 // the generated private API filename by Doclava.
179 Private_api_filename *string
180
181 // the generated private Dex API filename by Doclava.
182 Private_dex_api_filename *string
183
184 // the generated removed API filename by Doclava.
185 Removed_api_filename *string
186
David Brazdilaac0c3c2018-04-24 16:23:29 +0100187 // the generated removed Dex API filename by Doclava.
188 Removed_dex_api_filename *string
189
Mathew Inwood76c3de12018-06-22 15:28:11 +0100190 // mapping of dex signatures to source file and line number. This is a temporary property and
191 // will be deleted; you probably shouldn't be using it.
192 Dex_mapping_filename *string
193
Nan Zhang28c68b92018-03-13 16:17:01 -0700194 // the generated exact API filename by Doclava.
195 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700196
Nan Zhang66dc2362018-08-14 20:41:04 -0700197 // the generated proguard filename by Doclava.
198 Proguard_filename *string
199
Nan Zhang853f4202018-04-12 16:55:56 -0700200 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
201 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700202
203 Check_api struct {
204 Last_released ApiToCheck
205
206 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900207
208 // do not perform API check against Last_released, in the case that both two specified API
209 // files by Last_released are modules which don't exist.
210 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700211 }
Nan Zhang79614d12018-04-19 18:03:39 -0700212
Nan Zhang1598a9e2018-09-04 17:14:32 -0700213 // if set to true, generate docs through Dokka instead of Doclava.
214 Dokka_enabled *bool
215}
216
217type DroidstubsProperties struct {
218 // the tag name used to distinguish if the API files belong to public/system/test.
219 Api_tag_name *string
220
Nan Zhang199645c2018-09-19 12:40:06 -0700221 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700222 Api_filename *string
223
Nan Zhang199645c2018-09-19 12:40:06 -0700224 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700225 Dex_api_filename *string
226
Nan Zhang199645c2018-09-19 12:40:06 -0700227 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700228 Private_api_filename *string
229
Nan Zhang199645c2018-09-19 12:40:06 -0700230 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700231 Private_dex_api_filename *string
232
Nan Zhang199645c2018-09-19 12:40:06 -0700233 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700234 Removed_api_filename *string
235
Nan Zhang199645c2018-09-19 12:40:06 -0700236 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700237 Removed_dex_api_filename *string
238
Nan Zhang9c69a122018-08-22 10:22:08 -0700239 // mapping of dex signatures to source file and line number. This is a temporary property and
240 // will be deleted; you probably shouldn't be using it.
241 Dex_mapping_filename *string
242
Nan Zhang199645c2018-09-19 12:40:06 -0700243 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700244 Exact_api_filename *string
245
Nan Zhang199645c2018-09-19 12:40:06 -0700246 // the generated proguard filename by Metalava.
247 Proguard_filename *string
248
Nan Zhang1598a9e2018-09-04 17:14:32 -0700249 Check_api struct {
250 Last_released ApiToCheck
251
252 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900253
254 // do not perform API check against Last_released, in the case that both two specified API
255 // files by Last_released are modules which don't exist.
256 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200257
258 Api_lint struct {
259 Enabled *bool
260
261 // If set, performs api_lint on any new APIs not found in the given signature file
262 New_since *string `android:"path"`
263
264 // If not blank, path to the baseline txt file for approved API lint violations.
265 Baseline_file *string `android:"path"`
266 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700267 }
Nan Zhang79614d12018-04-19 18:03:39 -0700268
269 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800270 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700271
272 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700273 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700274
Pete Gillin77167902018-09-19 18:16:26 +0100275 // 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 -0700276 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700277
Pete Gillin77167902018-09-19 18:16:26 +0100278 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
279 Merge_inclusion_annotations_dirs []string
280
Pete Gillinc382a562018-11-14 18:45:46 +0000281 // a file containing a list of classes to do nullability validation for.
282 Validate_nullability_from_list *string
283
Pete Gillin581d6082018-10-22 15:55:04 +0100284 // a file containing expected warnings produced by validation of nullability annotations.
285 Check_nullability_warnings *string
286
Nan Zhang1598a9e2018-09-04 17:14:32 -0700287 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
288 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700289
290 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
291 Api_levels_annotations_enabled *bool
292
293 // the dirs which Metalava extracts API levels annotations from.
294 Api_levels_annotations_dirs []string
295
296 // if set to true, collect the values used by the Dev tools and
297 // write them in files packaged with the SDK. Defaults to false.
298 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700299
300 // If set to true, .xml based public API file will be also generated, and
301 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
302 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800303}
304
Nan Zhanga40da042018-08-01 12:48:00 -0700305//
306// Common flags passed down to build rule
307//
308type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700309 bootClasspathArgs string
310 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700311 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700312 dokkaClasspathArgs string
313 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700314 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700315
Nan Zhanga40da042018-08-01 12:48:00 -0700316 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700317 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700318 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700319}
320
321func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
322 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
323 android.InitDefaultableModule(module)
324}
325
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200326func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
327 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
328 return false
329 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700330 return true
331 } else if String(apiToCheck.Api_file) != "" {
332 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
333 } else if String(apiToCheck.Removed_api_file) != "" {
334 panic("for " + apiVersionTag + " api_file has to be non-empty!")
335 }
336
337 return false
338}
339
Inseob Kim38449af2019-02-28 14:24:05 +0900340func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
341 api_file := String(apiToCheck.Api_file)
342 removed_api_file := String(apiToCheck.Removed_api_file)
343
344 api_module := android.SrcIsModule(api_file)
345 removed_api_module := android.SrcIsModule(removed_api_file)
346
347 if api_module == "" || removed_api_module == "" {
348 return
349 }
350
351 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
352 return
353 }
354
355 apiToCheck.Api_file = nil
356 apiToCheck.Removed_api_file = nil
357}
358
Nan Zhang1598a9e2018-09-04 17:14:32 -0700359type ApiFilePath interface {
360 ApiFilePath() android.Path
361}
362
Nan Zhanga40da042018-08-01 12:48:00 -0700363//
364// Javadoc
365//
Nan Zhang581fd212018-01-10 16:06:12 -0800366type Javadoc struct {
367 android.ModuleBase
368 android.DefaultableModuleBase
369
370 properties JavadocProperties
371
372 srcJars android.Paths
373 srcFiles android.Paths
374 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700375 argFiles android.Paths
376
377 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800378
Nan Zhangccff0f72018-03-08 17:26:16 -0800379 docZip android.WritablePath
380 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800381}
382
Colin Cross41955e82019-05-29 14:40:35 -0700383func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
384 switch tag {
385 case "":
386 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700387 case ".docs.zip":
388 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700389 default:
390 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
391 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800392}
393
Colin Crossa3002fc2019-07-08 16:48:04 -0700394// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800395func JavadocFactory() android.Module {
396 module := &Javadoc{}
397
398 module.AddProperties(&module.properties)
399
400 InitDroiddocModule(module, android.HostAndDeviceSupported)
401 return module
402}
403
Colin Crossa3002fc2019-07-08 16:48:04 -0700404// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800405func JavadocHostFactory() android.Module {
406 module := &Javadoc{}
407
408 module.AddProperties(&module.properties)
409
410 InitDroiddocModule(module, android.HostSupported)
411 return module
412}
413
Colin Cross41955e82019-05-29 14:40:35 -0700414var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800415
Colin Cross83bb3162018-06-25 15:48:06 -0700416func (j *Javadoc) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900417 return String(j.properties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700418}
419
Paul Duffine25c6442019-10-11 13:50:28 +0100420func (j *Javadoc) systemModules() string {
421 return proptools.String(j.properties.System_modules)
422}
423
Colin Cross83bb3162018-06-25 15:48:06 -0700424func (j *Javadoc) minSdkVersion() string {
425 return j.sdkVersion()
426}
427
Dan Willemsen419290a2018-10-31 15:28:47 -0700428func (j *Javadoc) targetSdkVersion() string {
429 return j.sdkVersion()
430}
431
Nan Zhang581fd212018-01-10 16:06:12 -0800432func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
433 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100434 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700435 if sdkDep.useDefaultLibs {
436 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
437 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
438 if sdkDep.hasFrameworkLibs() {
439 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700440 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700441 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700442 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100443 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700444 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800445 }
446 }
447
Colin Cross42d48b72018-08-29 14:10:52 -0700448 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800449}
450
Nan Zhanga40da042018-08-01 12:48:00 -0700451func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
452 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900453
Colin Cross3047fa22019-04-18 10:56:44 -0700454 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900455
456 return flags
457}
458
459func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700460 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900461
462 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
463 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
464
465 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700466 var deps android.Paths
467
Jiyong Park1e440682018-05-23 18:42:04 +0900468 if aidlPreprocess.Valid() {
469 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700470 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900471 } else {
472 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
473 }
474
475 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
476 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
477 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
478 flags = append(flags, "-I"+src.String())
479 }
480
Colin Cross3047fa22019-04-18 10:56:44 -0700481 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900482}
483
Jiyong Parkd90d7412019-08-20 22:49:19 +0900484// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900485func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700486 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900487
488 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700489 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900490
Jiyong Park1112c4c2019-08-16 21:12:10 +0900491 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
492
Jiyong Park1e440682018-05-23 18:42:04 +0900493 for _, srcFile := range srcFiles {
494 switch srcFile.Ext() {
495 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700496 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900497 case ".logtags":
498 javaFile := genLogtags(ctx, srcFile)
499 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900500 default:
501 outSrcFiles = append(outSrcFiles, srcFile)
502 }
503 }
504
Colin Crossc0806172019-06-14 18:51:47 -0700505 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
506 if len(aidlSrcs) > 0 {
507 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
508 outSrcFiles = append(outSrcFiles, srcJarFiles...)
509 }
510
Jiyong Park1e440682018-05-23 18:42:04 +0900511 return outSrcFiles
512}
513
Nan Zhang581fd212018-01-10 16:06:12 -0800514func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
515 var deps deps
516
Colin Cross83bb3162018-06-25 15:48:06 -0700517 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800518 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700519 ctx.AddMissingDependencies(sdkDep.bootclasspath)
520 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800521 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700522 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800523 }
524
525 ctx.VisitDirectDeps(func(module android.Module) {
526 otherName := ctx.OtherModuleName(module)
527 tag := ctx.OtherModuleDependencyTag(module)
528
Colin Cross2d24c1b2018-05-23 10:59:18 -0700529 switch tag {
530 case bootClasspathTag:
531 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800532 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffine25c6442019-10-11 13:50:28 +0100533 } else if sm, ok := module.(*SystemModules); ok {
534 // A system modules dependency has been added to the bootclasspath
535 // so add its libs to the bootclasspath.
536 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700537 } else {
538 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
539 }
540 case libTag:
541 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800542 case SdkLibraryDependency:
543 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700544 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900545 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900546 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700547 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800548 checkProducesJars(ctx, dep)
549 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800550 default:
551 ctx.ModuleErrorf("depends on non-java module %q", otherName)
552 }
Colin Cross6cef4812019-10-17 14:23:50 -0700553 case java9LibTag:
554 switch dep := module.(type) {
555 case Dependency:
556 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
557 default:
558 ctx.ModuleErrorf("depends on non-java module %q", otherName)
559 }
Nan Zhang357466b2018-04-17 17:38:36 -0700560 case systemModulesTag:
561 if deps.systemModules != nil {
562 panic("Found two system module dependencies")
563 }
564 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000565 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700566 panic("Missing directory for system module dependency")
567 }
Colin Crossb77043e2019-07-16 13:57:13 -0700568 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800569 }
570 })
571 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
572 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800573 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900574
575 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
576 if filterPackages == nil {
577 return srcs
578 }
579 filtered := []android.Path{}
580 for _, src := range srcs {
581 if src.Ext() != ".java" {
582 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
583 // but otherwise metalava emits stub sources having references to the generated AIDL classes
584 // in filtered-out pacages (e.g. com.android.internal.*).
585 // TODO(b/141149570) We need to fix this by introducing default private constructors or
586 // fixing metalava to not emit constructors having references to unknown classes.
587 filtered = append(filtered, src)
588 continue
589 }
590 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
591 for _, pkg := range filterPackages {
592 if strings.HasPrefix(packageName, pkg) {
593 filtered = append(filtered, src)
594 break
595 }
596 }
597 }
598 return filtered
599 }
600 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
601
Nan Zhanga40da042018-08-01 12:48:00 -0700602 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900603 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800604
605 // srcs may depend on some genrule output.
606 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800607 j.srcJars = append(j.srcJars, deps.srcJars...)
608
Nan Zhang581fd212018-01-10 16:06:12 -0800609 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800610 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800611
Nan Zhang9c69a122018-08-22 10:22:08 -0700612 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800613 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
614 }
615 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800616
Colin Cross8a497952019-03-05 22:25:09 -0800617 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000618 argFilesMap := map[string]string{}
619 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700620
Paul Duffin99e4a502019-02-11 15:38:42 +0000621 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800622 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000623 if _, exists := argFilesMap[label]; !exists {
624 argFilesMap[label] = strings.Join(paths.Strings(), " ")
625 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700626 } else {
627 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000628 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700629 }
630 }
631
632 var err error
Colin Cross15638152019-07-11 11:11:35 -0700633 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 if strings.HasPrefix(name, "location ") {
635 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000636 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700637 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700638 } else {
Colin Cross15638152019-07-11 11:11:35 -0700639 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000640 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700641 }
642 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700643 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700644 }
Colin Cross15638152019-07-11 11:11:35 -0700645 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700646 })
647
648 if err != nil {
649 ctx.PropertyErrorf("args", "%s", err.Error())
650 }
651
Nan Zhang581fd212018-01-10 16:06:12 -0800652 return deps
653}
654
655func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
656 j.addDeps(ctx)
657}
658
659func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
660 deps := j.collectDeps(ctx)
661
Colin Crossdaa4c672019-07-15 22:53:46 -0700662 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800663
Colin Crossdaa4c672019-07-15 22:53:46 -0700664 outDir := android.PathForModuleOut(ctx, "out")
665 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
666
667 j.stubsSrcJar = nil
668
669 rule := android.NewRuleBuilder()
670
671 rule.Command().Text("rm -rf").Text(outDir.String())
672 rule.Command().Text("mkdir -p").Text(outDir.String())
673
674 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700675
Colin Cross83bb3162018-06-25 15:48:06 -0700676 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800677
Colin Crossdaa4c672019-07-15 22:53:46 -0700678 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
679 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800680
Colin Cross1e743852019-10-28 11:37:20 -0700681 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700682 Flag("-J-Xmx1024m").
683 Flag("-XDignore.symbol.file").
684 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800685
Colin Crossdaa4c672019-07-15 22:53:46 -0700686 rule.Command().
687 BuiltTool(ctx, "soong_zip").
688 Flag("-write_if_changed").
689 Flag("-d").
690 FlagWithOutput("-o ", j.docZip).
691 FlagWithArg("-C ", outDir.String()).
692 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700693
Colin Crossdaa4c672019-07-15 22:53:46 -0700694 rule.Restat()
695
696 zipSyncCleanupCmd(rule, srcJarDir)
697
698 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800699}
700
Nan Zhanga40da042018-08-01 12:48:00 -0700701//
702// Droiddoc
703//
704type Droiddoc struct {
705 Javadoc
706
707 properties DroiddocProperties
708 apiFile android.WritablePath
709 dexApiFile android.WritablePath
710 privateApiFile android.WritablePath
711 privateDexApiFile android.WritablePath
712 removedApiFile android.WritablePath
713 removedDexApiFile android.WritablePath
714 exactApiFile android.WritablePath
715 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700716 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700717
718 checkCurrentApiTimestamp android.WritablePath
719 updateCurrentApiTimestamp android.WritablePath
720 checkLastReleasedApiTimestamp android.WritablePath
721
Nan Zhanga40da042018-08-01 12:48:00 -0700722 apiFilePath android.Path
723}
724
Colin Crossa3002fc2019-07-08 16:48:04 -0700725// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700726func DroiddocFactory() android.Module {
727 module := &Droiddoc{}
728
729 module.AddProperties(&module.properties,
730 &module.Javadoc.properties)
731
732 InitDroiddocModule(module, android.HostAndDeviceSupported)
733 return module
734}
735
Colin Crossa3002fc2019-07-08 16:48:04 -0700736// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700737func DroiddocHostFactory() android.Module {
738 module := &Droiddoc{}
739
740 module.AddProperties(&module.properties,
741 &module.Javadoc.properties)
742
743 InitDroiddocModule(module, android.HostSupported)
744 return module
745}
746
747func (d *Droiddoc) ApiFilePath() android.Path {
748 return d.apiFilePath
749}
750
Nan Zhang581fd212018-01-10 16:06:12 -0800751func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
752 d.Javadoc.addDeps(ctx)
753
Inseob Kim38449af2019-02-28 14:24:05 +0900754 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
755 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
756 }
757
Nan Zhang79614d12018-04-19 18:03:39 -0700758 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800759 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
760 }
Nan Zhang581fd212018-01-10 16:06:12 -0800761}
762
Colin Crossab054432019-07-15 16:13:59 -0700763func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Nan Zhang443fa522018-08-20 20:58:28 -0700764 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
765 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
766 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700767 cmd.FlagWithArg("-source ", "1.8").
768 Flag("-J-Xmx1600m").
769 Flag("-J-XX:-OmitStackTraceInFastThrow").
770 Flag("-XDignore.symbol.file").
771 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
772 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
773 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
Elliott Hughes26bce342019-09-12 15:05:13 -0700774 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 -0700775
Nan Zhanga40da042018-08-01 12:48:00 -0700776 if String(d.properties.Custom_template) == "" {
777 // TODO: This is almost always droiddoc-templates-sdk
778 ctx.PropertyErrorf("custom_template", "must specify a template")
779 }
780
781 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700782 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700783 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700784 } else {
785 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
786 }
787 })
788
789 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700790 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
791 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
792 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700793 }
794
795 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700796 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
797 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
798 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700799 }
800
801 if len(d.properties.Html_dirs) > 2 {
802 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
803 }
804
Colin Cross8a497952019-03-05 22:25:09 -0800805 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700806 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700807
Colin Crossab054432019-07-15 16:13:59 -0700808 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700809
810 if String(d.properties.Proofread_file) != "" {
811 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700812 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700813 }
814
815 if String(d.properties.Todo_file) != "" {
816 // tricky part:
817 // we should not compute full path for todo_file through PathForModuleOut().
818 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700819 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
820 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700821 }
822
823 if String(d.properties.Resourcesdir) != "" {
824 // TODO: should we add files under resourcesDir to the implicits? It seems that
825 // resourcesDir is one sub dir of htmlDir
826 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700827 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700828 }
829
830 if String(d.properties.Resourcesoutdir) != "" {
831 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700832 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700833 }
Nan Zhanga40da042018-08-01 12:48:00 -0700834}
835
Colin Crossab054432019-07-15 16:13:59 -0700836func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200837 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
838 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700839 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700840
Nan Zhanga40da042018-08-01 12:48:00 -0700841 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700842 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700843 d.apiFilePath = d.apiFile
844 }
845
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200846 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
847 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700848 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700849 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700850 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700851 }
852
853 if String(d.properties.Private_api_filename) != "" {
854 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700855 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700856 }
857
858 if String(d.properties.Dex_api_filename) != "" {
859 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700860 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700861 }
862
863 if String(d.properties.Private_dex_api_filename) != "" {
864 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700865 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700866 }
867
868 if String(d.properties.Removed_dex_api_filename) != "" {
869 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700870 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700871 }
872
873 if String(d.properties.Exact_api_filename) != "" {
874 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700875 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700876 }
877
878 if String(d.properties.Dex_mapping_filename) != "" {
879 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700880 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700881 }
882
Nan Zhang66dc2362018-08-14 20:41:04 -0700883 if String(d.properties.Proguard_filename) != "" {
884 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700885 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700886 }
887
Nan Zhanga40da042018-08-01 12:48:00 -0700888 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700889 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700890 }
891
892 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700893 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700894 }
Nan Zhanga40da042018-08-01 12:48:00 -0700895}
896
Colin Crossab054432019-07-15 16:13:59 -0700897func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700898 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700899 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
900 rule.Command().Text("cp").
901 Input(staticDocIndexRedirect).
902 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700903 }
904
905 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700906 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
907 rule.Command().Text("cp").
908 Input(staticDocProperties).
909 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700910 }
Nan Zhanga40da042018-08-01 12:48:00 -0700911}
912
Colin Crossab054432019-07-15 16:13:59 -0700913func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700914 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700915
916 cmd := rule.Command().
917 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
918 Flag(config.JavacVmFlags).
919 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700920 FlagWithRspFileInputList("@", srcs).
921 FlagWithInput("@", srcJarList)
922
Colin Crossab054432019-07-15 16:13:59 -0700923 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
924 // based stubs generation.
925 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
926 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
927 // the correct package name base path.
928 if len(sourcepaths) > 0 {
929 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
930 } else {
931 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
932 }
933
934 cmd.FlagWithArg("-d ", outDir.String()).
935 Flag("-quiet")
936
937 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700938}
939
Colin Crossdaa4c672019-07-15 22:53:46 -0700940func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
941 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
942 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
943
944 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
945
946 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
947 cmd.Flag(flag).Implicits(deps)
948
949 cmd.FlagWithArg("--patch-module ", "java.base=.")
950
951 if len(classpath) > 0 {
952 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
953 }
954
955 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700956}
957
Colin Crossdaa4c672019-07-15 22:53:46 -0700958func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
959 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
960 sourcepaths android.Paths) *android.RuleBuilderCommand {
961
962 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
963
964 if len(bootclasspath) == 0 && ctx.Device() {
965 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
966 // ensure java does not fall back to the default bootclasspath.
967 cmd.FlagWithArg("-bootclasspath ", `""`)
968 } else if len(bootclasspath) > 0 {
969 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
970 }
971
972 if len(classpath) > 0 {
973 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
974 }
975
976 return cmd
977}
978
Colin Crossab054432019-07-15 16:13:59 -0700979func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
980 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700981
Colin Crossab054432019-07-15 16:13:59 -0700982 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
983 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
984
985 return rule.Command().
986 BuiltTool(ctx, "dokka").
987 Flag(config.JavacVmFlags).
988 Flag(srcJarDir.String()).
989 FlagWithInputList("-classpath ", dokkaClasspath, ":").
990 FlagWithArg("-format ", "dac").
991 FlagWithArg("-dacRoot ", "/reference/kotlin").
992 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700993}
994
995func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
996 deps := d.Javadoc.collectDeps(ctx)
997
Colin Crossdaa4c672019-07-15 22:53:46 -0700998 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
999 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1000
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1002 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1003 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1004 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1005
Colin Crossab054432019-07-15 16:13:59 -07001006 outDir := android.PathForModuleOut(ctx, "out")
1007 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1008 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001009
Colin Crossab054432019-07-15 16:13:59 -07001010 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001011
Colin Crossab054432019-07-15 16:13:59 -07001012 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1013 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001014
Colin Crossab054432019-07-15 16:13:59 -07001015 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1016
1017 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001018 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001019 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001020 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001021 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001022 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001023 }
1024
Colin Crossab054432019-07-15 16:13:59 -07001025 d.stubsFlags(ctx, cmd, stubsDir)
1026
1027 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1028
1029 var desc string
1030 if Bool(d.properties.Dokka_enabled) {
1031 desc = "dokka"
1032 } else {
1033 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1034
1035 for _, o := range d.Javadoc.properties.Out {
1036 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1037 }
1038
1039 d.postDoclavaCmds(ctx, rule)
1040 desc = "doclava"
1041 }
1042
1043 rule.Command().
1044 BuiltTool(ctx, "soong_zip").
1045 Flag("-write_if_changed").
1046 Flag("-d").
1047 FlagWithOutput("-o ", d.docZip).
1048 FlagWithArg("-C ", outDir.String()).
1049 FlagWithArg("-D ", outDir.String())
1050
1051 rule.Command().
1052 BuiltTool(ctx, "soong_zip").
1053 Flag("-write_if_changed").
1054 Flag("-jar").
1055 FlagWithOutput("-o ", d.stubsSrcJar).
1056 FlagWithArg("-C ", stubsDir.String()).
1057 FlagWithArg("-D ", stubsDir.String())
1058
1059 rule.Restat()
1060
1061 zipSyncCleanupCmd(rule, srcJarDir)
1062
1063 rule.Build(pctx, ctx, "javadoc", desc)
1064
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001065 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001066 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001067
1068 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1069 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001070
1071 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001072
1073 rule := android.NewRuleBuilder()
1074
1075 rule.Command().Text("( true")
1076
1077 rule.Command().
1078 BuiltTool(ctx, "apicheck").
1079 Flag("-JXmx1024m").
1080 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1081 OptionalFlag(d.properties.Check_api.Current.Args).
1082 Input(apiFile).
1083 Input(d.apiFile).
1084 Input(removedApiFile).
1085 Input(d.removedApiFile)
1086
1087 msg := fmt.Sprintf(`\n******************************\n`+
1088 `You have tried to change the API from what has been previously approved.\n\n`+
1089 `To make these errors go away, you have two choices:\n`+
1090 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1091 ` errors above.\n\n`+
1092 ` 2. You can update current.txt by executing the following command:\n`+
1093 ` make %s-update-current-api\n\n`+
1094 ` To submit the revised current.txt to the main Android repository,\n`+
1095 ` you will need approval.\n`+
1096 `******************************\n`, ctx.ModuleName())
1097
1098 rule.Command().
1099 Text("touch").Output(d.checkCurrentApiTimestamp).
1100 Text(") || (").
1101 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1102 Text("; exit 38").
1103 Text(")")
1104
1105 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001106
1107 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001108
1109 // update API rule
1110 rule = android.NewRuleBuilder()
1111
1112 rule.Command().Text("( true")
1113
1114 rule.Command().
1115 Text("cp").Flag("-f").
1116 Input(d.apiFile).Flag(apiFile.String())
1117
1118 rule.Command().
1119 Text("cp").Flag("-f").
1120 Input(d.removedApiFile).Flag(removedApiFile.String())
1121
1122 msg = "failed to update public API"
1123
1124 rule.Command().
1125 Text("touch").Output(d.updateCurrentApiTimestamp).
1126 Text(") || (").
1127 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1128 Text("; exit 38").
1129 Text(")")
1130
1131 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001132 }
1133
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001134 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001135 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001136
1137 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1138 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001139
1140 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001141
1142 rule := android.NewRuleBuilder()
1143
1144 rule.Command().
1145 Text("(").
1146 BuiltTool(ctx, "apicheck").
1147 Flag("-JXmx1024m").
1148 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1149 OptionalFlag(d.properties.Check_api.Last_released.Args).
1150 Input(apiFile).
1151 Input(d.apiFile).
1152 Input(removedApiFile).
1153 Input(d.removedApiFile)
1154
1155 msg := `\n******************************\n` +
1156 `You have tried to change the API from what has been previously released in\n` +
1157 `an SDK. Please fix the errors listed above.\n` +
1158 `******************************\n`
1159
1160 rule.Command().
1161 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1162 Text(") || (").
1163 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1164 Text("; exit 38").
1165 Text(")")
1166
1167 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001168 }
1169}
1170
1171//
1172// Droidstubs
1173//
1174type Droidstubs struct {
1175 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001176 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001177
Pete Gillin581d6082018-10-22 15:55:04 +01001178 properties DroidstubsProperties
1179 apiFile android.WritablePath
1180 apiXmlFile android.WritablePath
1181 lastReleasedApiXmlFile android.WritablePath
1182 dexApiFile android.WritablePath
1183 privateApiFile android.WritablePath
1184 privateDexApiFile android.WritablePath
1185 removedApiFile android.WritablePath
1186 removedDexApiFile android.WritablePath
1187 apiMappingFile android.WritablePath
1188 exactApiFile android.WritablePath
1189 proguardFile android.WritablePath
1190 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001191
1192 checkCurrentApiTimestamp android.WritablePath
1193 updateCurrentApiTimestamp android.WritablePath
1194 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001195 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001196 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001197
Pete Gillin581d6082018-10-22 15:55:04 +01001198 checkNullabilityWarningsTimestamp android.WritablePath
1199
Nan Zhang1598a9e2018-09-04 17:14:32 -07001200 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001201 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001202
1203 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001204
1205 jdiffDocZip android.WritablePath
1206 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001207
1208 metadataZip android.WritablePath
1209 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001210}
1211
Colin Crossa3002fc2019-07-08 16:48:04 -07001212// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1213// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1214// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001215func DroidstubsFactory() android.Module {
1216 module := &Droidstubs{}
1217
1218 module.AddProperties(&module.properties,
1219 &module.Javadoc.properties)
1220
1221 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001222 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001223 return module
1224}
1225
Colin Crossa3002fc2019-07-08 16:48:04 -07001226// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1227// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1228// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1229// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001230func DroidstubsHostFactory() android.Module {
1231 module := &Droidstubs{}
1232
1233 module.AddProperties(&module.properties,
1234 &module.Javadoc.properties)
1235
1236 InitDroiddocModule(module, android.HostSupported)
1237 return module
1238}
1239
1240func (d *Droidstubs) ApiFilePath() android.Path {
1241 return d.apiFilePath
1242}
1243
1244func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1245 d.Javadoc.addDeps(ctx)
1246
Inseob Kim38449af2019-02-28 14:24:05 +09001247 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1248 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1249 }
1250
Nan Zhang1598a9e2018-09-04 17:14:32 -07001251 if len(d.properties.Merge_annotations_dirs) != 0 {
1252 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1253 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1254 }
1255 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001256
Pete Gillin77167902018-09-19 18:16:26 +01001257 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1258 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1259 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1260 }
1261 }
1262
Nan Zhang9c69a122018-08-22 10:22:08 -07001263 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1264 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1265 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1266 }
1267 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001268}
1269
Colin Cross33961b52019-07-11 11:01:22 -07001270func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001271 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1272 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001273 String(d.properties.Api_filename) != "" {
1274 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001275 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001276 d.apiFilePath = d.apiFile
1277 }
1278
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.Removed_api_filename) != "" {
1282 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001283 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001284 }
1285
1286 if String(d.properties.Private_api_filename) != "" {
1287 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001288 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001289 }
1290
1291 if String(d.properties.Dex_api_filename) != "" {
1292 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001293 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001294 }
1295
1296 if String(d.properties.Private_dex_api_filename) != "" {
1297 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001298 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001299 }
1300
1301 if String(d.properties.Removed_dex_api_filename) != "" {
1302 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001303 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001304 }
1305
1306 if String(d.properties.Exact_api_filename) != "" {
1307 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001308 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001309 }
1310
Nan Zhang9c69a122018-08-22 10:22:08 -07001311 if String(d.properties.Dex_mapping_filename) != "" {
1312 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001313 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001314 }
1315
Nan Zhang199645c2018-09-19 12:40:06 -07001316 if String(d.properties.Proguard_filename) != "" {
1317 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001318 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001319 }
1320
Nan Zhang9c69a122018-08-22 10:22:08 -07001321 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001322 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1323 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001324 }
1325
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001327 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001328 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001329 cmd.FlagWithArg("--stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001330 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001331}
1332
Colin Cross33961b52019-07-11 11:01:22 -07001333func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001334 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001335 cmd.Flag("--include-annotations")
1336
Pete Gillinc382a562018-11-14 18:45:46 +00001337 validatingNullability :=
1338 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1339 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001340
Pete Gillina262c052018-09-14 14:25:48 +01001341 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001342 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001343 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001344 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001345 }
Colin Cross33961b52019-07-11 11:01:22 -07001346
Pete Gillinc382a562018-11-14 18:45:46 +00001347 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001348 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001349 }
Colin Cross33961b52019-07-11 11:01:22 -07001350
Pete Gillina262c052018-09-14 14:25:48 +01001351 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001352 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001353 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001354 }
Nan Zhanga40da042018-08-01 12:48:00 -07001355
1356 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001357 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001358
Nan Zhang1598a9e2018-09-04 17:14:32 -07001359 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001360 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001361 "has to be non-empty if annotations was enabled!")
1362 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001363
Colin Cross33961b52019-07-11 11:01:22 -07001364 d.mergeAnnoDirFlags(ctx, cmd)
1365
1366 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1367 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1368 FlagWithArg("--hide ", "SuperfluousPrefix").
1369 FlagWithArg("--hide ", "AnnotationExtraction")
1370 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001371}
1372
Colin Cross33961b52019-07-11 11:01:22 -07001373func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1374 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1375 if t, ok := m.(*ExportedDroiddocDir); ok {
1376 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1377 } else {
1378 ctx.PropertyErrorf("merge_annotations_dirs",
1379 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1380 }
1381 })
1382}
1383
1384func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001385 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1386 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001387 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001388 } else {
1389 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1390 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1391 }
1392 })
Nan Zhanga40da042018-08-01 12:48:00 -07001393}
1394
Colin Cross33961b52019-07-11 11:01:22 -07001395func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001396 if Bool(d.properties.Api_levels_annotations_enabled) {
1397 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001398
1399 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1400 ctx.PropertyErrorf("api_levels_annotations_dirs",
1401 "has to be non-empty if api levels annotations was enabled!")
1402 }
1403
Colin Cross33961b52019-07-11 11:01:22 -07001404 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1405 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1406 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1407 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001408
1409 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1410 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001411 for _, dep := range t.deps {
1412 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001413 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001414 }
1415 }
Colin Cross33961b52019-07-11 11:01:22 -07001416 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001417 } else {
1418 ctx.PropertyErrorf("api_levels_annotations_dirs",
1419 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1420 }
1421 })
1422
1423 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001424}
1425
Colin Cross33961b52019-07-11 11:01:22 -07001426func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001427 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1428 if d.apiFile.String() == "" {
1429 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1430 }
1431
1432 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001433 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001434
1435 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1436 ctx.PropertyErrorf("check_api.last_released.api_file",
1437 "has to be non-empty if jdiff was enabled!")
1438 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001439
Colin Cross33961b52019-07-11 11:01:22 -07001440 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001441 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001442 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1443 }
1444}
Nan Zhang71bbe632018-09-17 14:32:21 -07001445
Colin Cross1e743852019-10-28 11:37:20 -07001446func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001447 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
1448 cmd := rule.Command().BuiltTool(ctx, "metalava").
1449 Flag(config.JavacVmFlags).
1450 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001451 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001452 FlagWithRspFileInputList("@", srcs).
1453 FlagWithInput("@", srcJarList)
1454
1455 if len(bootclasspath) > 0 {
1456 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001457 }
1458
Colin Cross33961b52019-07-11 11:01:22 -07001459 if len(classpath) > 0 {
1460 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1461 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001462
Colin Cross33961b52019-07-11 11:01:22 -07001463 if len(sourcepaths) > 0 {
1464 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1465 } else {
1466 cmd.FlagWithArg("-sourcepath ", `""`)
1467 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001468
Colin Cross33961b52019-07-11 11:01:22 -07001469 cmd.Flag("--no-banner").
1470 Flag("--color").
1471 Flag("--quiet").
1472 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001473
Colin Cross33961b52019-07-11 11:01:22 -07001474 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001475}
1476
Nan Zhang1598a9e2018-09-04 17:14:32 -07001477func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001478 deps := d.Javadoc.collectDeps(ctx)
1479
1480 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001481
Colin Cross33961b52019-07-11 11:01:22 -07001482 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001483
Colin Crossdaa4c672019-07-15 22:53:46 -07001484 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001485
Colin Cross33961b52019-07-11 11:01:22 -07001486 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1487 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001488
Colin Cross33961b52019-07-11 11:01:22 -07001489 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001490
Colin Cross33961b52019-07-11 11:01:22 -07001491 rule.Command().Text("rm -rf").Text(stubsDir.String())
1492 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001493
Colin Cross33961b52019-07-11 11:01:22 -07001494 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1495
1496 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1497 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1498
1499 d.stubsFlags(ctx, cmd, stubsDir)
1500
1501 d.annotationsFlags(ctx, cmd)
1502 d.inclusionAnnotationsFlags(ctx, cmd)
1503 d.apiLevelsAnnotationsFlags(ctx, cmd)
1504 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001505
Nan Zhang1598a9e2018-09-04 17:14:32 -07001506 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1507 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1508 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1509 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1510 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001511 }
Colin Cross33961b52019-07-11 11:01:22 -07001512
1513 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1514 for _, o := range d.Javadoc.properties.Out {
1515 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1516 }
1517
1518 rule.Command().
1519 BuiltTool(ctx, "soong_zip").
1520 Flag("-write_if_changed").
1521 Flag("-jar").
1522 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1523 FlagWithArg("-C ", stubsDir.String()).
1524 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001525
1526 if Bool(d.properties.Write_sdk_values) {
1527 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1528 rule.Command().
1529 BuiltTool(ctx, "soong_zip").
1530 Flag("-write_if_changed").
1531 Flag("-d").
1532 FlagWithOutput("-o ", d.metadataZip).
1533 FlagWithArg("-C ", d.metadataDir.String()).
1534 FlagWithArg("-D ", d.metadataDir.String())
1535 }
1536
Colin Cross33961b52019-07-11 11:01:22 -07001537 rule.Restat()
1538
1539 zipSyncCleanupCmd(rule, srcJarDir)
1540
1541 rule.Build(pctx, ctx, "metalava", "metalava")
1542
1543 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001544
Adrian Roos075eedc2019-10-10 12:07:03 +02001545 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1546 rule := android.NewRuleBuilder()
1547 rule.Command().Text("( true")
1548
1549 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1550 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1551
1552 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1553 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1554
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001555 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1556
Adrian Roos075eedc2019-10-10 12:07:03 +02001557 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1558 if newSince.Valid() {
1559 cmd.FlagWithInput("--api-lint ", newSince.Path())
1560 } else {
1561 cmd.Flag("--api-lint")
1562 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001563 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1564 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001565
1566 d.inclusionAnnotationsFlags(ctx, cmd)
1567 d.mergeAnnoDirFlags(ctx, cmd)
1568
1569 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1570 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1571 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1572
1573 if baselineFile.Valid() {
1574 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1575 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1576 }
1577
1578 zipSyncCleanupCmd(rule, srcJarDir)
1579
1580 msg := fmt.Sprintf(`\n******************************\n`+
1581 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1582 `To make these errors go away, you have two choices:\n`+
1583 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1584 ` 2. You can update the baseline by executing the following command:\n`+
1585 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1586 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1587 rule.Command().
1588 Text("touch").Output(d.apiLintTimestamp).
1589 Text(") || (").
1590 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1591 Text("; exit 38").
1592 Text(")")
1593
1594 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1595
1596 }
1597
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001598 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001599 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001600
1601 if len(d.Javadoc.properties.Out) > 0 {
1602 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1603 }
1604
1605 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1606 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001607 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1608 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001609
Nan Zhang2760dfc2018-08-24 17:32:54 +00001610 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001611
Colin Cross33961b52019-07-11 11:01:22 -07001612 rule := android.NewRuleBuilder()
1613
1614 rule.Command().Text("( true")
1615
1616 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1617 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1618
1619 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1620 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1621
1622 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1623 FlagWithInput("--check-compatibility:api:current ", apiFile).
1624 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1625
1626 d.inclusionAnnotationsFlags(ctx, cmd)
1627 d.mergeAnnoDirFlags(ctx, cmd)
1628
Adrian Roos14f75a92019-08-12 17:54:09 +02001629 if baselineFile.Valid() {
1630 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1631 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1632 }
1633
Colin Cross33961b52019-07-11 11:01:22 -07001634 zipSyncCleanupCmd(rule, srcJarDir)
1635
1636 msg := fmt.Sprintf(`\n******************************\n`+
1637 `You have tried to change the API from what has been previously approved.\n\n`+
1638 `To make these errors go away, you have two choices:\n`+
1639 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1640 ` errors above.\n\n`+
1641 ` 2. You can update current.txt by executing the following command:\n`+
1642 ` make %s-update-current-api\n\n`+
1643 ` To submit the revised current.txt to the main Android repository,\n`+
1644 ` you will need approval.\n`+
1645 `******************************\n`, ctx.ModuleName())
1646
1647 rule.Command().
1648 Text("touch").Output(d.checkCurrentApiTimestamp).
1649 Text(") || (").
1650 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1651 Text("; exit 38").
1652 Text(")")
1653
1654 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001655
1656 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001657
1658 // update API rule
1659 rule = android.NewRuleBuilder()
1660
1661 rule.Command().Text("( true")
1662
1663 rule.Command().
1664 Text("cp").Flag("-f").
1665 Input(d.apiFile).Flag(apiFile.String())
1666
1667 rule.Command().
1668 Text("cp").Flag("-f").
1669 Input(d.removedApiFile).Flag(removedApiFile.String())
1670
1671 msg = "failed to update public API"
1672
1673 rule.Command().
1674 Text("touch").Output(d.updateCurrentApiTimestamp).
1675 Text(") || (").
1676 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1677 Text("; exit 38").
1678 Text(")")
1679
1680 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001681 }
Nan Zhanga40da042018-08-01 12:48:00 -07001682
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001683 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001684 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001685
1686 if len(d.Javadoc.properties.Out) > 0 {
1687 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1688 }
1689
1690 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1691 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001692 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1693 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001694
Nan Zhang2760dfc2018-08-24 17:32:54 +00001695 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001696
Colin Cross33961b52019-07-11 11:01:22 -07001697 rule := android.NewRuleBuilder()
1698
1699 rule.Command().Text("( true")
1700
1701 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1702 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1703
1704 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1705 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1706
1707 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1708 FlagWithInput("--check-compatibility:api:released ", apiFile)
1709
1710 d.inclusionAnnotationsFlags(ctx, cmd)
1711
1712 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1713
1714 d.mergeAnnoDirFlags(ctx, cmd)
1715
Adrian Roos14f75a92019-08-12 17:54:09 +02001716 if baselineFile.Valid() {
1717 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1718 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1719 }
1720
Colin Cross33961b52019-07-11 11:01:22 -07001721 zipSyncCleanupCmd(rule, srcJarDir)
1722
1723 msg := `\n******************************\n` +
1724 `You have tried to change the API from what has been previously released in\n` +
1725 `an SDK. Please fix the errors listed above.\n` +
1726 `******************************\n`
1727 rule.Command().
1728 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1729 Text(") || (").
1730 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1731 Text("; exit 38").
1732 Text(")")
1733
1734 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001735 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001736
Pete Gillin581d6082018-10-22 15:55:04 +01001737 if String(d.properties.Check_nullability_warnings) != "" {
1738 if d.nullabilityWarningsFile == nil {
1739 ctx.PropertyErrorf("check_nullability_warnings",
1740 "Cannot specify check_nullability_warnings unless validating nullability")
1741 }
Colin Cross33961b52019-07-11 11:01:22 -07001742
1743 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1744
Pete Gillin581d6082018-10-22 15:55:04 +01001745 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001746
Pete Gillin581d6082018-10-22 15:55:04 +01001747 msg := fmt.Sprintf(`\n******************************\n`+
1748 `The warnings encountered during nullability annotation validation did\n`+
1749 `not match the checked in file of expected warnings. The diffs are shown\n`+
1750 `above. You have two options:\n`+
1751 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1752 ` 2. Update the file of expected warnings by running:\n`+
1753 ` cp %s %s\n`+
1754 ` and submitting the updated file as part of your change.`,
1755 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001756
1757 rule := android.NewRuleBuilder()
1758
1759 rule.Command().
1760 Text("(").
1761 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1762 Text("&&").
1763 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1764 Text(") || (").
1765 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1766 Text("; exit 38").
1767 Text(")")
1768
1769 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001770 }
1771
Nan Zhang71bbe632018-09-17 14:32:21 -07001772 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001773 if len(d.Javadoc.properties.Out) > 0 {
1774 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1775 }
1776
1777 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1778 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1779 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1780
1781 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001782
Nan Zhang86b06202018-09-21 17:09:21 -07001783 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1784 // since there's cron job downstream that fetch this .zip file periodically.
1785 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001786 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1787 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1788
Nan Zhang71bbe632018-09-17 14:32:21 -07001789 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001790
Colin Cross33961b52019-07-11 11:01:22 -07001791 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1792 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001793
Colin Cross33961b52019-07-11 11:01:22 -07001794 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1795
Colin Crossdaa4c672019-07-15 22:53:46 -07001796 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001797 deps.bootClasspath, deps.classpath, d.sourcepaths)
1798
1799 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001800 Flag("-XDignore.symbol.file").
1801 FlagWithArg("-doclet ", "jdiff.JDiff").
1802 FlagWithInput("-docletpath ", jdiff).
1803 Flag("-quiet").
1804 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1805 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1806 Implicit(d.apiXmlFile).
1807 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1808 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1809 Implicit(d.lastReleasedApiXmlFile)
1810
Colin Cross33961b52019-07-11 11:01:22 -07001811 rule.Command().
1812 BuiltTool(ctx, "soong_zip").
1813 Flag("-write_if_changed").
1814 Flag("-d").
1815 FlagWithOutput("-o ", d.jdiffDocZip).
1816 FlagWithArg("-C ", outDir.String()).
1817 FlagWithArg("-D ", outDir.String())
1818
1819 rule.Command().
1820 BuiltTool(ctx, "soong_zip").
1821 Flag("-write_if_changed").
1822 Flag("-jar").
1823 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1824 FlagWithArg("-C ", stubsDir.String()).
1825 FlagWithArg("-D ", stubsDir.String())
1826
1827 rule.Restat()
1828
1829 zipSyncCleanupCmd(rule, srcJarDir)
1830
1831 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001832 }
Nan Zhang581fd212018-01-10 16:06:12 -08001833}
Dan Willemsencc090972018-02-26 14:33:31 -08001834
Nan Zhanga40da042018-08-01 12:48:00 -07001835//
Nan Zhangf4936b02018-08-01 15:00:28 -07001836// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001837//
Dan Willemsencc090972018-02-26 14:33:31 -08001838var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001839var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001840var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001841var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001842
Nan Zhangf4936b02018-08-01 15:00:28 -07001843type ExportedDroiddocDirProperties struct {
1844 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001845 Path *string
1846}
1847
Nan Zhangf4936b02018-08-01 15:00:28 -07001848type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001849 android.ModuleBase
1850
Nan Zhangf4936b02018-08-01 15:00:28 -07001851 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001852
1853 deps android.Paths
1854 dir android.Path
1855}
1856
Colin Crossa3002fc2019-07-08 16:48:04 -07001857// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001858func ExportedDroiddocDirFactory() android.Module {
1859 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001860 module.AddProperties(&module.properties)
1861 android.InitAndroidModule(module)
1862 return module
1863}
1864
Nan Zhangf4936b02018-08-01 15:00:28 -07001865func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001866
Nan Zhangf4936b02018-08-01 15:00:28 -07001867func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001868 path := String(d.properties.Path)
1869 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001870 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001871}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001872
1873//
1874// Defaults
1875//
1876type DocDefaults struct {
1877 android.ModuleBase
1878 android.DefaultsModuleBase
1879}
1880
Nan Zhangb2b33de2018-02-23 11:18:47 -08001881func DocDefaultsFactory() android.Module {
1882 module := &DocDefaults{}
1883
1884 module.AddProperties(
1885 &JavadocProperties{},
1886 &DroiddocProperties{},
1887 )
1888
1889 android.InitDefaultsModule(module)
1890
1891 return module
1892}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001893
1894func StubsDefaultsFactory() android.Module {
1895 module := &DocDefaults{}
1896
1897 module.AddProperties(
1898 &JavadocProperties{},
1899 &DroidstubsProperties{},
1900 )
1901
1902 android.InitDefaultsModule(module)
1903
1904 return module
1905}
Colin Cross33961b52019-07-11 11:01:22 -07001906
1907func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1908 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1909
1910 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1911 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1912 srcJarList := srcJarDir.Join(ctx, "list")
1913
1914 rule.Temporary(srcJarList)
1915
1916 rule.Command().BuiltTool(ctx, "zipsync").
1917 FlagWithArg("-d ", srcJarDir.String()).
1918 FlagWithOutput("-l ", srcJarList).
1919 FlagWithArg("-f ", `"*.java"`).
1920 Inputs(srcJars)
1921
1922 return srcJarList
1923}
1924
1925func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1926 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1927}
Paul Duffin91547182019-11-12 19:39:36 +00001928
1929var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1930
1931type PrebuiltStubsSourcesProperties struct {
1932 Srcs []string `android:"path"`
1933}
1934
1935type PrebuiltStubsSources struct {
1936 android.ModuleBase
1937 android.DefaultableModuleBase
1938 prebuilt android.Prebuilt
1939 android.SdkBase
1940
1941 properties PrebuiltStubsSourcesProperties
1942
1943 srcs android.Paths
1944 stubsSrcJar android.ModuleOutPath
1945}
1946
1947func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1948 p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1949}
1950
1951func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1952 return &p.prebuilt
1953}
1954
1955func (p *PrebuiltStubsSources) Name() string {
1956 return p.prebuilt.Name(p.ModuleBase.Name())
1957}
1958
1959func (p *PrebuiltStubsSources) Srcs() android.Paths {
1960 return append(android.Paths{}, p.srcs...)
1961}
1962
1963// prebuilt_stubs_sources imports a set of java source files as if they were
1964// generated by droidstubs.
1965//
1966// By default, a prebuilt_stubs_sources has a single variant that expects a
1967// set of `.java` files generated by droidstubs.
1968//
1969// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1970// for host modules.
1971//
1972// Intended only for use by sdk snapshots.
1973func PrebuiltStubsSourcesFactory() android.Module {
1974 module := &PrebuiltStubsSources{}
1975
1976 module.AddProperties(&module.properties)
1977
1978 android.InitPrebuiltModule(module, &module.properties.Srcs)
1979 android.InitSdkAwareModule(module)
1980 InitDroiddocModule(module, android.HostAndDeviceSupported)
1981 return module
1982}
1983
Paul Duffin13879572019-11-28 14:31:38 +00001984type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001985 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001986}
1987
1988func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1989 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1990}
1991
1992func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1993 _, ok := module.(*Droidstubs)
1994 return ok
1995}
1996
1997func (mt *droidStubsSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1998 variants := member.Variants()
1999 if len(variants) != 1 {
2000 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2001 }
2002 variant := variants[0]
2003 d, _ := variant.(*Droidstubs)
Paul Duffin91547182019-11-12 19:39:36 +00002004 stubsSrcJar := d.stubsSrcJar
2005
2006 snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
2007 builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
2008
Paul Duffin9d8d6092019-12-05 18:19:29 +00002009 pbm := builder.AddPrebuiltModule(member, "prebuilt_stubs_sources")
Paul Duffinb645ec82019-11-27 17:43:54 +00002010 pbm.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin91547182019-11-12 19:39:36 +00002011}