blob: 62a66618db37359ff3e60833a3190fbb97528712 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000030 RegisterDocsBuildComponents(android.InitRegistrationContext)
31 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000032
33 // Register sdk member type.
34 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
35 SdkMemberTypeBase: android.SdkMemberTypeBase{
36 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000037 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
38 // the APEX.
39 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000040 },
41 })
Nan Zhang581fd212018-01-10 16:06:12 -080042}
43
Paul Duffin884363e2019-12-19 10:21:09 +000044func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
45 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
46
47 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
48 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
49 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
50 ctx.RegisterModuleType("javadoc", JavadocFactory)
51 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
52}
53
54func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
55 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
56
57 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
58 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
59
60 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
61}
62
Colin Crossa1ce2a02018-06-20 15:19:39 -070063var (
64 srcsLibTag = dependencyTag{name: "sources from javalib"}
65)
66
Nan Zhang581fd212018-01-10 16:06:12 -080067type JavadocProperties struct {
68 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
69 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080070 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080071
72 // list of directories rooted at the Android.bp file that will
73 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080075
76 // list of source files that should not be used to build the Java module.
77 // This is most useful in the arch/multilib variants to remove non-common files
78 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080079 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080080
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090081 // list of package names that should actually be used. If this property is left unspecified,
82 // all the sources from the srcs property is used.
83 Filter_packages []string
84
Nan Zhangb2b33de2018-02-23 11:18:47 -080085 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080086 Libs []string `android:"arch_variant"`
87
88 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080089 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080090
Paul Duffine25c6442019-10-11 13:50:28 +010091 // if not blank, set to the version of the sdk to compile against.
92 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080093 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090094
Paul Duffine25c6442019-10-11 13:50:28 +010095 // When targeting 1.9 and above, override the modules to use with --system,
96 // otherwise provides defaults libraries to add to the bootclasspath.
97 // Defaults to "none"
98 System_modules *string
99
Jiyong Park1e440682018-05-23 18:42:04 +0900100 Aidl struct {
101 // Top level directories to pass to aidl tool
102 Include_dirs []string
103
104 // Directories rooted at the Android.bp file to pass to aidl tool
105 Local_include_dirs []string
106 }
Nan Zhang357466b2018-04-17 17:38:36 -0700107
108 // If not blank, set the java version passed to javadoc as -source
109 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
111 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800112 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700113
114 // user customized droiddoc args.
115 // Available variables for substitution:
116 //
117 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700118 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700119 Args *string
120
121 // names of the output files used in args that will be generated
122 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800123}
124
Nan Zhang61819ce2018-05-04 18:49:16 -0700125type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900126 // path to the API txt file that the new API extracted from source code is checked
127 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800128 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700129
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900130 // path to the API txt file that the new @removed API extractd from source code is
131 // checked against. The path can be local to the module or from other module (via
132 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800133 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700134
Adrian Roos14f75a92019-08-12 17:54:09 +0200135 // If not blank, path to the baseline txt file for approved API check violations.
136 Baseline_file *string `android:"path"`
137
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700139 Args *string
140}
141
Nan Zhang581fd212018-01-10 16:06:12 -0800142type DroiddocProperties struct {
143 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800144 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800145
Nan Zhanga40da042018-08-01 12:48:00 -0700146 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800147 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800148
149 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800150 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800151
152 // proofread file contains all of the text content of the javadocs concatenated into one file,
153 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700154 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // a todo file lists the program elements that are missing documentation.
157 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800158 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800159
160 // directory under current module source that provide additional resources (images).
161 Resourcesdir *string
162
163 // resources output directory under out/soong/.intermediates.
164 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800165
Nan Zhange2ba5d42018-07-11 15:16:55 -0700166 // if set to true, collect the values used by the Dev tools and
167 // write them in files packaged with the SDK. Defaults to false.
168 Write_sdk_values *bool
169
170 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700172
173 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800174 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700175
Nan Zhang581fd212018-01-10 16:06:12 -0800176 // a list of files under current module source dir which contains known tags in Java sources.
177 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700179
Nan Zhang28c68b92018-03-13 16:17:01 -0700180 // the generated public API filename by Doclava.
181 Api_filename *string
182
Nan Zhang28c68b92018-03-13 16:17:01 -0700183 // the generated removed API filename by Doclava.
184 Removed_api_filename *string
185
David Brazdilaac0c3c2018-04-24 16:23:29 +0100186 // the generated removed Dex API filename by Doclava.
187 Removed_dex_api_filename *string
188
Nan Zhang853f4202018-04-12 16:55:56 -0700189 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
190 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700191
192 Check_api struct {
193 Last_released ApiToCheck
194
195 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900196
197 // do not perform API check against Last_released, in the case that both two specified API
198 // files by Last_released are modules which don't exist.
199 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700200 }
Nan Zhang79614d12018-04-19 18:03:39 -0700201
Nan Zhang1598a9e2018-09-04 17:14:32 -0700202 // if set to true, generate docs through Dokka instead of Doclava.
203 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000204
205 // Compat config XML. Generates compat change documentation if set.
206 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700207}
208
209type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700210 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700211 Api_filename *string
212
Nan Zhang199645c2018-09-19 12:40:06 -0700213 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700214 Removed_api_filename *string
215
Nan Zhang199645c2018-09-19 12:40:06 -0700216 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700217 Removed_dex_api_filename *string
218
Nan Zhang1598a9e2018-09-04 17:14:32 -0700219 Check_api struct {
220 Last_released ApiToCheck
221
222 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900223
Paul Duffin8986cc92020-05-10 19:32:20 +0100224 // The java_sdk_library module generates references to modules (i.e. filegroups)
225 // from which information about the latest API version can be obtained. As those
226 // modules may not exist (e.g. because a previous version has not been released) it
227 // sets ignore_missing_latest_api=true on the droidstubs modules it creates so
228 // that droidstubs can ignore those references if the modules do not yet exist.
229 //
230 // If true then this will ignore module references for modules that do not exist
231 // in properties that supply the previous version of the API.
232 //
233 // There are two sets of those:
234 // * Api_file, Removed_api_file in check_api.last_released
235 // * New_since in check_api.api_lint.new_since
236 //
237 // The first two must be set as a pair, so either they should both exist or neither
238 // should exist - in which case when this property is true they are ignored. If one
239 // exists and the other does not then it is an error.
Inseob Kim38449af2019-02-28 14:24:05 +0900240 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200241
242 Api_lint struct {
243 Enabled *bool
244
245 // If set, performs api_lint on any new APIs not found in the given signature file
246 New_since *string `android:"path"`
247
248 // If not blank, path to the baseline txt file for approved API lint violations.
249 Baseline_file *string `android:"path"`
250 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700251 }
Nan Zhang79614d12018-04-19 18:03:39 -0700252
253 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800254 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700255
256 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700257 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700258
Pete Gillin77167902018-09-19 18:16:26 +0100259 // 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 -0700260 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700261
Pete Gillin77167902018-09-19 18:16:26 +0100262 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
263 Merge_inclusion_annotations_dirs []string
264
Pete Gillinc382a562018-11-14 18:45:46 +0000265 // a file containing a list of classes to do nullability validation for.
266 Validate_nullability_from_list *string
267
Pete Gillin581d6082018-10-22 15:55:04 +0100268 // a file containing expected warnings produced by validation of nullability annotations.
269 Check_nullability_warnings *string
270
Nan Zhang1598a9e2018-09-04 17:14:32 -0700271 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
272 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700273
Paul Duffin455b0bf2020-04-08 18:18:03 +0100274 // if set to false then do not write out stubs. Defaults to true.
275 //
276 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
277 Generate_stubs *bool
278
Nan Zhang9c69a122018-08-22 10:22:08 -0700279 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
280 Api_levels_annotations_enabled *bool
281
282 // the dirs which Metalava extracts API levels annotations from.
283 Api_levels_annotations_dirs []string
284
285 // if set to true, collect the values used by the Dev tools and
286 // write them in files packaged with the SDK. Defaults to false.
287 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700288
289 // If set to true, .xml based public API file will be also generated, and
290 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
291 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800292}
293
Nan Zhanga40da042018-08-01 12:48:00 -0700294//
295// Common flags passed down to build rule
296//
297type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700298 bootClasspathArgs string
299 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700300 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700301 dokkaClasspathArgs string
302 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700303 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700304
Nan Zhanga40da042018-08-01 12:48:00 -0700305 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700306 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700307 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700308}
309
310func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
311 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
312 android.InitDefaultableModule(module)
313}
314
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200315func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
316 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
317 return false
318 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700319 return true
320 } else if String(apiToCheck.Api_file) != "" {
321 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
322 } else if String(apiToCheck.Removed_api_file) != "" {
323 panic("for " + apiVersionTag + " api_file has to be non-empty!")
324 }
325
326 return false
327}
328
Inseob Kim38449af2019-02-28 14:24:05 +0900329func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
330 api_file := String(apiToCheck.Api_file)
331 removed_api_file := String(apiToCheck.Removed_api_file)
332
333 api_module := android.SrcIsModule(api_file)
334 removed_api_module := android.SrcIsModule(removed_api_file)
335
336 if api_module == "" || removed_api_module == "" {
337 return
338 }
339
340 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
341 return
342 }
343
344 apiToCheck.Api_file = nil
345 apiToCheck.Removed_api_file = nil
346}
347
Paul Duffinf488ef22020-04-09 00:10:17 +0100348// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349type ApiFilePath interface {
350 ApiFilePath() android.Path
351}
352
Paul Duffinf488ef22020-04-09 00:10:17 +0100353// Provider of information about API stubs, used by java_sdk_library.
354type ApiStubsProvider interface {
355 ApiFilePath
Paul Duffin75dcc802020-04-09 01:08:11 +0100356 RemovedApiFilePath() android.Path
Paul Duffinf488ef22020-04-09 00:10:17 +0100357 StubsSrcJar() android.Path
358}
359
Nan Zhanga40da042018-08-01 12:48:00 -0700360//
361// Javadoc
362//
Nan Zhang581fd212018-01-10 16:06:12 -0800363type Javadoc struct {
364 android.ModuleBase
365 android.DefaultableModuleBase
366
367 properties JavadocProperties
368
369 srcJars android.Paths
370 srcFiles android.Paths
371 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700372 argFiles android.Paths
373
374 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800375
Nan Zhangccff0f72018-03-08 17:26:16 -0800376 docZip android.WritablePath
377 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800378}
379
Colin Cross41955e82019-05-29 14:40:35 -0700380func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
381 switch tag {
382 case "":
383 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700384 case ".docs.zip":
385 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700386 default:
387 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
388 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800389}
390
Colin Crossa3002fc2019-07-08 16:48:04 -0700391// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800392func JavadocFactory() android.Module {
393 module := &Javadoc{}
394
395 module.AddProperties(&module.properties)
396
397 InitDroiddocModule(module, android.HostAndDeviceSupported)
398 return module
399}
400
Colin Crossa3002fc2019-07-08 16:48:04 -0700401// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800402func JavadocHostFactory() android.Module {
403 module := &Javadoc{}
404
405 module.AddProperties(&module.properties)
406
407 InitDroiddocModule(module, android.HostSupported)
408 return module
409}
410
Colin Cross41955e82019-05-29 14:40:35 -0700411var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800412
Jiyong Park6a927c42020-01-21 02:03:43 +0900413func (j *Javadoc) sdkVersion() sdkSpec {
414 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700415}
416
Paul Duffine25c6442019-10-11 13:50:28 +0100417func (j *Javadoc) systemModules() string {
418 return proptools.String(j.properties.System_modules)
419}
420
Jiyong Park6a927c42020-01-21 02:03:43 +0900421func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700422 return j.sdkVersion()
423}
424
Jiyong Park6a927c42020-01-21 02:03:43 +0900425func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700426 return j.sdkVersion()
427}
428
Nan Zhang581fd212018-01-10 16:06:12 -0800429func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
430 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100431 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700432 if sdkDep.useDefaultLibs {
433 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
434 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
435 if sdkDep.hasFrameworkLibs() {
436 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700437 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700438 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700439 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100440 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700441 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800442 }
443 }
444
Colin Cross42d48b72018-08-29 14:10:52 -0700445 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800446}
447
Nan Zhanga40da042018-08-01 12:48:00 -0700448func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
449 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900450
Colin Cross3047fa22019-04-18 10:56:44 -0700451 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900452
453 return flags
454}
455
456func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700457 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900458
459 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
460 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
461
462 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700463 var deps android.Paths
464
Jiyong Park1e440682018-05-23 18:42:04 +0900465 if aidlPreprocess.Valid() {
466 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700467 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900468 } else {
469 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
470 }
471
472 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
473 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
474 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
475 flags = append(flags, "-I"+src.String())
476 }
477
Colin Cross3047fa22019-04-18 10:56:44 -0700478 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900479}
480
Jiyong Parkd90d7412019-08-20 22:49:19 +0900481// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900482func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700483 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900484
485 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700486 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900487
Jiyong Park1112c4c2019-08-16 21:12:10 +0900488 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
489
Jiyong Park1e440682018-05-23 18:42:04 +0900490 for _, srcFile := range srcFiles {
491 switch srcFile.Ext() {
492 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700493 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900494 case ".logtags":
495 javaFile := genLogtags(ctx, srcFile)
496 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900497 default:
498 outSrcFiles = append(outSrcFiles, srcFile)
499 }
500 }
501
Colin Crossc0806172019-06-14 18:51:47 -0700502 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
503 if len(aidlSrcs) > 0 {
504 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
505 outSrcFiles = append(outSrcFiles, srcJarFiles...)
506 }
507
Jiyong Park1e440682018-05-23 18:42:04 +0900508 return outSrcFiles
509}
510
Nan Zhang581fd212018-01-10 16:06:12 -0800511func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
512 var deps deps
513
Colin Cross83bb3162018-06-25 15:48:06 -0700514 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800515 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700516 ctx.AddMissingDependencies(sdkDep.bootclasspath)
517 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800518 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700519 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000520 deps.aidlPreprocess = sdkDep.aidl
521 } else {
522 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800523 }
524
525 ctx.VisitDirectDeps(func(module android.Module) {
526 otherName := ctx.OtherModuleName(module)
527 tag := ctx.OtherModuleDependencyTag(module)
528
Colin Cross2d24c1b2018-05-23 10:59:18 -0700529 switch tag {
530 case bootClasspathTag:
531 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800532 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000533 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100534 // A system modules dependency has been added to the bootclasspath
535 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000536 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700537 } else {
538 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
539 }
540 case libTag:
541 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800542 case SdkLibraryDependency:
543 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700544 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900545 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900546 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700547 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800548 checkProducesJars(ctx, dep)
549 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800550 default:
551 ctx.ModuleErrorf("depends on non-java module %q", otherName)
552 }
Colin Cross6cef4812019-10-17 14:23:50 -0700553 case java9LibTag:
554 switch dep := module.(type) {
555 case Dependency:
556 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
557 default:
558 ctx.ModuleErrorf("depends on non-java module %q", otherName)
559 }
Nan Zhang357466b2018-04-17 17:38:36 -0700560 case systemModulesTag:
561 if deps.systemModules != nil {
562 panic("Found two system module dependencies")
563 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000564 sm := module.(SystemModulesProvider)
565 outputDir, outputDeps := sm.OutputDirAndDeps()
566 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800567 }
568 })
569 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
570 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800571 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900572
573 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
574 if filterPackages == nil {
575 return srcs
576 }
577 filtered := []android.Path{}
578 for _, src := range srcs {
579 if src.Ext() != ".java" {
580 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
581 // but otherwise metalava emits stub sources having references to the generated AIDL classes
582 // in filtered-out pacages (e.g. com.android.internal.*).
583 // TODO(b/141149570) We need to fix this by introducing default private constructors or
584 // fixing metalava to not emit constructors having references to unknown classes.
585 filtered = append(filtered, src)
586 continue
587 }
588 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800589 if android.HasAnyPrefix(packageName, filterPackages) {
590 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900591 }
592 }
593 return filtered
594 }
595 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
596
Nan Zhanga40da042018-08-01 12:48:00 -0700597 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900598 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800599
600 // srcs may depend on some genrule output.
601 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800602 j.srcJars = append(j.srcJars, deps.srcJars...)
603
Nan Zhang581fd212018-01-10 16:06:12 -0800604 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800605 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800606
Nan Zhang9c69a122018-08-22 10:22:08 -0700607 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800608 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
609 }
610 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800611
Colin Cross8a497952019-03-05 22:25:09 -0800612 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000613 argFilesMap := map[string]string{}
614 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700615
Paul Duffin99e4a502019-02-11 15:38:42 +0000616 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800617 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000618 if _, exists := argFilesMap[label]; !exists {
619 argFilesMap[label] = strings.Join(paths.Strings(), " ")
620 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700621 } else {
622 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000623 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700624 }
625 }
626
627 var err error
Colin Cross15638152019-07-11 11:11:35 -0700628 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700629 if strings.HasPrefix(name, "location ") {
630 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000631 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700632 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700633 } else {
Colin Cross15638152019-07-11 11:11:35 -0700634 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000635 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700636 }
637 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700638 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700639 }
Colin Cross15638152019-07-11 11:11:35 -0700640 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700641 })
642
643 if err != nil {
644 ctx.PropertyErrorf("args", "%s", err.Error())
645 }
646
Nan Zhang581fd212018-01-10 16:06:12 -0800647 return deps
648}
649
650func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
651 j.addDeps(ctx)
652}
653
654func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
655 deps := j.collectDeps(ctx)
656
Colin Crossdaa4c672019-07-15 22:53:46 -0700657 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800658
Colin Crossdaa4c672019-07-15 22:53:46 -0700659 outDir := android.PathForModuleOut(ctx, "out")
660 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
661
662 j.stubsSrcJar = nil
663
664 rule := android.NewRuleBuilder()
665
666 rule.Command().Text("rm -rf").Text(outDir.String())
667 rule.Command().Text("mkdir -p").Text(outDir.String())
668
669 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700670
Colin Cross83bb3162018-06-25 15:48:06 -0700671 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800672
Colin Crossdaa4c672019-07-15 22:53:46 -0700673 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
674 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800675
Colin Cross1e743852019-10-28 11:37:20 -0700676 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700677 Flag("-J-Xmx1024m").
678 Flag("-XDignore.symbol.file").
679 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800680
Colin Crossdaa4c672019-07-15 22:53:46 -0700681 rule.Command().
682 BuiltTool(ctx, "soong_zip").
683 Flag("-write_if_changed").
684 Flag("-d").
685 FlagWithOutput("-o ", j.docZip).
686 FlagWithArg("-C ", outDir.String()).
687 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700688
Colin Crossdaa4c672019-07-15 22:53:46 -0700689 rule.Restat()
690
691 zipSyncCleanupCmd(rule, srcJarDir)
692
693 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800694}
695
Nan Zhanga40da042018-08-01 12:48:00 -0700696//
697// Droiddoc
698//
699type Droiddoc struct {
700 Javadoc
701
702 properties DroiddocProperties
703 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700704 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700705 removedApiFile android.WritablePath
706 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700707
708 checkCurrentApiTimestamp android.WritablePath
709 updateCurrentApiTimestamp android.WritablePath
710 checkLastReleasedApiTimestamp android.WritablePath
711
Nan Zhanga40da042018-08-01 12:48:00 -0700712 apiFilePath android.Path
713}
714
Colin Crossa3002fc2019-07-08 16:48:04 -0700715// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700716func DroiddocFactory() android.Module {
717 module := &Droiddoc{}
718
719 module.AddProperties(&module.properties,
720 &module.Javadoc.properties)
721
722 InitDroiddocModule(module, android.HostAndDeviceSupported)
723 return module
724}
725
Colin Crossa3002fc2019-07-08 16:48:04 -0700726// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700727func DroiddocHostFactory() android.Module {
728 module := &Droiddoc{}
729
730 module.AddProperties(&module.properties,
731 &module.Javadoc.properties)
732
733 InitDroiddocModule(module, android.HostSupported)
734 return module
735}
736
737func (d *Droiddoc) ApiFilePath() android.Path {
738 return d.apiFilePath
739}
740
Nan Zhang581fd212018-01-10 16:06:12 -0800741func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
742 d.Javadoc.addDeps(ctx)
743
Inseob Kim38449af2019-02-28 14:24:05 +0900744 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
745 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
746 }
747
Nan Zhang79614d12018-04-19 18:03:39 -0700748 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800749 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
750 }
Nan Zhang581fd212018-01-10 16:06:12 -0800751}
752
Colin Crossab054432019-07-15 16:13:59 -0700753func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000754 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700755 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
756 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
757 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700758 cmd.FlagWithArg("-source ", "1.8").
759 Flag("-J-Xmx1600m").
760 Flag("-J-XX:-OmitStackTraceInFastThrow").
761 Flag("-XDignore.symbol.file").
762 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
763 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000764 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700765 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 -0700766
Nan Zhanga40da042018-08-01 12:48:00 -0700767 if String(d.properties.Custom_template) == "" {
768 // TODO: This is almost always droiddoc-templates-sdk
769 ctx.PropertyErrorf("custom_template", "must specify a template")
770 }
771
772 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700773 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700774 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700775 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000776 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700777 }
778 })
779
780 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700781 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
782 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
783 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700784 }
785
786 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700787 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
788 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
789 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700790 }
791
792 if len(d.properties.Html_dirs) > 2 {
793 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
794 }
795
Colin Cross8a497952019-03-05 22:25:09 -0800796 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700797 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700798
Colin Crossab054432019-07-15 16:13:59 -0700799 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700800
801 if String(d.properties.Proofread_file) != "" {
802 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700803 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700804 }
805
806 if String(d.properties.Todo_file) != "" {
807 // tricky part:
808 // we should not compute full path for todo_file through PathForModuleOut().
809 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700810 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
811 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700812 }
813
814 if String(d.properties.Resourcesdir) != "" {
815 // TODO: should we add files under resourcesDir to the implicits? It seems that
816 // resourcesDir is one sub dir of htmlDir
817 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700818 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700819 }
820
821 if String(d.properties.Resourcesoutdir) != "" {
822 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700823 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700824 }
Nan Zhanga40da042018-08-01 12:48:00 -0700825}
826
Colin Crossab054432019-07-15 16:13:59 -0700827func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200828 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
829 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700830 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700831
Nan Zhanga40da042018-08-01 12:48:00 -0700832 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700833 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700834 d.apiFilePath = d.apiFile
835 }
836
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200837 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
838 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700839 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700840 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700841 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700842 }
843
Nan Zhanga40da042018-08-01 12:48:00 -0700844 if String(d.properties.Removed_dex_api_filename) != "" {
845 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700846 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700847 }
848
Nan Zhanga40da042018-08-01 12:48:00 -0700849 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700850 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700851 }
852
853 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700854 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700855 }
Nan Zhanga40da042018-08-01 12:48:00 -0700856}
857
Colin Crossab054432019-07-15 16:13:59 -0700858func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700859 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700860 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
861 rule.Command().Text("cp").
862 Input(staticDocIndexRedirect).
863 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700864 }
865
866 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700867 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
868 rule.Command().Text("cp").
869 Input(staticDocProperties).
870 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700871 }
Nan Zhanga40da042018-08-01 12:48:00 -0700872}
873
Colin Crossab054432019-07-15 16:13:59 -0700874func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700875 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700876
877 cmd := rule.Command().
878 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
879 Flag(config.JavacVmFlags).
880 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700881 FlagWithRspFileInputList("@", srcs).
882 FlagWithInput("@", srcJarList)
883
Colin Crossab054432019-07-15 16:13:59 -0700884 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
885 // based stubs generation.
886 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
887 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
888 // the correct package name base path.
889 if len(sourcepaths) > 0 {
890 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
891 } else {
892 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
893 }
894
895 cmd.FlagWithArg("-d ", outDir.String()).
896 Flag("-quiet")
897
898 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700899}
900
Colin Crossdaa4c672019-07-15 22:53:46 -0700901func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
902 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
903 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
904
905 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
906
907 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
908 cmd.Flag(flag).Implicits(deps)
909
910 cmd.FlagWithArg("--patch-module ", "java.base=.")
911
912 if len(classpath) > 0 {
913 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
914 }
915
916 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700917}
918
Colin Crossdaa4c672019-07-15 22:53:46 -0700919func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
920 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
921 sourcepaths android.Paths) *android.RuleBuilderCommand {
922
923 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
924
925 if len(bootclasspath) == 0 && ctx.Device() {
926 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
927 // ensure java does not fall back to the default bootclasspath.
928 cmd.FlagWithArg("-bootclasspath ", `""`)
929 } else if len(bootclasspath) > 0 {
930 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
931 }
932
933 if len(classpath) > 0 {
934 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
935 }
936
937 return cmd
938}
939
Colin Crossab054432019-07-15 16:13:59 -0700940func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
941 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700942
Colin Crossab054432019-07-15 16:13:59 -0700943 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
944 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
945
946 return rule.Command().
947 BuiltTool(ctx, "dokka").
948 Flag(config.JavacVmFlags).
949 Flag(srcJarDir.String()).
950 FlagWithInputList("-classpath ", dokkaClasspath, ":").
951 FlagWithArg("-format ", "dac").
952 FlagWithArg("-dacRoot ", "/reference/kotlin").
953 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700954}
955
956func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
957 deps := d.Javadoc.collectDeps(ctx)
958
Colin Crossdaa4c672019-07-15 22:53:46 -0700959 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
960 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
961
Nan Zhang1598a9e2018-09-04 17:14:32 -0700962 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
963 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
964 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
965 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
966
Colin Crossab054432019-07-15 16:13:59 -0700967 outDir := android.PathForModuleOut(ctx, "out")
968 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
969 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700970
Colin Crossab054432019-07-15 16:13:59 -0700971 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700972
Colin Crossab054432019-07-15 16:13:59 -0700973 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
974 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700975
Colin Crossab054432019-07-15 16:13:59 -0700976 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
977
978 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700979 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700980 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700981 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700982 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700983 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700984 }
985
Colin Crossab054432019-07-15 16:13:59 -0700986 d.stubsFlags(ctx, cmd, stubsDir)
987
988 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
989
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000990 if d.properties.Compat_config != nil {
991 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
992 cmd.FlagWithInput("-compatconfig ", compatConfig)
993 }
994
Colin Crossab054432019-07-15 16:13:59 -0700995 var desc string
996 if Bool(d.properties.Dokka_enabled) {
997 desc = "dokka"
998 } else {
999 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1000
1001 for _, o := range d.Javadoc.properties.Out {
1002 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1003 }
1004
1005 d.postDoclavaCmds(ctx, rule)
1006 desc = "doclava"
1007 }
1008
1009 rule.Command().
1010 BuiltTool(ctx, "soong_zip").
1011 Flag("-write_if_changed").
1012 Flag("-d").
1013 FlagWithOutput("-o ", d.docZip).
1014 FlagWithArg("-C ", outDir.String()).
1015 FlagWithArg("-D ", outDir.String())
1016
1017 rule.Command().
1018 BuiltTool(ctx, "soong_zip").
1019 Flag("-write_if_changed").
1020 Flag("-jar").
1021 FlagWithOutput("-o ", d.stubsSrcJar).
1022 FlagWithArg("-C ", stubsDir.String()).
1023 FlagWithArg("-D ", stubsDir.String())
1024
1025 rule.Restat()
1026
1027 zipSyncCleanupCmd(rule, srcJarDir)
1028
1029 rule.Build(pctx, ctx, "javadoc", desc)
1030
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001031 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001032 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001033
1034 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1035 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001036
1037 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001038
1039 rule := android.NewRuleBuilder()
1040
1041 rule.Command().Text("( true")
1042
1043 rule.Command().
1044 BuiltTool(ctx, "apicheck").
1045 Flag("-JXmx1024m").
1046 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1047 OptionalFlag(d.properties.Check_api.Current.Args).
1048 Input(apiFile).
1049 Input(d.apiFile).
1050 Input(removedApiFile).
1051 Input(d.removedApiFile)
1052
1053 msg := fmt.Sprintf(`\n******************************\n`+
1054 `You have tried to change the API from what has been previously approved.\n\n`+
1055 `To make these errors go away, you have two choices:\n`+
1056 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1057 ` errors above.\n\n`+
1058 ` 2. You can update current.txt by executing the following command:\n`+
1059 ` make %s-update-current-api\n\n`+
1060 ` To submit the revised current.txt to the main Android repository,\n`+
1061 ` you will need approval.\n`+
1062 `******************************\n`, ctx.ModuleName())
1063
1064 rule.Command().
1065 Text("touch").Output(d.checkCurrentApiTimestamp).
1066 Text(") || (").
1067 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1068 Text("; exit 38").
1069 Text(")")
1070
1071 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001072
1073 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001074
1075 // update API rule
1076 rule = android.NewRuleBuilder()
1077
1078 rule.Command().Text("( true")
1079
1080 rule.Command().
1081 Text("cp").Flag("-f").
1082 Input(d.apiFile).Flag(apiFile.String())
1083
1084 rule.Command().
1085 Text("cp").Flag("-f").
1086 Input(d.removedApiFile).Flag(removedApiFile.String())
1087
1088 msg = "failed to update public API"
1089
1090 rule.Command().
1091 Text("touch").Output(d.updateCurrentApiTimestamp).
1092 Text(") || (").
1093 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1094 Text("; exit 38").
1095 Text(")")
1096
1097 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001098 }
1099
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001100 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001101 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001102
1103 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1104 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001105
1106 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001107
1108 rule := android.NewRuleBuilder()
1109
1110 rule.Command().
1111 Text("(").
1112 BuiltTool(ctx, "apicheck").
1113 Flag("-JXmx1024m").
1114 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1115 OptionalFlag(d.properties.Check_api.Last_released.Args).
1116 Input(apiFile).
1117 Input(d.apiFile).
1118 Input(removedApiFile).
1119 Input(d.removedApiFile)
1120
1121 msg := `\n******************************\n` +
1122 `You have tried to change the API from what has been previously released in\n` +
1123 `an SDK. Please fix the errors listed above.\n` +
1124 `******************************\n`
1125
1126 rule.Command().
1127 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1128 Text(") || (").
1129 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1130 Text("; exit 38").
1131 Text(")")
1132
1133 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001134 }
1135}
1136
1137//
1138// Droidstubs
1139//
1140type Droidstubs struct {
1141 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001142 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001143
Pete Gillin581d6082018-10-22 15:55:04 +01001144 properties DroidstubsProperties
1145 apiFile android.WritablePath
1146 apiXmlFile android.WritablePath
1147 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001148 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001149 removedApiFile android.WritablePath
1150 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001151 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001152
1153 checkCurrentApiTimestamp android.WritablePath
1154 updateCurrentApiTimestamp android.WritablePath
1155 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001156 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001157 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001158
Pete Gillin581d6082018-10-22 15:55:04 +01001159 checkNullabilityWarningsTimestamp android.WritablePath
1160
Nan Zhang1598a9e2018-09-04 17:14:32 -07001161 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001162 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001163
1164 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001165
1166 jdiffDocZip android.WritablePath
1167 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001168
1169 metadataZip android.WritablePath
1170 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001171}
1172
Colin Crossa3002fc2019-07-08 16:48:04 -07001173// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1174// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1175// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001176func DroidstubsFactory() android.Module {
1177 module := &Droidstubs{}
1178
1179 module.AddProperties(&module.properties,
1180 &module.Javadoc.properties)
1181
1182 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001183 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001184 return module
1185}
1186
Colin Crossa3002fc2019-07-08 16:48:04 -07001187// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1188// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1189// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1190// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001191func DroidstubsHostFactory() android.Module {
1192 module := &Droidstubs{}
1193
1194 module.AddProperties(&module.properties,
1195 &module.Javadoc.properties)
1196
1197 InitDroiddocModule(module, android.HostSupported)
1198 return module
1199}
1200
1201func (d *Droidstubs) ApiFilePath() android.Path {
1202 return d.apiFilePath
1203}
1204
Paul Duffin75dcc802020-04-09 01:08:11 +01001205func (d *Droidstubs) RemovedApiFilePath() android.Path {
1206 return d.removedApiFile
1207}
1208
Paul Duffinf488ef22020-04-09 00:10:17 +01001209func (d *Droidstubs) StubsSrcJar() android.Path {
1210 return d.stubsSrcJar
1211}
1212
Nan Zhang1598a9e2018-09-04 17:14:32 -07001213func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1214 d.Javadoc.addDeps(ctx)
1215
Paul Duffin8986cc92020-05-10 19:32:20 +01001216 // If requested clear any properties that provide information about the latest version
1217 // of an API and which reference non-existent modules.
Inseob Kim38449af2019-02-28 14:24:05 +09001218 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1219 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
Paul Duffin8986cc92020-05-10 19:32:20 +01001220
1221 // If the new_since references a module, e.g. :module-latest-api and the module
1222 // does not exist then clear it.
1223 newSinceSrc := d.properties.Check_api.Api_lint.New_since
1224 newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc))
1225 if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) {
1226 d.properties.Check_api.Api_lint.New_since = nil
1227 }
Inseob Kim38449af2019-02-28 14:24:05 +09001228 }
1229
Nan Zhang1598a9e2018-09-04 17:14:32 -07001230 if len(d.properties.Merge_annotations_dirs) != 0 {
1231 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1232 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1233 }
1234 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001235
Pete Gillin77167902018-09-19 18:16:26 +01001236 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1237 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1238 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1239 }
1240 }
1241
Nan Zhang9c69a122018-08-22 10:22:08 -07001242 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1243 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1244 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1245 }
1246 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001247}
1248
Paul Duffin455b0bf2020-04-08 18:18:03 +01001249func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001250 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1251 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001252 String(d.properties.Api_filename) != "" {
1253 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001254 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001255 d.apiFilePath = d.apiFile
1256 }
1257
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001258 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1259 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001260 String(d.properties.Removed_api_filename) != "" {
1261 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001262 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001263 }
1264
Nan Zhang1598a9e2018-09-04 17:14:32 -07001265 if String(d.properties.Removed_dex_api_filename) != "" {
1266 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001267 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001268 }
1269
Nan Zhang9c69a122018-08-22 10:22:08 -07001270 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001271 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1272 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001273 }
1274
Paul Duffin455b0bf2020-04-08 18:18:03 +01001275 if stubsDir.Valid() {
1276 if Bool(d.properties.Create_doc_stubs) {
1277 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1278 } else {
1279 cmd.FlagWithArg("--stubs ", stubsDir.String())
1280 cmd.Flag("--exclude-documentation-from-stubs")
1281 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001282 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001283}
1284
Colin Cross33961b52019-07-11 11:01:22 -07001285func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001286 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001287 cmd.Flag("--include-annotations")
1288
Pete Gillinc382a562018-11-14 18:45:46 +00001289 validatingNullability :=
1290 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1291 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001292
Pete Gillina262c052018-09-14 14:25:48 +01001293 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001294 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001295 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001296 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001297 }
Colin Cross33961b52019-07-11 11:01:22 -07001298
Pete Gillinc382a562018-11-14 18:45:46 +00001299 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001300 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001301 }
Colin Cross33961b52019-07-11 11:01:22 -07001302
Pete Gillina262c052018-09-14 14:25:48 +01001303 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001304 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001305 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001306 }
Nan Zhanga40da042018-08-01 12:48:00 -07001307
1308 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001309 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001310
Nan Zhang1598a9e2018-09-04 17:14:32 -07001311 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001312 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001313 "has to be non-empty if annotations was enabled!")
1314 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001315
Colin Cross33961b52019-07-11 11:01:22 -07001316 d.mergeAnnoDirFlags(ctx, cmd)
1317
1318 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1319 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1320 FlagWithArg("--hide ", "SuperfluousPrefix").
1321 FlagWithArg("--hide ", "AnnotationExtraction")
1322 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001323}
1324
Colin Cross33961b52019-07-11 11:01:22 -07001325func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1326 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1327 if t, ok := m.(*ExportedDroiddocDir); ok {
1328 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1329 } else {
1330 ctx.PropertyErrorf("merge_annotations_dirs",
1331 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1332 }
1333 })
1334}
1335
1336func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001337 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1338 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001339 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001340 } else {
1341 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1342 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1343 }
1344 })
Nan Zhanga40da042018-08-01 12:48:00 -07001345}
1346
Colin Cross33961b52019-07-11 11:01:22 -07001347func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001348 if Bool(d.properties.Api_levels_annotations_enabled) {
1349 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001350
1351 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1352 ctx.PropertyErrorf("api_levels_annotations_dirs",
1353 "has to be non-empty if api levels annotations was enabled!")
1354 }
1355
Colin Cross33961b52019-07-11 11:01:22 -07001356 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1357 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1358 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1359 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001360
1361 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1362 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001363 for _, dep := range t.deps {
1364 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001365 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001366 }
1367 }
Colin Cross33961b52019-07-11 11:01:22 -07001368 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001369 } else {
1370 ctx.PropertyErrorf("api_levels_annotations_dirs",
1371 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1372 }
1373 })
1374
1375 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001376}
1377
Colin Cross33961b52019-07-11 11:01:22 -07001378func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001379 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1380 if d.apiFile.String() == "" {
1381 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1382 }
1383
1384 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001385 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001386
1387 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1388 ctx.PropertyErrorf("check_api.last_released.api_file",
1389 "has to be non-empty if jdiff was enabled!")
1390 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001391
Colin Cross33961b52019-07-11 11:01:22 -07001392 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001393 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001394 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1395 }
1396}
Nan Zhang71bbe632018-09-17 14:32:21 -07001397
Colin Cross1e743852019-10-28 11:37:20 -07001398func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001399 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001400 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1401 rule.HighMem()
Colin Cross33961b52019-07-11 11:01:22 -07001402 cmd := rule.Command().BuiltTool(ctx, "metalava").
1403 Flag(config.JavacVmFlags).
1404 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001405 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001406 FlagWithRspFileInputList("@", srcs).
1407 FlagWithInput("@", srcJarList)
1408
1409 if len(bootclasspath) > 0 {
1410 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001411 }
1412
Colin Cross33961b52019-07-11 11:01:22 -07001413 if len(classpath) > 0 {
1414 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1415 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001416
Colin Cross33961b52019-07-11 11:01:22 -07001417 if len(sourcepaths) > 0 {
1418 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1419 } else {
1420 cmd.FlagWithArg("-sourcepath ", `""`)
1421 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001422
Colin Cross33961b52019-07-11 11:01:22 -07001423 cmd.Flag("--no-banner").
1424 Flag("--color").
1425 Flag("--quiet").
1426 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001427
Colin Cross33961b52019-07-11 11:01:22 -07001428 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001429}
1430
Nan Zhang1598a9e2018-09-04 17:14:32 -07001431func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001432 deps := d.Javadoc.collectDeps(ctx)
1433
1434 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001435
Colin Cross33961b52019-07-11 11:01:22 -07001436 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001437
Colin Cross33961b52019-07-11 11:01:22 -07001438 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001439
Colin Cross33961b52019-07-11 11:01:22 -07001440 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001441
Paul Duffin455b0bf2020-04-08 18:18:03 +01001442 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1443 var stubsDir android.OptionalPath
1444 if generateStubs {
1445 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1446 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1447 rule.Command().Text("rm -rf").Text(stubsDir.String())
1448 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1449 }
Nan Zhanga40da042018-08-01 12:48:00 -07001450
Colin Cross33961b52019-07-11 11:01:22 -07001451 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1452
1453 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1454 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1455
1456 d.stubsFlags(ctx, cmd, stubsDir)
1457
1458 d.annotationsFlags(ctx, cmd)
1459 d.inclusionAnnotationsFlags(ctx, cmd)
1460 d.apiLevelsAnnotationsFlags(ctx, cmd)
1461 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001462
Nan Zhang1598a9e2018-09-04 17:14:32 -07001463 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1464 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1465 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1466 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1467 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001468 }
Colin Cross33961b52019-07-11 11:01:22 -07001469
1470 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1471 for _, o := range d.Javadoc.properties.Out {
1472 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1473 }
1474
Makoto Onukib850a9d2020-04-27 17:22:16 -07001475 // Add options for the other optional tasks: API-lint and check-released.
1476 // We generate separate timestamp files for them.
1477
1478 doApiLint := false
1479 doCheckReleased := false
1480
1481 // Add API lint options.
1482
1483 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1484 doApiLint = true
1485
1486 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1487 if newSince.Valid() {
1488 cmd.FlagWithInput("--api-lint ", newSince.Path())
1489 } else {
1490 cmd.Flag("--api-lint")
1491 }
1492 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1493 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1494
1495 // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released.
1496 if d.Name() != "android.car-system-stubs-docs" &&
1497 d.Name() != "android.car-stubs-docs" &&
1498 d.Name() != "system-api-stubs-docs" &&
1499 d.Name() != "test-api-stubs-docs" {
1500 cmd.Flag("--lints-as-errors")
1501 cmd.Flag("--warnings-as-errors") // Most lints are actually warnings.
1502 }
1503
1504 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1505 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1506 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1507
1508 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1509 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1510 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1511 // which is why we have '"$PWD"$' in it.
1512 //
1513 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1514 // message and metalava's one?
1515 msg := `$'` + // Enclose with $' ... '
1516 `************************************************************\n` +
1517 `Your API changes are triggering API Lint warnings or errors.\n` +
1518 `To make these errors go away, fix the code according to the\n` +
1519 `error and/or warning messages above.\n` +
1520 `\n` +
1521 `If it is not possible to do so, there are workarounds:\n` +
1522 `\n` +
1523 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1524
1525 if baselineFile.Valid() {
1526 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1527 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1528
1529 msg += fmt.Sprintf(``+
1530 `2. You can update the baseline by executing the following\n`+
1531 ` command:\n`+
Anton Hansson18a28952020-05-11 15:38:31 +01001532 ` cp \\\n`+
1533 ` "'"$PWD"$'/%s" \\\n`+
1534 ` "'"$PWD"$'/%s"\n`+
Makoto Onukib850a9d2020-04-27 17:22:16 -07001535 ` To submit the revised baseline.txt to the main Android\n`+
1536 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1537 } else {
1538 msg += fmt.Sprintf(``+
1539 `2. You can add a baseline file of existing lint failures\n`+
1540 ` to the build rule of %s.\n`, d.Name())
1541 }
1542 // Note the message ends with a ' (single quote), to close the $' ... ' .
1543 msg += `************************************************************\n'`
1544
1545 cmd.FlagWithArg("--error-message:api-lint ", msg)
1546 }
1547
1548 // Add "check released" options. (Detect incompatible API changes from the last public release)
1549
1550 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
1551 !ctx.Config().IsPdkBuild() {
1552 doCheckReleased = true
1553
1554 if len(d.Javadoc.properties.Out) > 0 {
1555 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1556 }
1557
1558 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1559 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1560 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1561 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1562
1563 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1564
1565 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1566 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1567
1568 if baselineFile.Valid() {
1569 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1570 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1571 }
1572
1573 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1574 msg := `$'\n******************************\n` +
1575 `You have tried to change the API from what has been previously released in\n` +
1576 `an SDK. Please fix the errors listed above.\n` +
1577 `******************************\n'`
1578
1579 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1580 }
1581
Paul Duffin455b0bf2020-04-08 18:18:03 +01001582 if generateStubs {
1583 rule.Command().
1584 BuiltTool(ctx, "soong_zip").
1585 Flag("-write_if_changed").
1586 Flag("-jar").
1587 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1588 FlagWithArg("-C ", stubsDir.String()).
1589 FlagWithArg("-D ", stubsDir.String())
1590 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001591
1592 if Bool(d.properties.Write_sdk_values) {
1593 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1594 rule.Command().
1595 BuiltTool(ctx, "soong_zip").
1596 Flag("-write_if_changed").
1597 Flag("-d").
1598 FlagWithOutput("-o ", d.metadataZip).
1599 FlagWithArg("-C ", d.metadataDir.String()).
1600 FlagWithArg("-D ", d.metadataDir.String())
1601 }
1602
Makoto Onukib850a9d2020-04-27 17:22:16 -07001603 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1604 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1605 if doApiLint {
1606 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1607 }
1608 if doCheckReleased {
1609 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1610 }
1611
Colin Cross33961b52019-07-11 11:01:22 -07001612 rule.Restat()
1613
1614 zipSyncCleanupCmd(rule, srcJarDir)
1615
Makoto Onukib850a9d2020-04-27 17:22:16 -07001616 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001617
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001618 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001619 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001620
1621 if len(d.Javadoc.properties.Out) > 0 {
1622 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1623 }
1624
1625 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1626 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001627 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001628
1629 if baselineFile.Valid() {
Makoto Onukib850a9d2020-04-27 17:22:16 -07001630 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001631 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001632
Nan Zhang2760dfc2018-08-24 17:32:54 +00001633 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001634
Colin Cross33961b52019-07-11 11:01:22 -07001635 rule := android.NewRuleBuilder()
1636
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001637 // Diff command line.
Makoto Onukib850a9d2020-04-27 17:22:16 -07001638 // -F matches the closest "opening" line, such as "package android {"
1639 // and " public class Intent {".
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001640 diff := `diff -u -F '{ *$'`
1641
Colin Cross33961b52019-07-11 11:01:22 -07001642 rule.Command().Text("( true")
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001643 rule.Command().
1644 Text(diff).
1645 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001646
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001647 rule.Command().
1648 Text(diff).
1649 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001650
1651 msg := fmt.Sprintf(`\n******************************\n`+
1652 `You have tried to change the API from what has been previously approved.\n\n`+
1653 `To make these errors go away, you have two choices:\n`+
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001654 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1655 ` to the new methods, etc. shown in the above diff.\n\n`+
1656 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001657 ` make %s-update-current-api\n\n`+
1658 ` To submit the revised current.txt to the main Android repository,\n`+
1659 ` you will need approval.\n`+
1660 `******************************\n`, ctx.ModuleName())
1661
1662 rule.Command().
1663 Text("touch").Output(d.checkCurrentApiTimestamp).
1664 Text(") || (").
1665 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1666 Text("; exit 38").
1667 Text(")")
1668
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001669 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001670
1671 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001672
1673 // update API rule
1674 rule = android.NewRuleBuilder()
1675
1676 rule.Command().Text("( true")
1677
1678 rule.Command().
1679 Text("cp").Flag("-f").
1680 Input(d.apiFile).Flag(apiFile.String())
1681
1682 rule.Command().
1683 Text("cp").Flag("-f").
1684 Input(d.removedApiFile).Flag(removedApiFile.String())
1685
1686 msg = "failed to update public API"
1687
1688 rule.Command().
1689 Text("touch").Output(d.updateCurrentApiTimestamp).
1690 Text(") || (").
1691 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1692 Text("; exit 38").
1693 Text(")")
1694
1695 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001696 }
Nan Zhanga40da042018-08-01 12:48:00 -07001697
Pete Gillin581d6082018-10-22 15:55:04 +01001698 if String(d.properties.Check_nullability_warnings) != "" {
1699 if d.nullabilityWarningsFile == nil {
1700 ctx.PropertyErrorf("check_nullability_warnings",
1701 "Cannot specify check_nullability_warnings unless validating nullability")
1702 }
Colin Cross33961b52019-07-11 11:01:22 -07001703
1704 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1705
Pete Gillin581d6082018-10-22 15:55:04 +01001706 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001707
Pete Gillin581d6082018-10-22 15:55:04 +01001708 msg := fmt.Sprintf(`\n******************************\n`+
1709 `The warnings encountered during nullability annotation validation did\n`+
1710 `not match the checked in file of expected warnings. The diffs are shown\n`+
1711 `above. You have two options:\n`+
1712 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1713 ` 2. Update the file of expected warnings by running:\n`+
1714 ` cp %s %s\n`+
1715 ` and submitting the updated file as part of your change.`,
1716 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001717
1718 rule := android.NewRuleBuilder()
1719
1720 rule.Command().
1721 Text("(").
1722 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1723 Text("&&").
1724 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1725 Text(") || (").
1726 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1727 Text("; exit 38").
1728 Text(")")
1729
1730 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001731 }
1732
Nan Zhang71bbe632018-09-17 14:32:21 -07001733 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001734 if len(d.Javadoc.properties.Out) > 0 {
1735 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1736 }
1737
1738 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1739 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1740 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1741
1742 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001743
Nan Zhang86b06202018-09-21 17:09:21 -07001744 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1745 // since there's cron job downstream that fetch this .zip file periodically.
1746 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001747 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1748 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1749
Nan Zhang71bbe632018-09-17 14:32:21 -07001750 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001751
Colin Cross33961b52019-07-11 11:01:22 -07001752 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1753 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001754
Colin Cross33961b52019-07-11 11:01:22 -07001755 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1756
Colin Crossdaa4c672019-07-15 22:53:46 -07001757 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001758 deps.bootClasspath, deps.classpath, d.sourcepaths)
1759
1760 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001761 Flag("-XDignore.symbol.file").
1762 FlagWithArg("-doclet ", "jdiff.JDiff").
1763 FlagWithInput("-docletpath ", jdiff).
1764 Flag("-quiet").
1765 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1766 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1767 Implicit(d.apiXmlFile).
1768 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1769 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1770 Implicit(d.lastReleasedApiXmlFile)
1771
Colin Cross33961b52019-07-11 11:01:22 -07001772 rule.Command().
1773 BuiltTool(ctx, "soong_zip").
1774 Flag("-write_if_changed").
1775 Flag("-d").
1776 FlagWithOutput("-o ", d.jdiffDocZip).
1777 FlagWithArg("-C ", outDir.String()).
1778 FlagWithArg("-D ", outDir.String())
1779
1780 rule.Command().
1781 BuiltTool(ctx, "soong_zip").
1782 Flag("-write_if_changed").
1783 Flag("-jar").
1784 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1785 FlagWithArg("-C ", stubsDir.String()).
1786 FlagWithArg("-D ", stubsDir.String())
1787
1788 rule.Restat()
1789
1790 zipSyncCleanupCmd(rule, srcJarDir)
1791
1792 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001793 }
Nan Zhang581fd212018-01-10 16:06:12 -08001794}
Dan Willemsencc090972018-02-26 14:33:31 -08001795
Nan Zhanga40da042018-08-01 12:48:00 -07001796//
Nan Zhangf4936b02018-08-01 15:00:28 -07001797// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001798//
Dan Willemsencc090972018-02-26 14:33:31 -08001799var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001800var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001801var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001802var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001803
Nan Zhangf4936b02018-08-01 15:00:28 -07001804type ExportedDroiddocDirProperties struct {
1805 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001806 Path *string
1807}
1808
Nan Zhangf4936b02018-08-01 15:00:28 -07001809type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001810 android.ModuleBase
1811
Nan Zhangf4936b02018-08-01 15:00:28 -07001812 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001813
1814 deps android.Paths
1815 dir android.Path
1816}
1817
Colin Crossa3002fc2019-07-08 16:48:04 -07001818// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001819func ExportedDroiddocDirFactory() android.Module {
1820 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001821 module.AddProperties(&module.properties)
1822 android.InitAndroidModule(module)
1823 return module
1824}
1825
Nan Zhangf4936b02018-08-01 15:00:28 -07001826func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001827
Nan Zhangf4936b02018-08-01 15:00:28 -07001828func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001829 path := String(d.properties.Path)
1830 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001831 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001832}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001833
1834//
1835// Defaults
1836//
1837type DocDefaults struct {
1838 android.ModuleBase
1839 android.DefaultsModuleBase
1840}
1841
Nan Zhangb2b33de2018-02-23 11:18:47 -08001842func DocDefaultsFactory() android.Module {
1843 module := &DocDefaults{}
1844
1845 module.AddProperties(
1846 &JavadocProperties{},
1847 &DroiddocProperties{},
1848 )
1849
1850 android.InitDefaultsModule(module)
1851
1852 return module
1853}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001854
1855func StubsDefaultsFactory() android.Module {
1856 module := &DocDefaults{}
1857
1858 module.AddProperties(
1859 &JavadocProperties{},
1860 &DroidstubsProperties{},
1861 )
1862
1863 android.InitDefaultsModule(module)
1864
1865 return module
1866}
Colin Cross33961b52019-07-11 11:01:22 -07001867
1868func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1869 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1870
1871 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1872 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1873 srcJarList := srcJarDir.Join(ctx, "list")
1874
1875 rule.Temporary(srcJarList)
1876
1877 rule.Command().BuiltTool(ctx, "zipsync").
1878 FlagWithArg("-d ", srcJarDir.String()).
1879 FlagWithOutput("-l ", srcJarList).
1880 FlagWithArg("-f ", `"*.java"`).
1881 Inputs(srcJars)
1882
1883 return srcJarList
1884}
1885
1886func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1887 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1888}
Paul Duffin91547182019-11-12 19:39:36 +00001889
1890var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1891
1892type PrebuiltStubsSourcesProperties struct {
1893 Srcs []string `android:"path"`
1894}
1895
1896type PrebuiltStubsSources struct {
1897 android.ModuleBase
1898 android.DefaultableModuleBase
1899 prebuilt android.Prebuilt
1900 android.SdkBase
1901
1902 properties PrebuiltStubsSourcesProperties
1903
Paul Duffin9b478b02019-12-10 13:41:51 +00001904 // The source directories containing stubs source files.
1905 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001906 stubsSrcJar android.ModuleOutPath
1907}
1908
Paul Duffin9b478b02019-12-10 13:41:51 +00001909func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1910 switch tag {
1911 case "":
1912 return android.Paths{p.stubsSrcJar}, nil
1913 default:
1914 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1915 }
1916}
1917
Paul Duffin91547182019-11-12 19:39:36 +00001918func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001919 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1920
1921 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1922
1923 rule := android.NewRuleBuilder()
1924 command := rule.Command().
1925 BuiltTool(ctx, "soong_zip").
1926 Flag("-write_if_changed").
1927 Flag("-jar").
1928 FlagWithOutput("-o ", p.stubsSrcJar)
1929
1930 for _, d := range p.srcDirs {
1931 dir := d.String()
1932 command.
1933 FlagWithArg("-C ", dir).
1934 FlagWithInput("-D ", d)
1935 }
1936
1937 rule.Restat()
1938
1939 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001940}
1941
1942func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1943 return &p.prebuilt
1944}
1945
1946func (p *PrebuiltStubsSources) Name() string {
1947 return p.prebuilt.Name(p.ModuleBase.Name())
1948}
1949
Paul Duffin91547182019-11-12 19:39:36 +00001950// prebuilt_stubs_sources imports a set of java source files as if they were
1951// generated by droidstubs.
1952//
1953// By default, a prebuilt_stubs_sources has a single variant that expects a
1954// set of `.java` files generated by droidstubs.
1955//
1956// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1957// for host modules.
1958//
1959// Intended only for use by sdk snapshots.
1960func PrebuiltStubsSourcesFactory() android.Module {
1961 module := &PrebuiltStubsSources{}
1962
1963 module.AddProperties(&module.properties)
1964
1965 android.InitPrebuiltModule(module, &module.properties.Srcs)
1966 android.InitSdkAwareModule(module)
1967 InitDroiddocModule(module, android.HostAndDeviceSupported)
1968 return module
1969}
1970
Paul Duffin13879572019-11-28 14:31:38 +00001971type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001972 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001973}
1974
1975func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1976 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1977}
1978
1979func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1980 _, ok := module.(*Droidstubs)
1981 return ok
1982}
1983
Paul Duffin93520ed2020-03-20 13:35:40 +00001984func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1985 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
1986}
1987
1988func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1989 return &droidStubsInfoProperties{}
1990}
1991
1992type droidStubsInfoProperties struct {
1993 android.SdkMemberPropertiesBase
1994
1995 StubsSrcJar android.Path
1996}
1997
1998func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1999 droidstubs := variant.(*Droidstubs)
2000 p.StubsSrcJar = droidstubs.stubsSrcJar
2001}
2002
2003func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
2004 if p.StubsSrcJar != nil {
2005 builder := ctx.SnapshotBuilder()
2006
2007 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2008
2009 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2010
2011 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002012 }
Paul Duffin91547182019-11-12 19:39:36 +00002013}