blob: 76cdaeac6cf3241757ec04ec7722c7d08e876327 [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)
Nan Zhang581fd212018-01-10 16:06:12 -080043}
44
Colin Crossa1ce2a02018-06-20 15:19:39 -070045var (
46 srcsLibTag = dependencyTag{name: "sources from javalib"}
47)
48
Nan Zhang581fd212018-01-10 16:06:12 -080049type JavadocProperties struct {
50 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
51 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080052 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080053
54 // list of directories rooted at the Android.bp file that will
55 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080056 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080057
58 // list of source files that should not be used to build the Java module.
59 // This is most useful in the arch/multilib variants to remove non-common files
60 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080061 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080062
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090063 // list of package names that should actually be used. If this property is left unspecified,
64 // all the sources from the srcs property is used.
65 Filter_packages []string
66
Nan Zhangb2b33de2018-02-23 11:18:47 -080067 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080068 Libs []string `android:"arch_variant"`
69
70 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080071 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080072
Paul Duffine25c6442019-10-11 13:50:28 +010073 // if not blank, set to the version of the sdk to compile against.
74 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080075 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090076
Paul Duffine25c6442019-10-11 13:50:28 +010077 // When targeting 1.9 and above, override the modules to use with --system,
78 // otherwise provides defaults libraries to add to the bootclasspath.
79 // Defaults to "none"
80 System_modules *string
81
Jiyong Park1e440682018-05-23 18:42:04 +090082 Aidl struct {
83 // Top level directories to pass to aidl tool
84 Include_dirs []string
85
86 // Directories rooted at the Android.bp file to pass to aidl tool
87 Local_include_dirs []string
88 }
Nan Zhang357466b2018-04-17 17:38:36 -070089
90 // If not blank, set the java version passed to javadoc as -source
91 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -070092
93 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -080094 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -070095
96 // user customized droiddoc args.
97 // Available variables for substitution:
98 //
99 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700100 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700101 Args *string
102
103 // names of the output files used in args that will be generated
104 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800105}
106
Nan Zhang61819ce2018-05-04 18:49:16 -0700107type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900108 // path to the API txt file that the new API extracted from source code is checked
109 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800110 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700111
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900112 // path to the API txt file that the new @removed API extractd from source code is
113 // checked against. The path can be local to the module or from other module (via
114 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800115 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700116
Adrian Roos14f75a92019-08-12 17:54:09 +0200117 // If not blank, path to the baseline txt file for approved API check violations.
118 Baseline_file *string `android:"path"`
119
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900120 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700121 Args *string
122}
123
Nan Zhang581fd212018-01-10 16:06:12 -0800124type DroiddocProperties struct {
125 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800126 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800127
Nan Zhanga40da042018-08-01 12:48:00 -0700128 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800129 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800130
131 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // proofread file contains all of the text content of the javadocs concatenated into one file,
135 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700136 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800137
138 // a todo file lists the program elements that are missing documentation.
139 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800140 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800141
142 // directory under current module source that provide additional resources (images).
143 Resourcesdir *string
144
145 // resources output directory under out/soong/.intermediates.
146 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800147
Nan Zhange2ba5d42018-07-11 15:16:55 -0700148 // if set to true, collect the values used by the Dev tools and
149 // write them in files packaged with the SDK. Defaults to false.
150 Write_sdk_values *bool
151
152 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800153 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700154
155 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800156 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700157
Nan Zhang581fd212018-01-10 16:06:12 -0800158 // a list of files under current module source dir which contains known tags in Java sources.
159 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800160 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700161
162 // the tag name used to distinguish if the API files belong to public/system/test.
163 Api_tag_name *string
164
165 // the generated public API filename by Doclava.
166 Api_filename *string
167
David Brazdilfbe4cc32018-05-31 13:56:46 +0100168 // the generated public Dex API filename by Doclava.
169 Dex_api_filename *string
170
Nan Zhang28c68b92018-03-13 16:17:01 -0700171 // the generated private API filename by Doclava.
172 Private_api_filename *string
173
174 // the generated private Dex API filename by Doclava.
175 Private_dex_api_filename *string
176
177 // the generated removed API filename by Doclava.
178 Removed_api_filename *string
179
David Brazdilaac0c3c2018-04-24 16:23:29 +0100180 // the generated removed Dex API filename by Doclava.
181 Removed_dex_api_filename *string
182
Mathew Inwood76c3de12018-06-22 15:28:11 +0100183 // mapping of dex signatures to source file and line number. This is a temporary property and
184 // will be deleted; you probably shouldn't be using it.
185 Dex_mapping_filename *string
186
Nan Zhang28c68b92018-03-13 16:17:01 -0700187 // the generated exact API filename by Doclava.
188 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700189
Nan Zhang66dc2362018-08-14 20:41:04 -0700190 // the generated proguard filename by Doclava.
191 Proguard_filename *string
192
Nan Zhang853f4202018-04-12 16:55:56 -0700193 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
194 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700195
196 Check_api struct {
197 Last_released ApiToCheck
198
199 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900200
201 // do not perform API check against Last_released, in the case that both two specified API
202 // files by Last_released are modules which don't exist.
203 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700204 }
Nan Zhang79614d12018-04-19 18:03:39 -0700205
Nan Zhang1598a9e2018-09-04 17:14:32 -0700206 // if set to true, generate docs through Dokka instead of Doclava.
207 Dokka_enabled *bool
208}
209
210type DroidstubsProperties struct {
211 // the tag name used to distinguish if the API files belong to public/system/test.
212 Api_tag_name *string
213
Nan Zhang199645c2018-09-19 12:40:06 -0700214 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700215 Api_filename *string
216
Nan Zhang199645c2018-09-19 12:40:06 -0700217 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700218 Dex_api_filename *string
219
Nan Zhang199645c2018-09-19 12:40:06 -0700220 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700221 Private_api_filename *string
222
Nan Zhang199645c2018-09-19 12:40:06 -0700223 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700224 Private_dex_api_filename *string
225
Nan Zhang199645c2018-09-19 12:40:06 -0700226 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700227 Removed_api_filename *string
228
Nan Zhang199645c2018-09-19 12:40:06 -0700229 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700230 Removed_dex_api_filename *string
231
Nan Zhang9c69a122018-08-22 10:22:08 -0700232 // mapping of dex signatures to source file and line number. This is a temporary property and
233 // will be deleted; you probably shouldn't be using it.
234 Dex_mapping_filename *string
235
Nan Zhang199645c2018-09-19 12:40:06 -0700236 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700237 Exact_api_filename *string
238
Nan Zhang199645c2018-09-19 12:40:06 -0700239 // the generated proguard filename by Metalava.
240 Proguard_filename *string
241
Nan Zhang1598a9e2018-09-04 17:14:32 -0700242 Check_api struct {
243 Last_released ApiToCheck
244
245 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900246
247 // do not perform API check against Last_released, in the case that both two specified API
248 // files by Last_released are modules which don't exist.
249 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200250
251 Api_lint struct {
252 Enabled *bool
253
254 // If set, performs api_lint on any new APIs not found in the given signature file
255 New_since *string `android:"path"`
256
257 // If not blank, path to the baseline txt file for approved API lint violations.
258 Baseline_file *string `android:"path"`
259 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700260 }
Nan Zhang79614d12018-04-19 18:03:39 -0700261
262 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800263 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700264
265 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700266 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700267
Pete Gillin77167902018-09-19 18:16:26 +0100268 // 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 -0700269 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700270
Pete Gillin77167902018-09-19 18:16:26 +0100271 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
272 Merge_inclusion_annotations_dirs []string
273
Pete Gillinc382a562018-11-14 18:45:46 +0000274 // a file containing a list of classes to do nullability validation for.
275 Validate_nullability_from_list *string
276
Pete Gillin581d6082018-10-22 15:55:04 +0100277 // a file containing expected warnings produced by validation of nullability annotations.
278 Check_nullability_warnings *string
279
Nan Zhang1598a9e2018-09-04 17:14:32 -0700280 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
281 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700282
283 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
284 Api_levels_annotations_enabled *bool
285
286 // the dirs which Metalava extracts API levels annotations from.
287 Api_levels_annotations_dirs []string
288
289 // if set to true, collect the values used by the Dev tools and
290 // write them in files packaged with the SDK. Defaults to false.
291 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700292
293 // If set to true, .xml based public API file will be also generated, and
294 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
295 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800296}
297
Nan Zhanga40da042018-08-01 12:48:00 -0700298//
299// Common flags passed down to build rule
300//
301type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700302 bootClasspathArgs string
303 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700304 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700305 dokkaClasspathArgs string
306 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700307 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700308
Nan Zhanga40da042018-08-01 12:48:00 -0700309 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700310 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700311 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700312}
313
314func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
315 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
316 android.InitDefaultableModule(module)
317}
318
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200319func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
320 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
321 return false
322 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700323 return true
324 } else if String(apiToCheck.Api_file) != "" {
325 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
326 } else if String(apiToCheck.Removed_api_file) != "" {
327 panic("for " + apiVersionTag + " api_file has to be non-empty!")
328 }
329
330 return false
331}
332
Inseob Kim38449af2019-02-28 14:24:05 +0900333func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
334 api_file := String(apiToCheck.Api_file)
335 removed_api_file := String(apiToCheck.Removed_api_file)
336
337 api_module := android.SrcIsModule(api_file)
338 removed_api_module := android.SrcIsModule(removed_api_file)
339
340 if api_module == "" || removed_api_module == "" {
341 return
342 }
343
344 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
345 return
346 }
347
348 apiToCheck.Api_file = nil
349 apiToCheck.Removed_api_file = nil
350}
351
Nan Zhang1598a9e2018-09-04 17:14:32 -0700352type ApiFilePath interface {
353 ApiFilePath() android.Path
354}
355
Nan Zhanga40da042018-08-01 12:48:00 -0700356//
357// Javadoc
358//
Nan Zhang581fd212018-01-10 16:06:12 -0800359type Javadoc struct {
360 android.ModuleBase
361 android.DefaultableModuleBase
362
363 properties JavadocProperties
364
365 srcJars android.Paths
366 srcFiles android.Paths
367 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700368 argFiles android.Paths
369
370 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800371
Nan Zhangccff0f72018-03-08 17:26:16 -0800372 docZip android.WritablePath
373 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800374}
375
Colin Cross41955e82019-05-29 14:40:35 -0700376func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
377 switch tag {
378 case "":
379 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700380 case ".docs.zip":
381 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700382 default:
383 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
384 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800385}
386
Colin Crossa3002fc2019-07-08 16:48:04 -0700387// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800388func JavadocFactory() android.Module {
389 module := &Javadoc{}
390
391 module.AddProperties(&module.properties)
392
393 InitDroiddocModule(module, android.HostAndDeviceSupported)
394 return module
395}
396
Colin Crossa3002fc2019-07-08 16:48:04 -0700397// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800398func JavadocHostFactory() android.Module {
399 module := &Javadoc{}
400
401 module.AddProperties(&module.properties)
402
403 InitDroiddocModule(module, android.HostSupported)
404 return module
405}
406
Colin Cross41955e82019-05-29 14:40:35 -0700407var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800408
Colin Cross83bb3162018-06-25 15:48:06 -0700409func (j *Javadoc) sdkVersion() string {
Jeongik Cha2cc570d2019-10-29 15:44:45 +0900410 return String(j.properties.Sdk_version)
Colin Cross83bb3162018-06-25 15:48:06 -0700411}
412
Paul Duffine25c6442019-10-11 13:50:28 +0100413func (j *Javadoc) systemModules() string {
414 return proptools.String(j.properties.System_modules)
415}
416
Colin Cross83bb3162018-06-25 15:48:06 -0700417func (j *Javadoc) minSdkVersion() string {
418 return j.sdkVersion()
419}
420
Dan Willemsen419290a2018-10-31 15:28:47 -0700421func (j *Javadoc) targetSdkVersion() string {
422 return j.sdkVersion()
423}
424
Nan Zhang581fd212018-01-10 16:06:12 -0800425func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
426 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100427 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700428 if sdkDep.useDefaultLibs {
429 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
430 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
431 if sdkDep.hasFrameworkLibs() {
432 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700433 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700434 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700435 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100436 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700437 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800438 }
439 }
440
Colin Cross42d48b72018-08-29 14:10:52 -0700441 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800442}
443
Nan Zhanga40da042018-08-01 12:48:00 -0700444func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
445 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900446
Colin Cross3047fa22019-04-18 10:56:44 -0700447 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900448
449 return flags
450}
451
452func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700453 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900454
455 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
456 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
457
458 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700459 var deps android.Paths
460
Jiyong Park1e440682018-05-23 18:42:04 +0900461 if aidlPreprocess.Valid() {
462 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700463 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900464 } else {
465 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
466 }
467
468 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
469 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
470 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
471 flags = append(flags, "-I"+src.String())
472 }
473
Colin Cross3047fa22019-04-18 10:56:44 -0700474 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900475}
476
Jiyong Parkd90d7412019-08-20 22:49:19 +0900477// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900478func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700479 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900480
481 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700482 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900483
Jiyong Park1112c4c2019-08-16 21:12:10 +0900484 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
485
Jiyong Park1e440682018-05-23 18:42:04 +0900486 for _, srcFile := range srcFiles {
487 switch srcFile.Ext() {
488 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700489 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900490 case ".logtags":
491 javaFile := genLogtags(ctx, srcFile)
492 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900493 default:
494 outSrcFiles = append(outSrcFiles, srcFile)
495 }
496 }
497
Colin Crossc0806172019-06-14 18:51:47 -0700498 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
499 if len(aidlSrcs) > 0 {
500 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
501 outSrcFiles = append(outSrcFiles, srcJarFiles...)
502 }
503
Jiyong Park1e440682018-05-23 18:42:04 +0900504 return outSrcFiles
505}
506
Nan Zhang581fd212018-01-10 16:06:12 -0800507func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
508 var deps deps
509
Colin Cross83bb3162018-06-25 15:48:06 -0700510 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800511 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700512 ctx.AddMissingDependencies(sdkDep.bootclasspath)
513 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800514 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700515 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800516 }
517
518 ctx.VisitDirectDeps(func(module android.Module) {
519 otherName := ctx.OtherModuleName(module)
520 tag := ctx.OtherModuleDependencyTag(module)
521
Colin Cross2d24c1b2018-05-23 10:59:18 -0700522 switch tag {
523 case bootClasspathTag:
524 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800525 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffine25c6442019-10-11 13:50:28 +0100526 } else if sm, ok := module.(*SystemModules); ok {
527 // A system modules dependency has been added to the bootclasspath
528 // so add its libs to the bootclasspath.
529 deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700530 } else {
531 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
532 }
533 case libTag:
534 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800535 case SdkLibraryDependency:
536 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700537 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900538 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900539 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700540 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800541 checkProducesJars(ctx, dep)
542 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800543 default:
544 ctx.ModuleErrorf("depends on non-java module %q", otherName)
545 }
Colin Cross6cef4812019-10-17 14:23:50 -0700546 case java9LibTag:
547 switch dep := module.(type) {
548 case Dependency:
549 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
550 default:
551 ctx.ModuleErrorf("depends on non-java module %q", otherName)
552 }
Nan Zhang357466b2018-04-17 17:38:36 -0700553 case systemModulesTag:
554 if deps.systemModules != nil {
555 panic("Found two system module dependencies")
556 }
557 sm := module.(*SystemModules)
Dan Willemsenff60a732019-06-13 16:52:01 +0000558 if sm.outputDir == nil && len(sm.outputDeps) == 0 {
Nan Zhang357466b2018-04-17 17:38:36 -0700559 panic("Missing directory for system module dependency")
560 }
Colin Crossb77043e2019-07-16 13:57:13 -0700561 deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800562 }
563 })
564 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
565 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800566 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900567
568 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
569 if filterPackages == nil {
570 return srcs
571 }
572 filtered := []android.Path{}
573 for _, src := range srcs {
574 if src.Ext() != ".java" {
575 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
576 // but otherwise metalava emits stub sources having references to the generated AIDL classes
577 // in filtered-out pacages (e.g. com.android.internal.*).
578 // TODO(b/141149570) We need to fix this by introducing default private constructors or
579 // fixing metalava to not emit constructors having references to unknown classes.
580 filtered = append(filtered, src)
581 continue
582 }
583 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
584 for _, pkg := range filterPackages {
585 if strings.HasPrefix(packageName, pkg) {
586 filtered = append(filtered, src)
587 break
588 }
589 }
590 }
591 return filtered
592 }
593 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
594
Nan Zhanga40da042018-08-01 12:48:00 -0700595 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900596 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800597
598 // srcs may depend on some genrule output.
599 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800600 j.srcJars = append(j.srcJars, deps.srcJars...)
601
Nan Zhang581fd212018-01-10 16:06:12 -0800602 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800603 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800604
Nan Zhang9c69a122018-08-22 10:22:08 -0700605 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800606 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
607 }
608 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800609
Colin Cross8a497952019-03-05 22:25:09 -0800610 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000611 argFilesMap := map[string]string{}
612 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700613
Paul Duffin99e4a502019-02-11 15:38:42 +0000614 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800615 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000616 if _, exists := argFilesMap[label]; !exists {
617 argFilesMap[label] = strings.Join(paths.Strings(), " ")
618 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700619 } else {
620 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000621 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700622 }
623 }
624
625 var err error
Colin Cross15638152019-07-11 11:11:35 -0700626 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700627 if strings.HasPrefix(name, "location ") {
628 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000629 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700630 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700631 } else {
Colin Cross15638152019-07-11 11:11:35 -0700632 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000633 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 }
635 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700636 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700637 }
Colin Cross15638152019-07-11 11:11:35 -0700638 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700639 })
640
641 if err != nil {
642 ctx.PropertyErrorf("args", "%s", err.Error())
643 }
644
Nan Zhang581fd212018-01-10 16:06:12 -0800645 return deps
646}
647
648func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
649 j.addDeps(ctx)
650}
651
652func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
653 deps := j.collectDeps(ctx)
654
Colin Crossdaa4c672019-07-15 22:53:46 -0700655 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800656
Colin Crossdaa4c672019-07-15 22:53:46 -0700657 outDir := android.PathForModuleOut(ctx, "out")
658 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
659
660 j.stubsSrcJar = nil
661
662 rule := android.NewRuleBuilder()
663
664 rule.Command().Text("rm -rf").Text(outDir.String())
665 rule.Command().Text("mkdir -p").Text(outDir.String())
666
667 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700668
Colin Cross83bb3162018-06-25 15:48:06 -0700669 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800670
Colin Crossdaa4c672019-07-15 22:53:46 -0700671 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
672 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800673
Colin Cross1e743852019-10-28 11:37:20 -0700674 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700675 Flag("-J-Xmx1024m").
676 Flag("-XDignore.symbol.file").
677 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800678
Colin Crossdaa4c672019-07-15 22:53:46 -0700679 rule.Command().
680 BuiltTool(ctx, "soong_zip").
681 Flag("-write_if_changed").
682 Flag("-d").
683 FlagWithOutput("-o ", j.docZip).
684 FlagWithArg("-C ", outDir.String()).
685 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700686
Colin Crossdaa4c672019-07-15 22:53:46 -0700687 rule.Restat()
688
689 zipSyncCleanupCmd(rule, srcJarDir)
690
691 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800692}
693
Nan Zhanga40da042018-08-01 12:48:00 -0700694//
695// Droiddoc
696//
697type Droiddoc struct {
698 Javadoc
699
700 properties DroiddocProperties
701 apiFile android.WritablePath
702 dexApiFile android.WritablePath
703 privateApiFile android.WritablePath
704 privateDexApiFile android.WritablePath
705 removedApiFile android.WritablePath
706 removedDexApiFile android.WritablePath
707 exactApiFile android.WritablePath
708 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700709 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700710
711 checkCurrentApiTimestamp android.WritablePath
712 updateCurrentApiTimestamp android.WritablePath
713 checkLastReleasedApiTimestamp android.WritablePath
714
Nan Zhanga40da042018-08-01 12:48:00 -0700715 apiFilePath android.Path
716}
717
Colin Crossa3002fc2019-07-08 16:48:04 -0700718// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700719func DroiddocFactory() android.Module {
720 module := &Droiddoc{}
721
722 module.AddProperties(&module.properties,
723 &module.Javadoc.properties)
724
725 InitDroiddocModule(module, android.HostAndDeviceSupported)
726 return module
727}
728
Colin Crossa3002fc2019-07-08 16:48:04 -0700729// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700730func DroiddocHostFactory() android.Module {
731 module := &Droiddoc{}
732
733 module.AddProperties(&module.properties,
734 &module.Javadoc.properties)
735
736 InitDroiddocModule(module, android.HostSupported)
737 return module
738}
739
740func (d *Droiddoc) ApiFilePath() android.Path {
741 return d.apiFilePath
742}
743
Nan Zhang581fd212018-01-10 16:06:12 -0800744func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
745 d.Javadoc.addDeps(ctx)
746
Inseob Kim38449af2019-02-28 14:24:05 +0900747 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
748 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
749 }
750
Nan Zhang79614d12018-04-19 18:03:39 -0700751 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800752 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
753 }
Nan Zhang581fd212018-01-10 16:06:12 -0800754}
755
Colin Crossab054432019-07-15 16:13:59 -0700756func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Nan Zhang443fa522018-08-20 20:58:28 -0700757 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
758 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
759 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700760 cmd.FlagWithArg("-source ", "1.8").
761 Flag("-J-Xmx1600m").
762 Flag("-J-XX:-OmitStackTraceInFastThrow").
763 Flag("-XDignore.symbol.file").
764 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
765 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
766 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
Elliott Hughes26bce342019-09-12 15:05:13 -0700767 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 -0700768
Nan Zhanga40da042018-08-01 12:48:00 -0700769 if String(d.properties.Custom_template) == "" {
770 // TODO: This is almost always droiddoc-templates-sdk
771 ctx.PropertyErrorf("custom_template", "must specify a template")
772 }
773
774 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700775 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700776 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700777 } else {
778 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
779 }
780 })
781
782 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700783 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
784 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
785 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700786 }
787
788 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700789 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
790 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
791 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700792 }
793
794 if len(d.properties.Html_dirs) > 2 {
795 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
796 }
797
Colin Cross8a497952019-03-05 22:25:09 -0800798 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700799 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700800
Colin Crossab054432019-07-15 16:13:59 -0700801 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700802
803 if String(d.properties.Proofread_file) != "" {
804 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700805 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700806 }
807
808 if String(d.properties.Todo_file) != "" {
809 // tricky part:
810 // we should not compute full path for todo_file through PathForModuleOut().
811 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700812 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
813 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700814 }
815
816 if String(d.properties.Resourcesdir) != "" {
817 // TODO: should we add files under resourcesDir to the implicits? It seems that
818 // resourcesDir is one sub dir of htmlDir
819 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700820 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700821 }
822
823 if String(d.properties.Resourcesoutdir) != "" {
824 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700825 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700826 }
Nan Zhanga40da042018-08-01 12:48:00 -0700827}
828
Colin Crossab054432019-07-15 16:13:59 -0700829func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200830 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
831 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700832 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700833
Nan Zhanga40da042018-08-01 12:48:00 -0700834 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700835 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700836 d.apiFilePath = d.apiFile
837 }
838
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200839 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
840 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700841 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700842 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700843 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700844 }
845
846 if String(d.properties.Private_api_filename) != "" {
847 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700848 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700849 }
850
851 if String(d.properties.Dex_api_filename) != "" {
852 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700853 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700854 }
855
856 if String(d.properties.Private_dex_api_filename) != "" {
857 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700858 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700859 }
860
861 if String(d.properties.Removed_dex_api_filename) != "" {
862 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700863 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700864 }
865
866 if String(d.properties.Exact_api_filename) != "" {
867 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700868 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700869 }
870
871 if String(d.properties.Dex_mapping_filename) != "" {
872 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700873 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700874 }
875
Nan Zhang66dc2362018-08-14 20:41:04 -0700876 if String(d.properties.Proguard_filename) != "" {
877 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700878 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700879 }
880
Nan Zhanga40da042018-08-01 12:48:00 -0700881 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700882 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700883 }
884
885 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700886 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700887 }
Nan Zhanga40da042018-08-01 12:48:00 -0700888}
889
Colin Crossab054432019-07-15 16:13:59 -0700890func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700891 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700892 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
893 rule.Command().Text("cp").
894 Input(staticDocIndexRedirect).
895 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700896 }
897
898 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700899 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
900 rule.Command().Text("cp").
901 Input(staticDocProperties).
902 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700903 }
Nan Zhanga40da042018-08-01 12:48:00 -0700904}
905
Colin Crossab054432019-07-15 16:13:59 -0700906func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700907 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700908
909 cmd := rule.Command().
910 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
911 Flag(config.JavacVmFlags).
912 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700913 FlagWithRspFileInputList("@", srcs).
914 FlagWithInput("@", srcJarList)
915
Colin Crossab054432019-07-15 16:13:59 -0700916 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
917 // based stubs generation.
918 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
919 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
920 // the correct package name base path.
921 if len(sourcepaths) > 0 {
922 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
923 } else {
924 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
925 }
926
927 cmd.FlagWithArg("-d ", outDir.String()).
928 Flag("-quiet")
929
930 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700931}
932
Colin Crossdaa4c672019-07-15 22:53:46 -0700933func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
934 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
935 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
936
937 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
938
939 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
940 cmd.Flag(flag).Implicits(deps)
941
942 cmd.FlagWithArg("--patch-module ", "java.base=.")
943
944 if len(classpath) > 0 {
945 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
946 }
947
948 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700949}
950
Colin Crossdaa4c672019-07-15 22:53:46 -0700951func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
952 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
953 sourcepaths android.Paths) *android.RuleBuilderCommand {
954
955 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
956
957 if len(bootclasspath) == 0 && ctx.Device() {
958 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
959 // ensure java does not fall back to the default bootclasspath.
960 cmd.FlagWithArg("-bootclasspath ", `""`)
961 } else if len(bootclasspath) > 0 {
962 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
963 }
964
965 if len(classpath) > 0 {
966 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
967 }
968
969 return cmd
970}
971
Colin Crossab054432019-07-15 16:13:59 -0700972func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
973 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700974
Colin Crossab054432019-07-15 16:13:59 -0700975 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
976 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
977
978 return rule.Command().
979 BuiltTool(ctx, "dokka").
980 Flag(config.JavacVmFlags).
981 Flag(srcJarDir.String()).
982 FlagWithInputList("-classpath ", dokkaClasspath, ":").
983 FlagWithArg("-format ", "dac").
984 FlagWithArg("-dacRoot ", "/reference/kotlin").
985 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700986}
987
988func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
989 deps := d.Javadoc.collectDeps(ctx)
990
Colin Crossdaa4c672019-07-15 22:53:46 -0700991 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
992 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
993
Nan Zhang1598a9e2018-09-04 17:14:32 -0700994 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
995 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
996 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
997 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
998
Colin Crossab054432019-07-15 16:13:59 -0700999 outDir := android.PathForModuleOut(ctx, "out")
1000 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1001 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001002
Colin Crossab054432019-07-15 16:13:59 -07001003 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001004
Colin Crossab054432019-07-15 16:13:59 -07001005 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1006 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001007
Colin Crossab054432019-07-15 16:13:59 -07001008 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1009
1010 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001011 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001012 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001013 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001014 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001015 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001016 }
1017
Colin Crossab054432019-07-15 16:13:59 -07001018 d.stubsFlags(ctx, cmd, stubsDir)
1019
1020 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1021
1022 var desc string
1023 if Bool(d.properties.Dokka_enabled) {
1024 desc = "dokka"
1025 } else {
1026 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1027
1028 for _, o := range d.Javadoc.properties.Out {
1029 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1030 }
1031
1032 d.postDoclavaCmds(ctx, rule)
1033 desc = "doclava"
1034 }
1035
1036 rule.Command().
1037 BuiltTool(ctx, "soong_zip").
1038 Flag("-write_if_changed").
1039 Flag("-d").
1040 FlagWithOutput("-o ", d.docZip).
1041 FlagWithArg("-C ", outDir.String()).
1042 FlagWithArg("-D ", outDir.String())
1043
1044 rule.Command().
1045 BuiltTool(ctx, "soong_zip").
1046 Flag("-write_if_changed").
1047 Flag("-jar").
1048 FlagWithOutput("-o ", d.stubsSrcJar).
1049 FlagWithArg("-C ", stubsDir.String()).
1050 FlagWithArg("-D ", stubsDir.String())
1051
1052 rule.Restat()
1053
1054 zipSyncCleanupCmd(rule, srcJarDir)
1055
1056 rule.Build(pctx, ctx, "javadoc", desc)
1057
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001058 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001059 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001060
1061 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1062 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001063
1064 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001065
1066 rule := android.NewRuleBuilder()
1067
1068 rule.Command().Text("( true")
1069
1070 rule.Command().
1071 BuiltTool(ctx, "apicheck").
1072 Flag("-JXmx1024m").
1073 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1074 OptionalFlag(d.properties.Check_api.Current.Args).
1075 Input(apiFile).
1076 Input(d.apiFile).
1077 Input(removedApiFile).
1078 Input(d.removedApiFile)
1079
1080 msg := fmt.Sprintf(`\n******************************\n`+
1081 `You have tried to change the API from what has been previously approved.\n\n`+
1082 `To make these errors go away, you have two choices:\n`+
1083 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1084 ` errors above.\n\n`+
1085 ` 2. You can update current.txt by executing the following command:\n`+
1086 ` make %s-update-current-api\n\n`+
1087 ` To submit the revised current.txt to the main Android repository,\n`+
1088 ` you will need approval.\n`+
1089 `******************************\n`, ctx.ModuleName())
1090
1091 rule.Command().
1092 Text("touch").Output(d.checkCurrentApiTimestamp).
1093 Text(") || (").
1094 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1095 Text("; exit 38").
1096 Text(")")
1097
1098 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001099
1100 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001101
1102 // update API rule
1103 rule = android.NewRuleBuilder()
1104
1105 rule.Command().Text("( true")
1106
1107 rule.Command().
1108 Text("cp").Flag("-f").
1109 Input(d.apiFile).Flag(apiFile.String())
1110
1111 rule.Command().
1112 Text("cp").Flag("-f").
1113 Input(d.removedApiFile).Flag(removedApiFile.String())
1114
1115 msg = "failed to update public API"
1116
1117 rule.Command().
1118 Text("touch").Output(d.updateCurrentApiTimestamp).
1119 Text(") || (").
1120 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1121 Text("; exit 38").
1122 Text(")")
1123
1124 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001125 }
1126
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001127 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001128 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001129
1130 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1131 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001132
1133 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001134
1135 rule := android.NewRuleBuilder()
1136
1137 rule.Command().
1138 Text("(").
1139 BuiltTool(ctx, "apicheck").
1140 Flag("-JXmx1024m").
1141 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1142 OptionalFlag(d.properties.Check_api.Last_released.Args).
1143 Input(apiFile).
1144 Input(d.apiFile).
1145 Input(removedApiFile).
1146 Input(d.removedApiFile)
1147
1148 msg := `\n******************************\n` +
1149 `You have tried to change the API from what has been previously released in\n` +
1150 `an SDK. Please fix the errors listed above.\n` +
1151 `******************************\n`
1152
1153 rule.Command().
1154 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1155 Text(") || (").
1156 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1157 Text("; exit 38").
1158 Text(")")
1159
1160 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001161 }
1162}
1163
1164//
1165// Droidstubs
1166//
1167type Droidstubs struct {
1168 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001169 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001170
Pete Gillin581d6082018-10-22 15:55:04 +01001171 properties DroidstubsProperties
1172 apiFile android.WritablePath
1173 apiXmlFile android.WritablePath
1174 lastReleasedApiXmlFile android.WritablePath
1175 dexApiFile android.WritablePath
1176 privateApiFile android.WritablePath
1177 privateDexApiFile android.WritablePath
1178 removedApiFile android.WritablePath
1179 removedDexApiFile android.WritablePath
1180 apiMappingFile android.WritablePath
1181 exactApiFile android.WritablePath
1182 proguardFile android.WritablePath
1183 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001184
1185 checkCurrentApiTimestamp android.WritablePath
1186 updateCurrentApiTimestamp android.WritablePath
1187 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001188 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001189 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001190
Pete Gillin581d6082018-10-22 15:55:04 +01001191 checkNullabilityWarningsTimestamp android.WritablePath
1192
Nan Zhang1598a9e2018-09-04 17:14:32 -07001193 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001194 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001195
1196 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001197
1198 jdiffDocZip android.WritablePath
1199 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001200
1201 metadataZip android.WritablePath
1202 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001203}
1204
Colin Crossa3002fc2019-07-08 16:48:04 -07001205// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1206// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1207// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001208func DroidstubsFactory() android.Module {
1209 module := &Droidstubs{}
1210
1211 module.AddProperties(&module.properties,
1212 &module.Javadoc.properties)
1213
1214 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001215 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001216 return module
1217}
1218
Colin Crossa3002fc2019-07-08 16:48:04 -07001219// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1220// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1221// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1222// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001223func DroidstubsHostFactory() android.Module {
1224 module := &Droidstubs{}
1225
1226 module.AddProperties(&module.properties,
1227 &module.Javadoc.properties)
1228
1229 InitDroiddocModule(module, android.HostSupported)
1230 return module
1231}
1232
1233func (d *Droidstubs) ApiFilePath() android.Path {
1234 return d.apiFilePath
1235}
1236
1237func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1238 d.Javadoc.addDeps(ctx)
1239
Inseob Kim38449af2019-02-28 14:24:05 +09001240 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1241 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1242 }
1243
Nan Zhang1598a9e2018-09-04 17:14:32 -07001244 if len(d.properties.Merge_annotations_dirs) != 0 {
1245 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1246 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1247 }
1248 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001249
Pete Gillin77167902018-09-19 18:16:26 +01001250 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1251 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1252 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1253 }
1254 }
1255
Nan Zhang9c69a122018-08-22 10:22:08 -07001256 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1257 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1258 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1259 }
1260 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001261}
1262
Colin Cross33961b52019-07-11 11:01:22 -07001263func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001264 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1265 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001266 String(d.properties.Api_filename) != "" {
1267 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001268 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001269 d.apiFilePath = d.apiFile
1270 }
1271
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001272 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1273 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001274 String(d.properties.Removed_api_filename) != "" {
1275 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001276 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001277 }
1278
1279 if String(d.properties.Private_api_filename) != "" {
1280 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001281 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001282 }
1283
1284 if String(d.properties.Dex_api_filename) != "" {
1285 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001286 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001287 }
1288
1289 if String(d.properties.Private_dex_api_filename) != "" {
1290 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001291 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001292 }
1293
1294 if String(d.properties.Removed_dex_api_filename) != "" {
1295 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001296 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001297 }
1298
1299 if String(d.properties.Exact_api_filename) != "" {
1300 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001301 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001302 }
1303
Nan Zhang9c69a122018-08-22 10:22:08 -07001304 if String(d.properties.Dex_mapping_filename) != "" {
1305 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001306 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001307 }
1308
Nan Zhang199645c2018-09-19 12:40:06 -07001309 if String(d.properties.Proguard_filename) != "" {
1310 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001311 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001312 }
1313
Nan Zhang9c69a122018-08-22 10:22:08 -07001314 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001315 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1316 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001317 }
1318
Nan Zhang1598a9e2018-09-04 17:14:32 -07001319 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001320 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001321 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001322 cmd.FlagWithArg("--stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001323 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001324}
1325
Colin Cross33961b52019-07-11 11:01:22 -07001326func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001327 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001328 cmd.Flag("--include-annotations")
1329
Pete Gillinc382a562018-11-14 18:45:46 +00001330 validatingNullability :=
1331 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1332 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001333
Pete Gillina262c052018-09-14 14:25:48 +01001334 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001335 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001336 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001337 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001338 }
Colin Cross33961b52019-07-11 11:01:22 -07001339
Pete Gillinc382a562018-11-14 18:45:46 +00001340 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001341 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001342 }
Colin Cross33961b52019-07-11 11:01:22 -07001343
Pete Gillina262c052018-09-14 14:25:48 +01001344 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001345 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001346 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001347 }
Nan Zhanga40da042018-08-01 12:48:00 -07001348
1349 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001350 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001351
Nan Zhang1598a9e2018-09-04 17:14:32 -07001352 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001353 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001354 "has to be non-empty if annotations was enabled!")
1355 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001356
Colin Cross33961b52019-07-11 11:01:22 -07001357 d.mergeAnnoDirFlags(ctx, cmd)
1358
1359 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1360 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1361 FlagWithArg("--hide ", "SuperfluousPrefix").
1362 FlagWithArg("--hide ", "AnnotationExtraction")
1363 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001364}
1365
Colin Cross33961b52019-07-11 11:01:22 -07001366func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1367 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1368 if t, ok := m.(*ExportedDroiddocDir); ok {
1369 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1370 } else {
1371 ctx.PropertyErrorf("merge_annotations_dirs",
1372 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1373 }
1374 })
1375}
1376
1377func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001378 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1379 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001380 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001381 } else {
1382 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1383 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1384 }
1385 })
Nan Zhanga40da042018-08-01 12:48:00 -07001386}
1387
Colin Cross33961b52019-07-11 11:01:22 -07001388func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001389 if Bool(d.properties.Api_levels_annotations_enabled) {
1390 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001391
1392 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1393 ctx.PropertyErrorf("api_levels_annotations_dirs",
1394 "has to be non-empty if api levels annotations was enabled!")
1395 }
1396
Colin Cross33961b52019-07-11 11:01:22 -07001397 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1398 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1399 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1400 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001401
1402 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1403 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001404 for _, dep := range t.deps {
1405 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001406 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001407 }
1408 }
Colin Cross33961b52019-07-11 11:01:22 -07001409 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001410 } else {
1411 ctx.PropertyErrorf("api_levels_annotations_dirs",
1412 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1413 }
1414 })
1415
1416 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001417}
1418
Colin Cross33961b52019-07-11 11:01:22 -07001419func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001420 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1421 if d.apiFile.String() == "" {
1422 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1423 }
1424
1425 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001426 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001427
1428 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1429 ctx.PropertyErrorf("check_api.last_released.api_file",
1430 "has to be non-empty if jdiff was enabled!")
1431 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001432
Colin Cross33961b52019-07-11 11:01:22 -07001433 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001434 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001435 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1436 }
1437}
Nan Zhang71bbe632018-09-17 14:32:21 -07001438
Colin Cross1e743852019-10-28 11:37:20 -07001439func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001440 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
1441 cmd := rule.Command().BuiltTool(ctx, "metalava").
1442 Flag(config.JavacVmFlags).
1443 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001444 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001445 FlagWithRspFileInputList("@", srcs).
1446 FlagWithInput("@", srcJarList)
1447
1448 if len(bootclasspath) > 0 {
1449 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001450 }
1451
Colin Cross33961b52019-07-11 11:01:22 -07001452 if len(classpath) > 0 {
1453 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1454 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001455
Colin Cross33961b52019-07-11 11:01:22 -07001456 if len(sourcepaths) > 0 {
1457 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1458 } else {
1459 cmd.FlagWithArg("-sourcepath ", `""`)
1460 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001461
Colin Cross33961b52019-07-11 11:01:22 -07001462 cmd.Flag("--no-banner").
1463 Flag("--color").
1464 Flag("--quiet").
1465 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001466
Colin Cross33961b52019-07-11 11:01:22 -07001467 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001468}
1469
Nan Zhang1598a9e2018-09-04 17:14:32 -07001470func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001471 deps := d.Javadoc.collectDeps(ctx)
1472
1473 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001474
Colin Cross33961b52019-07-11 11:01:22 -07001475 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001476
Colin Crossdaa4c672019-07-15 22:53:46 -07001477 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001478
Colin Cross33961b52019-07-11 11:01:22 -07001479 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1480 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001481
Colin Cross33961b52019-07-11 11:01:22 -07001482 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001483
Colin Cross33961b52019-07-11 11:01:22 -07001484 rule.Command().Text("rm -rf").Text(stubsDir.String())
1485 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001486
Colin Cross33961b52019-07-11 11:01:22 -07001487 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1488
1489 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1490 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1491
1492 d.stubsFlags(ctx, cmd, stubsDir)
1493
1494 d.annotationsFlags(ctx, cmd)
1495 d.inclusionAnnotationsFlags(ctx, cmd)
1496 d.apiLevelsAnnotationsFlags(ctx, cmd)
1497 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001498
Nan Zhang1598a9e2018-09-04 17:14:32 -07001499 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1500 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1501 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1502 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1503 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001504 }
Colin Cross33961b52019-07-11 11:01:22 -07001505
1506 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1507 for _, o := range d.Javadoc.properties.Out {
1508 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1509 }
1510
1511 rule.Command().
1512 BuiltTool(ctx, "soong_zip").
1513 Flag("-write_if_changed").
1514 Flag("-jar").
1515 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1516 FlagWithArg("-C ", stubsDir.String()).
1517 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001518
1519 if Bool(d.properties.Write_sdk_values) {
1520 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1521 rule.Command().
1522 BuiltTool(ctx, "soong_zip").
1523 Flag("-write_if_changed").
1524 Flag("-d").
1525 FlagWithOutput("-o ", d.metadataZip).
1526 FlagWithArg("-C ", d.metadataDir.String()).
1527 FlagWithArg("-D ", d.metadataDir.String())
1528 }
1529
Colin Cross33961b52019-07-11 11:01:22 -07001530 rule.Restat()
1531
1532 zipSyncCleanupCmd(rule, srcJarDir)
1533
1534 rule.Build(pctx, ctx, "metalava", "metalava")
1535
1536 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001537
Adrian Roos075eedc2019-10-10 12:07:03 +02001538 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1539 rule := android.NewRuleBuilder()
1540 rule.Command().Text("( true")
1541
1542 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1543 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1544
1545 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1546 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1547
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001548 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1549
Adrian Roos075eedc2019-10-10 12:07:03 +02001550 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1551 if newSince.Valid() {
1552 cmd.FlagWithInput("--api-lint ", newSince.Path())
1553 } else {
1554 cmd.Flag("--api-lint")
1555 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001556 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1557 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001558
1559 d.inclusionAnnotationsFlags(ctx, cmd)
1560 d.mergeAnnoDirFlags(ctx, cmd)
1561
1562 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1563 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1564 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1565
1566 if baselineFile.Valid() {
1567 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1568 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1569 }
1570
1571 zipSyncCleanupCmd(rule, srcJarDir)
1572
1573 msg := fmt.Sprintf(`\n******************************\n`+
1574 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1575 `To make these errors go away, you have two choices:\n`+
1576 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1577 ` 2. You can update the baseline by executing the following command:\n`+
1578 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1579 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1580 rule.Command().
1581 Text("touch").Output(d.apiLintTimestamp).
1582 Text(") || (").
1583 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1584 Text("; exit 38").
1585 Text(")")
1586
1587 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1588
1589 }
1590
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001591 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001592 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001593
1594 if len(d.Javadoc.properties.Out) > 0 {
1595 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1596 }
1597
1598 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1599 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001600 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1601 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001602
Nan Zhang2760dfc2018-08-24 17:32:54 +00001603 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001604
Colin Cross33961b52019-07-11 11:01:22 -07001605 rule := android.NewRuleBuilder()
1606
1607 rule.Command().Text("( true")
1608
1609 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1610 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1611
1612 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1613 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1614
1615 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1616 FlagWithInput("--check-compatibility:api:current ", apiFile).
1617 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1618
1619 d.inclusionAnnotationsFlags(ctx, cmd)
1620 d.mergeAnnoDirFlags(ctx, cmd)
1621
Adrian Roos14f75a92019-08-12 17:54:09 +02001622 if baselineFile.Valid() {
1623 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1624 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1625 }
1626
Colin Cross33961b52019-07-11 11:01:22 -07001627 zipSyncCleanupCmd(rule, srcJarDir)
1628
1629 msg := fmt.Sprintf(`\n******************************\n`+
1630 `You have tried to change the API from what has been previously approved.\n\n`+
1631 `To make these errors go away, you have two choices:\n`+
1632 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1633 ` errors above.\n\n`+
1634 ` 2. You can update current.txt by executing the following command:\n`+
1635 ` make %s-update-current-api\n\n`+
1636 ` To submit the revised current.txt to the main Android repository,\n`+
1637 ` you will need approval.\n`+
1638 `******************************\n`, ctx.ModuleName())
1639
1640 rule.Command().
1641 Text("touch").Output(d.checkCurrentApiTimestamp).
1642 Text(") || (").
1643 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1644 Text("; exit 38").
1645 Text(")")
1646
1647 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001648
1649 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001650
1651 // update API rule
1652 rule = android.NewRuleBuilder()
1653
1654 rule.Command().Text("( true")
1655
1656 rule.Command().
1657 Text("cp").Flag("-f").
1658 Input(d.apiFile).Flag(apiFile.String())
1659
1660 rule.Command().
1661 Text("cp").Flag("-f").
1662 Input(d.removedApiFile).Flag(removedApiFile.String())
1663
1664 msg = "failed to update public API"
1665
1666 rule.Command().
1667 Text("touch").Output(d.updateCurrentApiTimestamp).
1668 Text(") || (").
1669 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1670 Text("; exit 38").
1671 Text(")")
1672
1673 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001674 }
Nan Zhanga40da042018-08-01 12:48:00 -07001675
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001676 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001677 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001678
1679 if len(d.Javadoc.properties.Out) > 0 {
1680 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1681 }
1682
1683 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1684 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001685 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1686 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001687
Nan Zhang2760dfc2018-08-24 17:32:54 +00001688 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001689
Colin Cross33961b52019-07-11 11:01:22 -07001690 rule := android.NewRuleBuilder()
1691
1692 rule.Command().Text("( true")
1693
1694 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1695 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1696
1697 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1698 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1699
1700 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1701 FlagWithInput("--check-compatibility:api:released ", apiFile)
1702
1703 d.inclusionAnnotationsFlags(ctx, cmd)
1704
1705 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1706
1707 d.mergeAnnoDirFlags(ctx, cmd)
1708
Adrian Roos14f75a92019-08-12 17:54:09 +02001709 if baselineFile.Valid() {
1710 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1711 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1712 }
1713
Colin Cross33961b52019-07-11 11:01:22 -07001714 zipSyncCleanupCmd(rule, srcJarDir)
1715
1716 msg := `\n******************************\n` +
1717 `You have tried to change the API from what has been previously released in\n` +
1718 `an SDK. Please fix the errors listed above.\n` +
1719 `******************************\n`
1720 rule.Command().
1721 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1722 Text(") || (").
1723 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1724 Text("; exit 38").
1725 Text(")")
1726
1727 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001728 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001729
Pete Gillin581d6082018-10-22 15:55:04 +01001730 if String(d.properties.Check_nullability_warnings) != "" {
1731 if d.nullabilityWarningsFile == nil {
1732 ctx.PropertyErrorf("check_nullability_warnings",
1733 "Cannot specify check_nullability_warnings unless validating nullability")
1734 }
Colin Cross33961b52019-07-11 11:01:22 -07001735
1736 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1737
Pete Gillin581d6082018-10-22 15:55:04 +01001738 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001739
Pete Gillin581d6082018-10-22 15:55:04 +01001740 msg := fmt.Sprintf(`\n******************************\n`+
1741 `The warnings encountered during nullability annotation validation did\n`+
1742 `not match the checked in file of expected warnings. The diffs are shown\n`+
1743 `above. You have two options:\n`+
1744 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1745 ` 2. Update the file of expected warnings by running:\n`+
1746 ` cp %s %s\n`+
1747 ` and submitting the updated file as part of your change.`,
1748 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001749
1750 rule := android.NewRuleBuilder()
1751
1752 rule.Command().
1753 Text("(").
1754 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1755 Text("&&").
1756 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1757 Text(") || (").
1758 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1759 Text("; exit 38").
1760 Text(")")
1761
1762 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001763 }
1764
Nan Zhang71bbe632018-09-17 14:32:21 -07001765 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001766 if len(d.Javadoc.properties.Out) > 0 {
1767 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1768 }
1769
1770 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1771 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1772 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1773
1774 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001775
Nan Zhang86b06202018-09-21 17:09:21 -07001776 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1777 // since there's cron job downstream that fetch this .zip file periodically.
1778 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001779 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1780 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1781
Nan Zhang71bbe632018-09-17 14:32:21 -07001782 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001783
Colin Cross33961b52019-07-11 11:01:22 -07001784 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1785 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001786
Colin Cross33961b52019-07-11 11:01:22 -07001787 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1788
Colin Crossdaa4c672019-07-15 22:53:46 -07001789 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001790 deps.bootClasspath, deps.classpath, d.sourcepaths)
1791
1792 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001793 Flag("-XDignore.symbol.file").
1794 FlagWithArg("-doclet ", "jdiff.JDiff").
1795 FlagWithInput("-docletpath ", jdiff).
1796 Flag("-quiet").
1797 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1798 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1799 Implicit(d.apiXmlFile).
1800 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1801 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1802 Implicit(d.lastReleasedApiXmlFile)
1803
Colin Cross33961b52019-07-11 11:01:22 -07001804 rule.Command().
1805 BuiltTool(ctx, "soong_zip").
1806 Flag("-write_if_changed").
1807 Flag("-d").
1808 FlagWithOutput("-o ", d.jdiffDocZip).
1809 FlagWithArg("-C ", outDir.String()).
1810 FlagWithArg("-D ", outDir.String())
1811
1812 rule.Command().
1813 BuiltTool(ctx, "soong_zip").
1814 Flag("-write_if_changed").
1815 Flag("-jar").
1816 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1817 FlagWithArg("-C ", stubsDir.String()).
1818 FlagWithArg("-D ", stubsDir.String())
1819
1820 rule.Restat()
1821
1822 zipSyncCleanupCmd(rule, srcJarDir)
1823
1824 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001825 }
Nan Zhang581fd212018-01-10 16:06:12 -08001826}
Dan Willemsencc090972018-02-26 14:33:31 -08001827
Nan Zhanga40da042018-08-01 12:48:00 -07001828//
Nan Zhangf4936b02018-08-01 15:00:28 -07001829// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001830//
Dan Willemsencc090972018-02-26 14:33:31 -08001831var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001832var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001833var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001834var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001835
Nan Zhangf4936b02018-08-01 15:00:28 -07001836type ExportedDroiddocDirProperties struct {
1837 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001838 Path *string
1839}
1840
Nan Zhangf4936b02018-08-01 15:00:28 -07001841type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001842 android.ModuleBase
1843
Nan Zhangf4936b02018-08-01 15:00:28 -07001844 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001845
1846 deps android.Paths
1847 dir android.Path
1848}
1849
Colin Crossa3002fc2019-07-08 16:48:04 -07001850// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001851func ExportedDroiddocDirFactory() android.Module {
1852 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001853 module.AddProperties(&module.properties)
1854 android.InitAndroidModule(module)
1855 return module
1856}
1857
Nan Zhangf4936b02018-08-01 15:00:28 -07001858func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001859
Nan Zhangf4936b02018-08-01 15:00:28 -07001860func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001861 path := String(d.properties.Path)
1862 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001863 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001864}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001865
1866//
1867// Defaults
1868//
1869type DocDefaults struct {
1870 android.ModuleBase
1871 android.DefaultsModuleBase
1872}
1873
Nan Zhangb2b33de2018-02-23 11:18:47 -08001874func DocDefaultsFactory() android.Module {
1875 module := &DocDefaults{}
1876
1877 module.AddProperties(
1878 &JavadocProperties{},
1879 &DroiddocProperties{},
1880 )
1881
1882 android.InitDefaultsModule(module)
1883
1884 return module
1885}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001886
1887func StubsDefaultsFactory() android.Module {
1888 module := &DocDefaults{}
1889
1890 module.AddProperties(
1891 &JavadocProperties{},
1892 &DroidstubsProperties{},
1893 )
1894
1895 android.InitDefaultsModule(module)
1896
1897 return module
1898}
Colin Cross33961b52019-07-11 11:01:22 -07001899
1900func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1901 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1902
1903 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1904 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1905 srcJarList := srcJarDir.Join(ctx, "list")
1906
1907 rule.Temporary(srcJarList)
1908
1909 rule.Command().BuiltTool(ctx, "zipsync").
1910 FlagWithArg("-d ", srcJarDir.String()).
1911 FlagWithOutput("-l ", srcJarList).
1912 FlagWithArg("-f ", `"*.java"`).
1913 Inputs(srcJars)
1914
1915 return srcJarList
1916}
1917
1918func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1919 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1920}
Paul Duffin91547182019-11-12 19:39:36 +00001921
1922var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1923
1924type PrebuiltStubsSourcesProperties struct {
1925 Srcs []string `android:"path"`
1926}
1927
1928type PrebuiltStubsSources struct {
1929 android.ModuleBase
1930 android.DefaultableModuleBase
1931 prebuilt android.Prebuilt
1932 android.SdkBase
1933
1934 properties PrebuiltStubsSourcesProperties
1935
1936 srcs android.Paths
1937 stubsSrcJar android.ModuleOutPath
1938}
1939
1940func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1941 p.srcs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1942}
1943
1944func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1945 return &p.prebuilt
1946}
1947
1948func (p *PrebuiltStubsSources) Name() string {
1949 return p.prebuilt.Name(p.ModuleBase.Name())
1950}
1951
1952func (p *PrebuiltStubsSources) Srcs() android.Paths {
1953 return append(android.Paths{}, p.srcs...)
1954}
1955
1956// prebuilt_stubs_sources imports a set of java source files as if they were
1957// generated by droidstubs.
1958//
1959// By default, a prebuilt_stubs_sources has a single variant that expects a
1960// set of `.java` files generated by droidstubs.
1961//
1962// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1963// for host modules.
1964//
1965// Intended only for use by sdk snapshots.
1966func PrebuiltStubsSourcesFactory() android.Module {
1967 module := &PrebuiltStubsSources{}
1968
1969 module.AddProperties(&module.properties)
1970
1971 android.InitPrebuiltModule(module, &module.properties.Srcs)
1972 android.InitSdkAwareModule(module)
1973 InitDroiddocModule(module, android.HostAndDeviceSupported)
1974 return module
1975}
1976
Paul Duffin13879572019-11-28 14:31:38 +00001977var DroidStubsSdkMemberType = &droidStubsSdkMemberType{}
1978
1979type droidStubsSdkMemberType struct {
1980}
1981
1982func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1983 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1984}
1985
1986func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1987 _, ok := module.(*Droidstubs)
1988 return ok
1989}
1990
1991func (mt *droidStubsSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
1992 variants := member.Variants()
1993 if len(variants) != 1 {
1994 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
1995 }
1996 variant := variants[0]
1997 d, _ := variant.(*Droidstubs)
Paul Duffin91547182019-11-12 19:39:36 +00001998 stubsSrcJar := d.stubsSrcJar
1999
2000 snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
2001 builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
2002
Paul Duffin9d8d6092019-12-05 18:19:29 +00002003 pbm := builder.AddPrebuiltModule(member, "prebuilt_stubs_sources")
Paul Duffinb645ec82019-11-27 17:43:54 +00002004 pbm.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin91547182019-11-12 19:39:36 +00002005}