blob: 33f422d4e5f1874981f7da8c64f276c73c1b45af [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"
Ramy Medhat427683c2020-04-30 03:08:37 -040027 "android/soong/remoteexec"
Nan Zhang581fd212018-01-10 16:06:12 -080028)
29
30func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000031 RegisterDocsBuildComponents(android.InitRegistrationContext)
32 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000033
34 // Register sdk member type.
35 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
36 SdkMemberTypeBase: android.SdkMemberTypeBase{
37 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000038 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
39 // the APEX.
40 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000041 },
42 })
Nan Zhang581fd212018-01-10 16:06:12 -080043}
44
Paul Duffin884363e2019-12-19 10:21:09 +000045func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
47
48 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
49 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
50 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
51 ctx.RegisterModuleType("javadoc", JavadocFactory)
52 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
53}
54
55func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
56 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
57
58 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
59 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
60
61 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
62}
63
Colin Crossa1ce2a02018-06-20 15:19:39 -070064var (
65 srcsLibTag = dependencyTag{name: "sources from javalib"}
66)
67
Nan Zhang581fd212018-01-10 16:06:12 -080068type JavadocProperties struct {
69 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
70 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080071 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080072
Nan Zhang581fd212018-01-10 16:06:12 -080073 // list of source files that should not be used to build the Java module.
74 // This is most useful in the arch/multilib variants to remove non-common files
75 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080076 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080077
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090078 // list of package names that should actually be used. If this property is left unspecified,
79 // all the sources from the srcs property is used.
80 Filter_packages []string
81
Nan Zhangb2b33de2018-02-23 11:18:47 -080082 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080083 Libs []string `android:"arch_variant"`
84
85 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080086 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080087
Paul Duffine25c6442019-10-11 13:50:28 +010088 // if not blank, set to the version of the sdk to compile against.
89 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080090 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090091
Paul Duffine25c6442019-10-11 13:50:28 +010092 // When targeting 1.9 and above, override the modules to use with --system,
93 // otherwise provides defaults libraries to add to the bootclasspath.
94 // Defaults to "none"
95 System_modules *string
96
Jiyong Park1e440682018-05-23 18:42:04 +090097 Aidl struct {
98 // Top level directories to pass to aidl tool
99 Include_dirs []string
100
101 // Directories rooted at the Android.bp file to pass to aidl tool
102 Local_include_dirs []string
103 }
Nan Zhang357466b2018-04-17 17:38:36 -0700104
105 // If not blank, set the java version passed to javadoc as -source
106 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700107
108 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800109 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
Liz Kammer585cac22020-07-06 09:12:57 -0700111 // user customized droiddoc args. Deprecated, use flags instead.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700112 // Available variables for substitution:
113 //
114 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700115 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700116 Args *string
117
Liz Kammer585cac22020-07-06 09:12:57 -0700118 // user customized droiddoc args. Not compatible with property args.
119 // Available variables for substitution:
120 //
121 // $(location <label>): the path to the arg_files with name <label>
122 // $$: a literal $
123 Flags []string
124
Nan Zhang1598a9e2018-09-04 17:14:32 -0700125 // names of the output files used in args that will be generated
126 Out []string
Ramy Medhat2f99eec2020-06-13 17:38:27 -0400127
128 // If set, metalava is sandboxed to only read files explicitly specified on the command
129 // line. Defaults to false.
130 Sandbox *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800131}
132
Nan Zhang61819ce2018-05-04 18:49:16 -0700133type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900134 // path to the API txt file that the new API extracted from source code is checked
135 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800136 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700137
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // path to the API txt file that the new @removed API extractd from source code is
139 // checked against. The path can be local to the module or from other module (via
140 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800141 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700142
Adrian Roos14f75a92019-08-12 17:54:09 +0200143 // If not blank, path to the baseline txt file for approved API check violations.
144 Baseline_file *string `android:"path"`
145
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900146 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700147 Args *string
148}
149
Nan Zhang581fd212018-01-10 16:06:12 -0800150type DroiddocProperties struct {
151 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800152 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800153
Nan Zhanga40da042018-08-01 12:48:00 -0700154 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800155 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800156
157 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800158 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800159
160 // proofread file contains all of the text content of the javadocs concatenated into one file,
161 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700162 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800163
164 // a todo file lists the program elements that are missing documentation.
165 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800166 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800167
168 // directory under current module source that provide additional resources (images).
169 Resourcesdir *string
170
171 // resources output directory under out/soong/.intermediates.
172 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800173
Nan Zhange2ba5d42018-07-11 15:16:55 -0700174 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700176
177 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700179
Nan Zhang581fd212018-01-10 16:06:12 -0800180 // a list of files under current module source dir which contains known tags in Java sources.
181 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800182 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700183
Nan Zhang1598a9e2018-09-04 17:14:32 -0700184 // if set to true, generate docs through Dokka instead of Doclava.
185 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000186
187 // Compat config XML. Generates compat change documentation if set.
188 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700189}
190
191type DroidstubsProperties struct {
Liz Kammer9ed79152020-08-24 15:56:32 -0700192 // The generated public API filename by Metalava, defaults to <module>_api.txt
Nan Zhang1598a9e2018-09-04 17:14:32 -0700193 Api_filename *string
194
Liz Kammer9ed79152020-08-24 15:56:32 -0700195 // the generated removed API filename by Metalava, defaults to <module>_removed.txt
Nan Zhang1598a9e2018-09-04 17:14:32 -0700196 Removed_api_filename *string
197
Nan Zhang199645c2018-09-19 12:40:06 -0700198 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700199 Removed_dex_api_filename *string
200
Nan Zhang1598a9e2018-09-04 17:14:32 -0700201 Check_api struct {
202 Last_released ApiToCheck
203
204 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900205
Paul Duffin160fe412020-05-10 19:32:20 +0100206 // The java_sdk_library module generates references to modules (i.e. filegroups)
207 // from which information about the latest API version can be obtained. As those
208 // modules may not exist (e.g. because a previous version has not been released) it
209 // sets ignore_missing_latest_api=true on the droidstubs modules it creates so
210 // that droidstubs can ignore those references if the modules do not yet exist.
211 //
212 // If true then this will ignore module references for modules that do not exist
213 // in properties that supply the previous version of the API.
214 //
215 // There are two sets of those:
216 // * Api_file, Removed_api_file in check_api.last_released
217 // * New_since in check_api.api_lint.new_since
218 //
219 // The first two must be set as a pair, so either they should both exist or neither
220 // should exist - in which case when this property is true they are ignored. If one
221 // exists and the other does not then it is an error.
Inseob Kim38449af2019-02-28 14:24:05 +0900222 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200223
224 Api_lint struct {
225 Enabled *bool
226
227 // If set, performs api_lint on any new APIs not found in the given signature file
228 New_since *string `android:"path"`
229
230 // If not blank, path to the baseline txt file for approved API lint violations.
231 Baseline_file *string `android:"path"`
232 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700233 }
Nan Zhang79614d12018-04-19 18:03:39 -0700234
235 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800236 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700237
238 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700239 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700240
Pete Gillin77167902018-09-19 18:16:26 +0100241 // 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 -0700242 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700243
Pete Gillin77167902018-09-19 18:16:26 +0100244 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
245 Merge_inclusion_annotations_dirs []string
246
Pete Gillinc382a562018-11-14 18:45:46 +0000247 // a file containing a list of classes to do nullability validation for.
248 Validate_nullability_from_list *string
249
Pete Gillin581d6082018-10-22 15:55:04 +0100250 // a file containing expected warnings produced by validation of nullability annotations.
251 Check_nullability_warnings *string
252
Nan Zhang1598a9e2018-09-04 17:14:32 -0700253 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
254 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700255
Paul Duffin6877e6d2020-09-25 19:59:14 +0100256 // if set to true, cause Metalava to output Javadoc comments in the stubs source files. Defaults to false.
257 // Has no effect if create_doc_stubs: true.
258 Output_javadoc_comments *bool
259
Paul Duffin3ae29512020-04-08 18:18:03 +0100260 // if set to false then do not write out stubs. Defaults to true.
261 //
262 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
263 Generate_stubs *bool
264
Nan Zhang9c69a122018-08-22 10:22:08 -0700265 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
266 Api_levels_annotations_enabled *bool
267
268 // the dirs which Metalava extracts API levels annotations from.
269 Api_levels_annotations_dirs []string
270
Liz Kammer3d894b72020-08-04 09:55:13 -0700271 // the filename which Metalava extracts API levels annotations from. Defaults to android.jar.
272 Api_levels_jar_filename *string
273
Nan Zhang9c69a122018-08-22 10:22:08 -0700274 // if set to true, collect the values used by the Dev tools and
275 // write them in files packaged with the SDK. Defaults to false.
276 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700277
278 // If set to true, .xml based public API file will be also generated, and
279 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
280 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800281}
282
Nan Zhanga40da042018-08-01 12:48:00 -0700283//
284// Common flags passed down to build rule
285//
286type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700287 bootClasspathArgs string
288 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700289 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700290 dokkaClasspathArgs string
291 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700292 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700293
Nan Zhanga40da042018-08-01 12:48:00 -0700294 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700295 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700296 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700297}
298
299func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
300 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
301 android.InitDefaultableModule(module)
302}
303
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200304func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
305 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
306 return false
307 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700308 return true
309 } else if String(apiToCheck.Api_file) != "" {
310 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
311 } else if String(apiToCheck.Removed_api_file) != "" {
312 panic("for " + apiVersionTag + " api_file has to be non-empty!")
313 }
314
315 return false
316}
317
Inseob Kim38449af2019-02-28 14:24:05 +0900318func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
319 api_file := String(apiToCheck.Api_file)
320 removed_api_file := String(apiToCheck.Removed_api_file)
321
322 api_module := android.SrcIsModule(api_file)
323 removed_api_module := android.SrcIsModule(removed_api_file)
324
325 if api_module == "" || removed_api_module == "" {
326 return
327 }
328
329 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
330 return
331 }
332
333 apiToCheck.Api_file = nil
334 apiToCheck.Removed_api_file = nil
335}
336
Paul Duffin3d1248c2020-04-09 00:10:17 +0100337// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700338type ApiFilePath interface {
339 ApiFilePath() android.Path
340}
341
Paul Duffin0f8faff2020-05-20 16:18:00 +0100342type ApiStubsSrcProvider interface {
343 StubsSrcJar() android.Path
344}
345
Paul Duffin3d1248c2020-04-09 00:10:17 +0100346// Provider of information about API stubs, used by java_sdk_library.
347type ApiStubsProvider interface {
348 ApiFilePath
Paul Duffin1fd005d2020-04-09 01:08:11 +0100349 RemovedApiFilePath() android.Path
Paul Duffin0f8faff2020-05-20 16:18:00 +0100350
351 ApiStubsSrcProvider
Paul Duffin3d1248c2020-04-09 00:10:17 +0100352}
353
Nan Zhanga40da042018-08-01 12:48:00 -0700354//
355// Javadoc
356//
Nan Zhang581fd212018-01-10 16:06:12 -0800357type Javadoc struct {
358 android.ModuleBase
359 android.DefaultableModuleBase
360
361 properties JavadocProperties
362
363 srcJars android.Paths
364 srcFiles android.Paths
365 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700366 argFiles android.Paths
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400367 implicits android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700368
Liz Kammer585cac22020-07-06 09:12:57 -0700369 args []string
Nan Zhang581fd212018-01-10 16:06:12 -0800370
Nan Zhangccff0f72018-03-08 17:26:16 -0800371 docZip android.WritablePath
372 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800373}
374
Colin Cross41955e82019-05-29 14:40:35 -0700375func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
376 switch tag {
377 case "":
378 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700379 case ".docs.zip":
380 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700381 default:
382 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
383 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800384}
385
Colin Crossa3002fc2019-07-08 16:48:04 -0700386// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800387func JavadocFactory() android.Module {
388 module := &Javadoc{}
389
390 module.AddProperties(&module.properties)
391
392 InitDroiddocModule(module, android.HostAndDeviceSupported)
393 return module
394}
395
Colin Crossa3002fc2019-07-08 16:48:04 -0700396// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800397func JavadocHostFactory() android.Module {
398 module := &Javadoc{}
399
400 module.AddProperties(&module.properties)
401
402 InitDroiddocModule(module, android.HostSupported)
403 return module
404}
405
Colin Cross41955e82019-05-29 14:40:35 -0700406var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800407
Jiyong Park6a927c42020-01-21 02:03:43 +0900408func (j *Javadoc) sdkVersion() sdkSpec {
409 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700410}
411
Paul Duffine25c6442019-10-11 13:50:28 +0100412func (j *Javadoc) systemModules() string {
413 return proptools.String(j.properties.System_modules)
414}
415
Jiyong Park6a927c42020-01-21 02:03:43 +0900416func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700417 return j.sdkVersion()
418}
419
Jiyong Park6a927c42020-01-21 02:03:43 +0900420func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700421 return j.sdkVersion()
422}
423
Nan Zhang581fd212018-01-10 16:06:12 -0800424func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
425 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100426 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Pete Gilline3d44b22020-06-29 11:28:51 +0100427 if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700428 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100429 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700430 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Pete Gilline3d44b22020-06-29 11:28:51 +0100431 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800432 }
433 }
434
Colin Cross42d48b72018-08-29 14:10:52 -0700435 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800436}
437
Nan Zhanga40da042018-08-01 12:48:00 -0700438func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
439 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900440
Colin Cross3047fa22019-04-18 10:56:44 -0700441 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900442
443 return flags
444}
445
446func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700447 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900448
449 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
450 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
451
452 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700453 var deps android.Paths
454
Jiyong Park1e440682018-05-23 18:42:04 +0900455 if aidlPreprocess.Valid() {
456 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700457 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900458 } else {
459 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
460 }
461
462 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
463 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
464 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
465 flags = append(flags, "-I"+src.String())
466 }
467
Colin Cross3047fa22019-04-18 10:56:44 -0700468 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900469}
470
Jiyong Parkd90d7412019-08-20 22:49:19 +0900471// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900472func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700473 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900474
475 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700476 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900477
Jiyong Park1112c4c2019-08-16 21:12:10 +0900478 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
479
Jiyong Park1e440682018-05-23 18:42:04 +0900480 for _, srcFile := range srcFiles {
481 switch srcFile.Ext() {
482 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700483 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900484 case ".logtags":
485 javaFile := genLogtags(ctx, srcFile)
486 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900487 default:
488 outSrcFiles = append(outSrcFiles, srcFile)
489 }
490 }
491
Colin Crossc0806172019-06-14 18:51:47 -0700492 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
493 if len(aidlSrcs) > 0 {
494 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
495 outSrcFiles = append(outSrcFiles, srcJarFiles...)
496 }
497
Jiyong Park1e440682018-05-23 18:42:04 +0900498 return outSrcFiles
499}
500
Nan Zhang581fd212018-01-10 16:06:12 -0800501func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
502 var deps deps
503
Colin Cross83bb3162018-06-25 15:48:06 -0700504 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800505 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700506 ctx.AddMissingDependencies(sdkDep.bootclasspath)
507 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800508 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700509 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000510 deps.aidlPreprocess = sdkDep.aidl
511 } else {
512 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800513 }
514
515 ctx.VisitDirectDeps(func(module android.Module) {
516 otherName := ctx.OtherModuleName(module)
517 tag := ctx.OtherModuleDependencyTag(module)
518
Colin Cross2d24c1b2018-05-23 10:59:18 -0700519 switch tag {
520 case bootClasspathTag:
521 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800522 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000523 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100524 // A system modules dependency has been added to the bootclasspath
525 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000526 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700527 } else {
528 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
529 }
530 case libTag:
531 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800532 case SdkLibraryDependency:
Paul Duffin649dadf2020-05-26 11:42:13 +0100533 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700534 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900535 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900536 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700537 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800538 checkProducesJars(ctx, dep)
539 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800540 default:
541 ctx.ModuleErrorf("depends on non-java module %q", otherName)
542 }
Colin Cross6cef4812019-10-17 14:23:50 -0700543 case java9LibTag:
544 switch dep := module.(type) {
545 case Dependency:
546 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
547 default:
548 ctx.ModuleErrorf("depends on non-java module %q", otherName)
549 }
Nan Zhang357466b2018-04-17 17:38:36 -0700550 case systemModulesTag:
551 if deps.systemModules != nil {
552 panic("Found two system module dependencies")
553 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000554 sm := module.(SystemModulesProvider)
555 outputDir, outputDeps := sm.OutputDirAndDeps()
556 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800557 }
558 })
559 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
560 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800561 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400562 j.implicits = append(j.implicits, srcFiles...)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900563
564 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
565 if filterPackages == nil {
566 return srcs
567 }
568 filtered := []android.Path{}
569 for _, src := range srcs {
570 if src.Ext() != ".java" {
571 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
572 // but otherwise metalava emits stub sources having references to the generated AIDL classes
573 // in filtered-out pacages (e.g. com.android.internal.*).
574 // TODO(b/141149570) We need to fix this by introducing default private constructors or
575 // fixing metalava to not emit constructors having references to unknown classes.
576 filtered = append(filtered, src)
577 continue
578 }
579 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800580 if android.HasAnyPrefix(packageName, filterPackages) {
581 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900582 }
583 }
584 return filtered
585 }
586 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
587
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400588 // While metalava needs package html files, it does not need them to be explicit on the command
589 // line. More importantly, the metalava rsp file is also used by the subsequent jdiff action if
590 // jdiff_enabled=true. javadoc complains if it receives html files on the command line. The filter
591 // below excludes html files from the rsp file for both metalava and jdiff. Note that the html
592 // files are still included as implicit inputs for successful remote execution and correct
593 // incremental builds.
594 filterHtml := func(srcs []android.Path) []android.Path {
595 filtered := []android.Path{}
596 for _, src := range srcs {
597 if src.Ext() == ".html" {
598 continue
599 }
600 filtered = append(filtered, src)
601 }
602 return filtered
603 }
604 srcFiles = filterHtml(srcFiles)
605
Liz Kammer585cac22020-07-06 09:12:57 -0700606 aidlFlags := j.collectAidlFlags(ctx, deps)
607 srcFiles = j.genSources(ctx, srcFiles, aidlFlags)
Nan Zhang581fd212018-01-10 16:06:12 -0800608
609 // srcs may depend on some genrule output.
610 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800611 j.srcJars = append(j.srcJars, deps.srcJars...)
612
Nan Zhang581fd212018-01-10 16:06:12 -0800613 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800614 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800615
Liz Kammere1ab2502020-09-10 15:29:25 +0000616 if len(j.srcFiles) > 0 {
617 j.sourcepaths = android.PathsForModuleSrc(ctx, []string{"."})
Nan Zhang581fd212018-01-10 16:06:12 -0800618 }
Nan Zhang581fd212018-01-10 16:06:12 -0800619
Colin Cross8a497952019-03-05 22:25:09 -0800620 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000621 argFilesMap := map[string]string{}
622 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700623
Paul Duffin99e4a502019-02-11 15:38:42 +0000624 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800625 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000626 if _, exists := argFilesMap[label]; !exists {
627 argFilesMap[label] = strings.Join(paths.Strings(), " ")
628 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700629 } else {
630 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000631 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700632 }
633 }
634
Liz Kammer585cac22020-07-06 09:12:57 -0700635 var argsPropertyName string
636 flags := make([]string, 0)
637 if j.properties.Args != nil && j.properties.Flags != nil {
638 ctx.PropertyErrorf("args", "flags is set. Cannot set args")
639 } else if args := proptools.String(j.properties.Args); args != "" {
640 flags = append(flags, args)
641 argsPropertyName = "args"
642 } else {
643 flags = append(flags, j.properties.Flags...)
644 argsPropertyName = "flags"
645 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700646
Liz Kammer585cac22020-07-06 09:12:57 -0700647 for _, flag := range flags {
648 args, err := android.Expand(flag, func(name string) (string, error) {
649 if strings.HasPrefix(name, "location ") {
650 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
651 if paths, ok := argFilesMap[label]; ok {
652 return paths, nil
653 } else {
654 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
655 label, strings.Join(argFileLabels, ", "))
656 }
657 } else if name == "genDir" {
658 return android.PathForModuleGen(ctx).String(), nil
659 }
660 return "", fmt.Errorf("unknown variable '$(%s)'", name)
661 })
662
663 if err != nil {
664 ctx.PropertyErrorf(argsPropertyName, "%s", err.Error())
665 }
666 j.args = append(j.args, args)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700667 }
668
Nan Zhang581fd212018-01-10 16:06:12 -0800669 return deps
670}
671
672func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
673 j.addDeps(ctx)
674}
675
676func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
677 deps := j.collectDeps(ctx)
678
Colin Crossdaa4c672019-07-15 22:53:46 -0700679 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800680
Colin Crossdaa4c672019-07-15 22:53:46 -0700681 outDir := android.PathForModuleOut(ctx, "out")
682 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
683
684 j.stubsSrcJar = nil
685
686 rule := android.NewRuleBuilder()
687
688 rule.Command().Text("rm -rf").Text(outDir.String())
689 rule.Command().Text("mkdir -p").Text(outDir.String())
690
691 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700692
Colin Cross83bb3162018-06-25 15:48:06 -0700693 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800694
Colin Crossdaa4c672019-07-15 22:53:46 -0700695 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
696 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800697
Colin Cross1e743852019-10-28 11:37:20 -0700698 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700699 Flag("-J-Xmx1024m").
700 Flag("-XDignore.symbol.file").
701 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800702
Colin Crossdaa4c672019-07-15 22:53:46 -0700703 rule.Command().
704 BuiltTool(ctx, "soong_zip").
705 Flag("-write_if_changed").
706 Flag("-d").
707 FlagWithOutput("-o ", j.docZip).
708 FlagWithArg("-C ", outDir.String()).
709 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700710
Colin Crossdaa4c672019-07-15 22:53:46 -0700711 rule.Restat()
712
713 zipSyncCleanupCmd(rule, srcJarDir)
714
715 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800716}
717
Nan Zhanga40da042018-08-01 12:48:00 -0700718//
719// Droiddoc
720//
721type Droiddoc struct {
722 Javadoc
723
Liz Kammere1ab2502020-09-10 15:29:25 +0000724 properties DroiddocProperties
Nan Zhanga40da042018-08-01 12:48:00 -0700725}
726
Colin Crossa3002fc2019-07-08 16:48:04 -0700727// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700728func DroiddocFactory() android.Module {
729 module := &Droiddoc{}
730
731 module.AddProperties(&module.properties,
732 &module.Javadoc.properties)
733
734 InitDroiddocModule(module, android.HostAndDeviceSupported)
735 return module
736}
737
Colin Crossa3002fc2019-07-08 16:48:04 -0700738// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700739func DroiddocHostFactory() android.Module {
740 module := &Droiddoc{}
741
742 module.AddProperties(&module.properties,
743 &module.Javadoc.properties)
744
745 InitDroiddocModule(module, android.HostSupported)
746 return module
747}
748
Liz Kammere1ab2502020-09-10 15:29:25 +0000749func (d *Droiddoc) OutputFiles(tag string) (android.Paths, error) {
750 switch tag {
751 case "", ".docs.zip":
752 return android.Paths{d.Javadoc.docZip}, nil
753 default:
754 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
755 }
Nan Zhanga40da042018-08-01 12:48:00 -0700756}
757
Nan Zhang581fd212018-01-10 16:06:12 -0800758func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
759 d.Javadoc.addDeps(ctx)
760
Nan Zhang79614d12018-04-19 18:03:39 -0700761 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800762 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
763 }
Nan Zhang581fd212018-01-10 16:06:12 -0800764}
765
Colin Crossab054432019-07-15 16:13:59 -0700766func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800767 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700768 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
769 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
770 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700771 cmd.FlagWithArg("-source ", "1.8").
772 Flag("-J-Xmx1600m").
773 Flag("-J-XX:-OmitStackTraceInFastThrow").
774 Flag("-XDignore.symbol.file").
775 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
776 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800777 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700778 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 -0700779
Nan Zhanga40da042018-08-01 12:48:00 -0700780 if String(d.properties.Custom_template) == "" {
781 // TODO: This is almost always droiddoc-templates-sdk
782 ctx.PropertyErrorf("custom_template", "must specify a template")
783 }
784
785 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700786 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700787 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700788 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000789 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700790 }
791 })
792
793 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700794 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
795 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
796 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700797 }
798
799 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700800 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
801 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
802 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700803 }
804
805 if len(d.properties.Html_dirs) > 2 {
806 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
807 }
808
Colin Cross8a497952019-03-05 22:25:09 -0800809 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700810 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700811
Colin Crossab054432019-07-15 16:13:59 -0700812 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700813
814 if String(d.properties.Proofread_file) != "" {
815 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700816 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700817 }
818
819 if String(d.properties.Todo_file) != "" {
820 // tricky part:
821 // we should not compute full path for todo_file through PathForModuleOut().
822 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700823 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
824 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700825 }
826
827 if String(d.properties.Resourcesdir) != "" {
828 // TODO: should we add files under resourcesDir to the implicits? It seems that
829 // resourcesDir is one sub dir of htmlDir
830 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700831 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700832 }
833
834 if String(d.properties.Resourcesoutdir) != "" {
835 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700836 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700837 }
Nan Zhanga40da042018-08-01 12:48:00 -0700838}
839
Colin Crossab054432019-07-15 16:13:59 -0700840func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700841 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700842 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
843 rule.Command().Text("cp").
844 Input(staticDocIndexRedirect).
845 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700846 }
847
848 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700849 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
850 rule.Command().Text("cp").
851 Input(staticDocProperties).
852 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700853 }
Nan Zhanga40da042018-08-01 12:48:00 -0700854}
855
Colin Crossab054432019-07-15 16:13:59 -0700856func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700857 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700858
859 cmd := rule.Command().
860 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
861 Flag(config.JavacVmFlags).
862 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700863 FlagWithRspFileInputList("@", srcs).
864 FlagWithInput("@", srcJarList)
865
Colin Crossab054432019-07-15 16:13:59 -0700866 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
867 // based stubs generation.
868 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
869 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
870 // the correct package name base path.
871 if len(sourcepaths) > 0 {
872 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
873 } else {
874 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
875 }
876
877 cmd.FlagWithArg("-d ", outDir.String()).
878 Flag("-quiet")
879
880 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700881}
882
Colin Crossdaa4c672019-07-15 22:53:46 -0700883func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
884 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
885 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
886
887 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
888
889 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
890 cmd.Flag(flag).Implicits(deps)
891
892 cmd.FlagWithArg("--patch-module ", "java.base=.")
893
894 if len(classpath) > 0 {
895 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
896 }
897
898 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700899}
900
Colin Crossdaa4c672019-07-15 22:53:46 -0700901func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
902 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
903 sourcepaths android.Paths) *android.RuleBuilderCommand {
904
905 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
906
907 if len(bootclasspath) == 0 && ctx.Device() {
908 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
909 // ensure java does not fall back to the default bootclasspath.
910 cmd.FlagWithArg("-bootclasspath ", `""`)
911 } else if len(bootclasspath) > 0 {
912 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
913 }
914
915 if len(classpath) > 0 {
916 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
917 }
918
919 return cmd
920}
921
Colin Crossab054432019-07-15 16:13:59 -0700922func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
923 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700924
Colin Crossab054432019-07-15 16:13:59 -0700925 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
926 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
927
928 return rule.Command().
929 BuiltTool(ctx, "dokka").
930 Flag(config.JavacVmFlags).
931 Flag(srcJarDir.String()).
932 FlagWithInputList("-classpath ", dokkaClasspath, ":").
933 FlagWithArg("-format ", "dac").
934 FlagWithArg("-dacRoot ", "/reference/kotlin").
935 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700936}
937
938func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
939 deps := d.Javadoc.collectDeps(ctx)
940
Colin Crossdaa4c672019-07-15 22:53:46 -0700941 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Colin Crossdaa4c672019-07-15 22:53:46 -0700942
Nan Zhang1598a9e2018-09-04 17:14:32 -0700943 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
944 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700945
Colin Crossab054432019-07-15 16:13:59 -0700946 outDir := android.PathForModuleOut(ctx, "out")
947 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700948
Colin Crossab054432019-07-15 16:13:59 -0700949 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700950
Colin Crossab054432019-07-15 16:13:59 -0700951 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
952
953 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700954 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700955 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700956 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700957 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700958 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700959 }
960
Liz Kammer585cac22020-07-06 09:12:57 -0700961 cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
Colin Crossab054432019-07-15 16:13:59 -0700962
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000963 if d.properties.Compat_config != nil {
964 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
965 cmd.FlagWithInput("-compatconfig ", compatConfig)
966 }
967
Colin Crossab054432019-07-15 16:13:59 -0700968 var desc string
969 if Bool(d.properties.Dokka_enabled) {
970 desc = "dokka"
971 } else {
972 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
973
974 for _, o := range d.Javadoc.properties.Out {
975 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
976 }
977
978 d.postDoclavaCmds(ctx, rule)
979 desc = "doclava"
980 }
981
982 rule.Command().
983 BuiltTool(ctx, "soong_zip").
984 Flag("-write_if_changed").
985 Flag("-d").
986 FlagWithOutput("-o ", d.docZip).
987 FlagWithArg("-C ", outDir.String()).
988 FlagWithArg("-D ", outDir.String())
989
Colin Crossab054432019-07-15 16:13:59 -0700990 rule.Restat()
991
992 zipSyncCleanupCmd(rule, srcJarDir)
993
994 rule.Build(pctx, ctx, "javadoc", desc)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700995}
996
997//
998// Droidstubs
999//
1000type Droidstubs struct {
1001 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001002 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001003
Pete Gillin581d6082018-10-22 15:55:04 +01001004 properties DroidstubsProperties
1005 apiFile android.WritablePath
1006 apiXmlFile android.WritablePath
1007 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001008 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001009 removedApiFile android.WritablePath
1010 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001011 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001012
1013 checkCurrentApiTimestamp android.WritablePath
1014 updateCurrentApiTimestamp android.WritablePath
1015 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001016 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001017 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001018
Pete Gillin581d6082018-10-22 15:55:04 +01001019 checkNullabilityWarningsTimestamp android.WritablePath
1020
Nan Zhang1598a9e2018-09-04 17:14:32 -07001021 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001022 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001023
1024 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001025
1026 jdiffDocZip android.WritablePath
1027 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001028
1029 metadataZip android.WritablePath
1030 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001031}
1032
Colin Crossa3002fc2019-07-08 16:48:04 -07001033// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1034// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1035// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001036func DroidstubsFactory() android.Module {
1037 module := &Droidstubs{}
1038
1039 module.AddProperties(&module.properties,
1040 &module.Javadoc.properties)
1041
1042 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001043 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001044 return module
1045}
1046
Colin Crossa3002fc2019-07-08 16:48:04 -07001047// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1048// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1049// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1050// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001051func DroidstubsHostFactory() android.Module {
1052 module := &Droidstubs{}
1053
1054 module.AddProperties(&module.properties,
1055 &module.Javadoc.properties)
1056
1057 InitDroiddocModule(module, android.HostSupported)
1058 return module
1059}
1060
Colin Cross014489c2020-06-02 20:09:13 -07001061func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) {
1062 switch tag {
1063 case "":
1064 return android.Paths{d.stubsSrcJar}, nil
1065 case ".docs.zip":
1066 return android.Paths{d.docZip}, nil
1067 case ".annotations.zip":
1068 return android.Paths{d.annotationsZip}, nil
1069 case ".api_versions.xml":
1070 return android.Paths{d.apiVersionsXml}, nil
1071 default:
1072 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1073 }
1074}
1075
Nan Zhang1598a9e2018-09-04 17:14:32 -07001076func (d *Droidstubs) ApiFilePath() android.Path {
1077 return d.apiFilePath
1078}
1079
Paul Duffin1fd005d2020-04-09 01:08:11 +01001080func (d *Droidstubs) RemovedApiFilePath() android.Path {
1081 return d.removedApiFile
1082}
1083
Paul Duffin3d1248c2020-04-09 00:10:17 +01001084func (d *Droidstubs) StubsSrcJar() android.Path {
1085 return d.stubsSrcJar
1086}
1087
Nan Zhang1598a9e2018-09-04 17:14:32 -07001088func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1089 d.Javadoc.addDeps(ctx)
1090
Paul Duffin160fe412020-05-10 19:32:20 +01001091 // If requested clear any properties that provide information about the latest version
1092 // of an API and which reference non-existent modules.
Inseob Kim38449af2019-02-28 14:24:05 +09001093 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1094 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
Paul Duffin160fe412020-05-10 19:32:20 +01001095
1096 // If the new_since references a module, e.g. :module-latest-api and the module
1097 // does not exist then clear it.
1098 newSinceSrc := d.properties.Check_api.Api_lint.New_since
1099 newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc))
1100 if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) {
1101 d.properties.Check_api.Api_lint.New_since = nil
1102 }
Inseob Kim38449af2019-02-28 14:24:05 +09001103 }
1104
Nan Zhang1598a9e2018-09-04 17:14:32 -07001105 if len(d.properties.Merge_annotations_dirs) != 0 {
1106 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1107 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1108 }
1109 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001110
Pete Gillin77167902018-09-19 18:16:26 +01001111 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1112 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1113 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1114 }
1115 }
1116
Nan Zhang9c69a122018-08-22 10:22:08 -07001117 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1118 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1119 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1120 }
1121 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001122}
1123
Paul Duffin3ae29512020-04-08 18:18:03 +01001124func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001125 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1126 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001127 String(d.properties.Api_filename) != "" {
Liz Kammer9ed79152020-08-24 15:56:32 -07001128 filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt")
1129 d.apiFile = android.PathForModuleOut(ctx, filename)
Colin Cross33961b52019-07-11 11:01:22 -07001130 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001131 d.apiFilePath = d.apiFile
1132 }
1133
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001134 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1135 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001136 String(d.properties.Removed_api_filename) != "" {
Liz Kammer9ed79152020-08-24 15:56:32 -07001137 filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt")
1138 d.removedApiFile = android.PathForModuleOut(ctx, filename)
Colin Cross33961b52019-07-11 11:01:22 -07001139 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001140 }
1141
Nan Zhang1598a9e2018-09-04 17:14:32 -07001142 if String(d.properties.Removed_dex_api_filename) != "" {
1143 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001144 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001145 }
1146
Nan Zhang9c69a122018-08-22 10:22:08 -07001147 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001148 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1149 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001150 }
1151
Paul Duffin3ae29512020-04-08 18:18:03 +01001152 if stubsDir.Valid() {
1153 if Bool(d.properties.Create_doc_stubs) {
1154 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1155 } else {
1156 cmd.FlagWithArg("--stubs ", stubsDir.String())
Paul Duffin6877e6d2020-09-25 19:59:14 +01001157 if !Bool(d.properties.Output_javadoc_comments) {
1158 cmd.Flag("--exclude-documentation-from-stubs")
1159 }
Paul Duffin3ae29512020-04-08 18:18:03 +01001160 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001161 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001162}
1163
Colin Cross33961b52019-07-11 11:01:22 -07001164func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001165 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001166 cmd.Flag("--include-annotations")
1167
Pete Gillinc382a562018-11-14 18:45:46 +00001168 validatingNullability :=
Liz Kammer585cac22020-07-06 09:12:57 -07001169 android.InList("--validate-nullability-from-merged-stubs", d.Javadoc.args) ||
Pete Gillinc382a562018-11-14 18:45:46 +00001170 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001171
Pete Gillina262c052018-09-14 14:25:48 +01001172 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001173 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001174 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001175 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001176 }
Colin Cross33961b52019-07-11 11:01:22 -07001177
Pete Gillinc382a562018-11-14 18:45:46 +00001178 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001179 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001180 }
Colin Cross33961b52019-07-11 11:01:22 -07001181
Pete Gillina262c052018-09-14 14:25:48 +01001182 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001183 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001184 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001185 }
Nan Zhanga40da042018-08-01 12:48:00 -07001186
1187 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001188 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001189
Anton Hansson9d7c3fb2020-05-21 10:11:31 +01001190 if len(d.properties.Merge_annotations_dirs) != 0 {
1191 d.mergeAnnoDirFlags(ctx, cmd)
Nan Zhanga40da042018-08-01 12:48:00 -07001192 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001193
Colin Cross33961b52019-07-11 11:01:22 -07001194 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1195 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1196 FlagWithArg("--hide ", "SuperfluousPrefix").
1197 FlagWithArg("--hide ", "AnnotationExtraction")
1198 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001199}
1200
Colin Cross33961b52019-07-11 11:01:22 -07001201func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1202 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1203 if t, ok := m.(*ExportedDroiddocDir); ok {
1204 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1205 } else {
1206 ctx.PropertyErrorf("merge_annotations_dirs",
1207 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1208 }
1209 })
1210}
1211
1212func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001213 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1214 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001215 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001216 } else {
1217 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1218 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1219 }
1220 })
Nan Zhanga40da042018-08-01 12:48:00 -07001221}
1222
Colin Cross33961b52019-07-11 11:01:22 -07001223func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Liz Kammer3d894b72020-08-04 09:55:13 -07001224 if !Bool(d.properties.Api_levels_annotations_enabled) {
1225 return
Nan Zhang9c69a122018-08-22 10:22:08 -07001226 }
Liz Kammer3d894b72020-08-04 09:55:13 -07001227
1228 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
1229
1230 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1231 ctx.PropertyErrorf("api_levels_annotations_dirs",
1232 "has to be non-empty if api levels annotations was enabled!")
1233 }
1234
1235 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1236 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
Dan Albert4f378d72020-07-23 17:32:15 -07001237 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String())
Liz Kammer3d894b72020-08-04 09:55:13 -07001238 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
1239
1240 filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")
1241
1242 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1243 if t, ok := m.(*ExportedDroiddocDir); ok {
1244 for _, dep := range t.deps {
1245 if strings.HasSuffix(dep.String(), filename) {
1246 cmd.Implicit(dep)
1247 }
1248 }
1249 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/"+filename)
1250 } else {
1251 ctx.PropertyErrorf("api_levels_annotations_dirs",
1252 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1253 }
1254 })
Nan Zhang9c69a122018-08-22 10:22:08 -07001255}
1256
Colin Cross33961b52019-07-11 11:01:22 -07001257func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Dan Willemsen9f435972020-05-28 15:28:00 -07001258 if Bool(d.properties.Jdiff_enabled) && d.apiFile != nil {
Nan Zhang71bbe632018-09-17 14:32:21 -07001259 if d.apiFile.String() == "" {
1260 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1261 }
1262
1263 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001264 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001265
1266 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1267 ctx.PropertyErrorf("check_api.last_released.api_file",
1268 "has to be non-empty if jdiff was enabled!")
1269 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001270
Colin Cross33961b52019-07-11 11:01:22 -07001271 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001272 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001273 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1274 }
1275}
Nan Zhang71bbe632018-09-17 14:32:21 -07001276
Colin Cross1e743852019-10-28 11:37:20 -07001277func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001278 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicitsRsp android.WritablePath, sandbox bool) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001279 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1280 rule.HighMem()
Ramy Medhat427683c2020-04-30 03:08:37 -04001281 cmd := rule.Command()
Ramy Medhat16f23a42020-09-03 01:29:49 -04001282 if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_METALAVA") {
Ramy Medhat427683c2020-04-30 03:08:37 -04001283 rule.Remoteable(android.RemoteRuleSupports{RBE: true})
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001284 pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava")
1285 execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
1286 labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"}
1287 if !sandbox {
1288 execStrategy = remoteexec.LocalExecStrategy
1289 labels["shallow"] = "true"
Ramy Medhat427683c2020-04-30 03:08:37 -04001290 }
1291 inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
1292 if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
1293 inputs = append(inputs, strings.Split(v, ",")...)
1294 }
1295 cmd.Text((&remoteexec.REParams{
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001296 Labels: labels,
Ramy Medhat427683c2020-04-30 03:08:37 -04001297 ExecStrategy: execStrategy,
1298 Inputs: inputs,
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001299 RSPFile: implicitsRsp.String(),
Ramy Medhat427683c2020-04-30 03:08:37 -04001300 ToolchainInputs: []string{config.JavaCmd(ctx).String()},
1301 Platform: map[string]string{remoteexec.PoolKey: pool},
1302 }).NoVarTemplate(ctx.Config()))
1303 }
1304
1305 cmd.BuiltTool(ctx, "metalava").
Colin Cross33961b52019-07-11 11:01:22 -07001306 Flag(config.JavacVmFlags).
Aurimas Liutikas4c5efde2020-09-21 11:18:06 -07001307 Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED").
Colin Cross33961b52019-07-11 11:01:22 -07001308 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001309 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001310 FlagWithRspFileInputList("@", srcs).
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001311 FlagWithInput("@", srcJarList)
1312
1313 if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" {
1314 cmd.Implicit(android.PathForSource(ctx, javaHome))
1315 }
1316
1317 if sandbox {
1318 cmd.FlagWithOutput("--strict-input-files ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
1319 } else {
1320 cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
1321 }
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001322
Colin Cross238c1f32020-06-07 16:58:18 -07001323 if implicitsRsp != nil {
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001324 cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
1325 }
Colin Cross33961b52019-07-11 11:01:22 -07001326
1327 if len(bootclasspath) > 0 {
1328 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001329 }
1330
Colin Cross33961b52019-07-11 11:01:22 -07001331 if len(classpath) > 0 {
1332 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1333 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001334
Colin Cross33961b52019-07-11 11:01:22 -07001335 if len(sourcepaths) > 0 {
1336 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1337 } else {
1338 cmd.FlagWithArg("-sourcepath ", `""`)
1339 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001340
Colin Cross33961b52019-07-11 11:01:22 -07001341 cmd.Flag("--no-banner").
1342 Flag("--color").
1343 Flag("--quiet").
Makoto Onuki0df103a2020-07-17 15:11:24 -07001344 Flag("--format=v2").
1345 FlagWithArg("--repeat-errors-max ", "10").
1346 FlagWithArg("--hide ", "UnresolvedImport")
Nan Zhang86d2d552018-08-09 15:33:27 -07001347
Colin Cross33961b52019-07-11 11:01:22 -07001348 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001349}
1350
Nan Zhang1598a9e2018-09-04 17:14:32 -07001351func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001352 deps := d.Javadoc.collectDeps(ctx)
1353
1354 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001355
Colin Cross33961b52019-07-11 11:01:22 -07001356 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001357
Colin Cross33961b52019-07-11 11:01:22 -07001358 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001359
Colin Cross33961b52019-07-11 11:01:22 -07001360 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001361
Paul Duffin3ae29512020-04-08 18:18:03 +01001362 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1363 var stubsDir android.OptionalPath
1364 if generateStubs {
1365 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1366 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1367 rule.Command().Text("rm -rf").Text(stubsDir.String())
1368 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1369 }
Nan Zhanga40da042018-08-01 12:48:00 -07001370
Colin Cross33961b52019-07-11 11:01:22 -07001371 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1372
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001373 implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp")
1374
Colin Cross33961b52019-07-11 11:01:22 -07001375 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001376 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp,
1377 Bool(d.Javadoc.properties.Sandbox))
1378 cmd.Implicits(d.Javadoc.implicits)
Colin Cross33961b52019-07-11 11:01:22 -07001379
1380 d.stubsFlags(ctx, cmd, stubsDir)
1381
1382 d.annotationsFlags(ctx, cmd)
1383 d.inclusionAnnotationsFlags(ctx, cmd)
1384 d.apiLevelsAnnotationsFlags(ctx, cmd)
1385 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001386
Liz Kammer585cac22020-07-06 09:12:57 -07001387 if android.InList("--generate-documentation", d.Javadoc.args) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001388 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1389 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1390 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
Liz Kammer585cac22020-07-06 09:12:57 -07001391 d.Javadoc.args = append(d.Javadoc.args, "-nodocs")
Nan Zhang79614d12018-04-19 18:03:39 -07001392 }
Colin Cross33961b52019-07-11 11:01:22 -07001393
Liz Kammer585cac22020-07-06 09:12:57 -07001394 cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
Colin Cross33961b52019-07-11 11:01:22 -07001395 for _, o := range d.Javadoc.properties.Out {
1396 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1397 }
1398
Makoto Onuki88b99052020-04-27 17:22:16 -07001399 // Add options for the other optional tasks: API-lint and check-released.
1400 // We generate separate timestamp files for them.
1401
1402 doApiLint := false
1403 doCheckReleased := false
1404
1405 // Add API lint options.
1406
Dan Willemsen9f435972020-05-28 15:28:00 -07001407 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) {
Makoto Onuki88b99052020-04-27 17:22:16 -07001408 doApiLint = true
1409
1410 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1411 if newSince.Valid() {
1412 cmd.FlagWithInput("--api-lint ", newSince.Path())
1413 } else {
1414 cmd.Flag("--api-lint")
1415 }
1416 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1417 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1418
Makoto Onuki194c43f2020-04-27 17:22:16 -07001419 // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released.
1420 if d.Name() != "android.car-system-stubs-docs" &&
Anton Hanssonb30f5932020-09-16 13:14:18 +01001421 d.Name() != "android.car-stubs-docs" {
Makoto Onuki194c43f2020-04-27 17:22:16 -07001422 cmd.Flag("--lints-as-errors")
1423 cmd.Flag("--warnings-as-errors") // Most lints are actually warnings.
1424 }
1425
Makoto Onuki88b99052020-04-27 17:22:16 -07001426 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1427 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1428 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1429
1430 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1431 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1432 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1433 // which is why we have '"$PWD"$' in it.
1434 //
1435 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1436 // message and metalava's one?
1437 msg := `$'` + // Enclose with $' ... '
1438 `************************************************************\n` +
1439 `Your API changes are triggering API Lint warnings or errors.\n` +
1440 `To make these errors go away, fix the code according to the\n` +
1441 `error and/or warning messages above.\n` +
1442 `\n` +
1443 `If it is not possible to do so, there are workarounds:\n` +
1444 `\n` +
1445 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1446
1447 if baselineFile.Valid() {
1448 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1449 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1450
1451 msg += fmt.Sprintf(``+
1452 `2. You can update the baseline by executing the following\n`+
1453 ` command:\n`+
Anton Hansson3361a292020-05-11 15:38:31 +01001454 ` cp \\\n`+
1455 ` "'"$PWD"$'/%s" \\\n`+
1456 ` "'"$PWD"$'/%s"\n`+
Makoto Onuki88b99052020-04-27 17:22:16 -07001457 ` To submit the revised baseline.txt to the main Android\n`+
1458 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1459 } else {
1460 msg += fmt.Sprintf(``+
1461 `2. You can add a baseline file of existing lint failures\n`+
1462 ` to the build rule of %s.\n`, d.Name())
1463 }
1464 // Note the message ends with a ' (single quote), to close the $' ... ' .
1465 msg += `************************************************************\n'`
1466
1467 cmd.FlagWithArg("--error-message:api-lint ", msg)
1468 }
1469
1470 // Add "check released" options. (Detect incompatible API changes from the last public release)
1471
Dan Willemsen9f435972020-05-28 15:28:00 -07001472 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") {
Makoto Onuki88b99052020-04-27 17:22:16 -07001473 doCheckReleased = true
1474
1475 if len(d.Javadoc.properties.Out) > 0 {
1476 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1477 }
1478
1479 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1480 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1481 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1482 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1483
1484 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1485
1486 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1487 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1488
1489 if baselineFile.Valid() {
1490 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1491 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1492 }
1493
1494 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1495 msg := `$'\n******************************\n` +
1496 `You have tried to change the API from what has been previously released in\n` +
1497 `an SDK. Please fix the errors listed above.\n` +
1498 `******************************\n'`
1499
1500 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1501 }
1502
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001503 impRule := android.NewRuleBuilder()
1504 impCmd := impRule.Command()
Liz Kammer20ebfb42020-07-28 11:32:07 -07001505 // An action that copies the ninja generated rsp file to a new location. This allows us to
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001506 // add a large number of inputs to a file without exceeding bash command length limits (which
1507 // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
1508 // rsp file to be ${output}.rsp.
1509 impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp)
1510 impRule.Build(pctx, ctx, "implicitsGen", "implicits generation")
1511 cmd.Implicit(implicitsRsp)
1512
Paul Duffin3ae29512020-04-08 18:18:03 +01001513 if generateStubs {
1514 rule.Command().
1515 BuiltTool(ctx, "soong_zip").
1516 Flag("-write_if_changed").
1517 Flag("-jar").
1518 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1519 FlagWithArg("-C ", stubsDir.String()).
1520 FlagWithArg("-D ", stubsDir.String())
1521 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001522
1523 if Bool(d.properties.Write_sdk_values) {
1524 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1525 rule.Command().
1526 BuiltTool(ctx, "soong_zip").
1527 Flag("-write_if_changed").
1528 Flag("-d").
1529 FlagWithOutput("-o ", d.metadataZip).
1530 FlagWithArg("-C ", d.metadataDir.String()).
1531 FlagWithArg("-D ", d.metadataDir.String())
1532 }
1533
Makoto Onuki88b99052020-04-27 17:22:16 -07001534 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1535 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1536 if doApiLint {
1537 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1538 }
1539 if doCheckReleased {
1540 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1541 }
1542
Colin Cross33961b52019-07-11 11:01:22 -07001543 rule.Restat()
1544
1545 zipSyncCleanupCmd(rule, srcJarDir)
1546
Makoto Onuki88b99052020-04-27 17:22:16 -07001547 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001548
Dan Willemsen9f435972020-05-28 15:28:00 -07001549 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") {
Colin Cross33961b52019-07-11 11:01:22 -07001550
1551 if len(d.Javadoc.properties.Out) > 0 {
1552 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1553 }
1554
1555 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1556 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001557 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onuki5405a732020-04-16 17:02:40 -07001558
1559 if baselineFile.Valid() {
Makoto Onuki88b99052020-04-27 17:22:16 -07001560 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onuki5405a732020-04-16 17:02:40 -07001561 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001562
Nan Zhang2760dfc2018-08-24 17:32:54 +00001563 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001564
Colin Cross33961b52019-07-11 11:01:22 -07001565 rule := android.NewRuleBuilder()
1566
Makoto Onuki5405a732020-04-16 17:02:40 -07001567 // Diff command line.
Makoto Onuki88b99052020-04-27 17:22:16 -07001568 // -F matches the closest "opening" line, such as "package android {"
1569 // and " public class Intent {".
Makoto Onuki5405a732020-04-16 17:02:40 -07001570 diff := `diff -u -F '{ *$'`
1571
Colin Cross33961b52019-07-11 11:01:22 -07001572 rule.Command().Text("( true")
Makoto Onuki5405a732020-04-16 17:02:40 -07001573 rule.Command().
1574 Text(diff).
1575 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001576
Makoto Onuki5405a732020-04-16 17:02:40 -07001577 rule.Command().
1578 Text(diff).
1579 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001580
1581 msg := fmt.Sprintf(`\n******************************\n`+
1582 `You have tried to change the API from what has been previously approved.\n\n`+
1583 `To make these errors go away, you have two choices:\n`+
Makoto Onuki5405a732020-04-16 17:02:40 -07001584 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1585 ` to the new methods, etc. shown in the above diff.\n\n`+
1586 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001587 ` make %s-update-current-api\n\n`+
1588 ` To submit the revised current.txt to the main Android repository,\n`+
1589 ` you will need approval.\n`+
1590 `******************************\n`, ctx.ModuleName())
1591
1592 rule.Command().
1593 Text("touch").Output(d.checkCurrentApiTimestamp).
1594 Text(") || (").
1595 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1596 Text("; exit 38").
1597 Text(")")
1598
Makoto Onuki5405a732020-04-16 17:02:40 -07001599 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001600
1601 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001602
1603 // update API rule
1604 rule = android.NewRuleBuilder()
1605
1606 rule.Command().Text("( true")
1607
1608 rule.Command().
1609 Text("cp").Flag("-f").
1610 Input(d.apiFile).Flag(apiFile.String())
1611
1612 rule.Command().
1613 Text("cp").Flag("-f").
1614 Input(d.removedApiFile).Flag(removedApiFile.String())
1615
1616 msg = "failed to update public API"
1617
1618 rule.Command().
1619 Text("touch").Output(d.updateCurrentApiTimestamp).
1620 Text(") || (").
1621 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1622 Text("; exit 38").
1623 Text(")")
1624
1625 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001626 }
Nan Zhanga40da042018-08-01 12:48:00 -07001627
Pete Gillin581d6082018-10-22 15:55:04 +01001628 if String(d.properties.Check_nullability_warnings) != "" {
1629 if d.nullabilityWarningsFile == nil {
1630 ctx.PropertyErrorf("check_nullability_warnings",
1631 "Cannot specify check_nullability_warnings unless validating nullability")
1632 }
Colin Cross33961b52019-07-11 11:01:22 -07001633
1634 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1635
Pete Gillin581d6082018-10-22 15:55:04 +01001636 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001637
Pete Gillin581d6082018-10-22 15:55:04 +01001638 msg := fmt.Sprintf(`\n******************************\n`+
1639 `The warnings encountered during nullability annotation validation did\n`+
1640 `not match the checked in file of expected warnings. The diffs are shown\n`+
1641 `above. You have two options:\n`+
1642 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1643 ` 2. Update the file of expected warnings by running:\n`+
1644 ` cp %s %s\n`+
1645 ` and submitting the updated file as part of your change.`,
1646 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001647
1648 rule := android.NewRuleBuilder()
1649
1650 rule.Command().
1651 Text("(").
1652 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1653 Text("&&").
1654 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1655 Text(") || (").
1656 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1657 Text("; exit 38").
1658 Text(")")
1659
1660 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001661 }
1662
Dan Willemsen9f435972020-05-28 15:28:00 -07001663 if Bool(d.properties.Jdiff_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001664 if len(d.Javadoc.properties.Out) > 0 {
1665 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1666 }
1667
1668 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1669 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1670 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1671
1672 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001673
Nan Zhang86b06202018-09-21 17:09:21 -07001674 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1675 // since there's cron job downstream that fetch this .zip file periodically.
1676 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001677 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1678 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1679
Nan Zhang71bbe632018-09-17 14:32:21 -07001680 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001681
Colin Cross33961b52019-07-11 11:01:22 -07001682 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1683 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001684
Colin Cross33961b52019-07-11 11:01:22 -07001685 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1686
Colin Crossdaa4c672019-07-15 22:53:46 -07001687 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001688 deps.bootClasspath, deps.classpath, d.sourcepaths)
1689
1690 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001691 Flag("-XDignore.symbol.file").
1692 FlagWithArg("-doclet ", "jdiff.JDiff").
1693 FlagWithInput("-docletpath ", jdiff).
Paul Duffin10269f12020-06-19 18:39:55 +01001694 Flag("-quiet")
1695
1696 if d.apiXmlFile != nil {
1697 cmd.FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1698 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1699 Implicit(d.apiXmlFile)
1700 }
1701
1702 if d.lastReleasedApiXmlFile != nil {
1703 cmd.FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1704 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1705 Implicit(d.lastReleasedApiXmlFile)
1706 }
Colin Cross33961b52019-07-11 11:01:22 -07001707
Colin Cross33961b52019-07-11 11:01:22 -07001708 rule.Command().
1709 BuiltTool(ctx, "soong_zip").
1710 Flag("-write_if_changed").
1711 Flag("-d").
1712 FlagWithOutput("-o ", d.jdiffDocZip).
1713 FlagWithArg("-C ", outDir.String()).
1714 FlagWithArg("-D ", outDir.String())
1715
1716 rule.Command().
1717 BuiltTool(ctx, "soong_zip").
1718 Flag("-write_if_changed").
1719 Flag("-jar").
1720 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1721 FlagWithArg("-C ", stubsDir.String()).
1722 FlagWithArg("-D ", stubsDir.String())
1723
1724 rule.Restat()
1725
1726 zipSyncCleanupCmd(rule, srcJarDir)
1727
1728 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001729 }
Nan Zhang581fd212018-01-10 16:06:12 -08001730}
Dan Willemsencc090972018-02-26 14:33:31 -08001731
Nan Zhanga40da042018-08-01 12:48:00 -07001732//
Nan Zhangf4936b02018-08-01 15:00:28 -07001733// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001734//
Dan Willemsencc090972018-02-26 14:33:31 -08001735var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001736var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001737var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001738var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001739
Nan Zhangf4936b02018-08-01 15:00:28 -07001740type ExportedDroiddocDirProperties struct {
1741 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001742 Path *string
1743}
1744
Nan Zhangf4936b02018-08-01 15:00:28 -07001745type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001746 android.ModuleBase
1747
Nan Zhangf4936b02018-08-01 15:00:28 -07001748 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001749
1750 deps android.Paths
1751 dir android.Path
1752}
1753
Colin Crossa3002fc2019-07-08 16:48:04 -07001754// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001755func ExportedDroiddocDirFactory() android.Module {
1756 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001757 module.AddProperties(&module.properties)
1758 android.InitAndroidModule(module)
1759 return module
1760}
1761
Nan Zhangf4936b02018-08-01 15:00:28 -07001762func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001763
Nan Zhangf4936b02018-08-01 15:00:28 -07001764func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001765 path := String(d.properties.Path)
1766 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001767 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001768}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001769
1770//
1771// Defaults
1772//
1773type DocDefaults struct {
1774 android.ModuleBase
1775 android.DefaultsModuleBase
1776}
1777
Nan Zhangb2b33de2018-02-23 11:18:47 -08001778func DocDefaultsFactory() android.Module {
1779 module := &DocDefaults{}
1780
1781 module.AddProperties(
1782 &JavadocProperties{},
1783 &DroiddocProperties{},
1784 )
1785
1786 android.InitDefaultsModule(module)
1787
1788 return module
1789}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001790
1791func StubsDefaultsFactory() android.Module {
1792 module := &DocDefaults{}
1793
1794 module.AddProperties(
1795 &JavadocProperties{},
1796 &DroidstubsProperties{},
1797 )
1798
1799 android.InitDefaultsModule(module)
1800
1801 return module
1802}
Colin Cross33961b52019-07-11 11:01:22 -07001803
1804func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1805 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1806
1807 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1808 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1809 srcJarList := srcJarDir.Join(ctx, "list")
1810
1811 rule.Temporary(srcJarList)
1812
1813 rule.Command().BuiltTool(ctx, "zipsync").
1814 FlagWithArg("-d ", srcJarDir.String()).
1815 FlagWithOutput("-l ", srcJarList).
1816 FlagWithArg("-f ", `"*.java"`).
1817 Inputs(srcJars)
1818
1819 return srcJarList
1820}
1821
1822func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1823 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1824}
Paul Duffin91547182019-11-12 19:39:36 +00001825
1826var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1827
1828type PrebuiltStubsSourcesProperties struct {
1829 Srcs []string `android:"path"`
1830}
1831
1832type PrebuiltStubsSources struct {
1833 android.ModuleBase
1834 android.DefaultableModuleBase
1835 prebuilt android.Prebuilt
1836 android.SdkBase
1837
1838 properties PrebuiltStubsSourcesProperties
1839
Paul Duffin9b478b02019-12-10 13:41:51 +00001840 // The source directories containing stubs source files.
1841 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001842 stubsSrcJar android.ModuleOutPath
1843}
1844
Paul Duffin9b478b02019-12-10 13:41:51 +00001845func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1846 switch tag {
1847 case "":
1848 return android.Paths{p.stubsSrcJar}, nil
1849 default:
1850 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1851 }
1852}
1853
Paul Duffin0f8faff2020-05-20 16:18:00 +01001854func (d *PrebuiltStubsSources) StubsSrcJar() android.Path {
1855 return d.stubsSrcJar
1856}
1857
Paul Duffin91547182019-11-12 19:39:36 +00001858func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001859 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1860
1861 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1862
1863 rule := android.NewRuleBuilder()
1864 command := rule.Command().
1865 BuiltTool(ctx, "soong_zip").
1866 Flag("-write_if_changed").
1867 Flag("-jar").
1868 FlagWithOutput("-o ", p.stubsSrcJar)
1869
1870 for _, d := range p.srcDirs {
1871 dir := d.String()
1872 command.
1873 FlagWithArg("-C ", dir).
1874 FlagWithInput("-D ", d)
1875 }
1876
1877 rule.Restat()
1878
1879 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001880}
1881
1882func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1883 return &p.prebuilt
1884}
1885
1886func (p *PrebuiltStubsSources) Name() string {
1887 return p.prebuilt.Name(p.ModuleBase.Name())
1888}
1889
Paul Duffin91547182019-11-12 19:39:36 +00001890// prebuilt_stubs_sources imports a set of java source files as if they were
1891// generated by droidstubs.
1892//
1893// By default, a prebuilt_stubs_sources has a single variant that expects a
1894// set of `.java` files generated by droidstubs.
1895//
1896// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1897// for host modules.
1898//
1899// Intended only for use by sdk snapshots.
1900func PrebuiltStubsSourcesFactory() android.Module {
1901 module := &PrebuiltStubsSources{}
1902
1903 module.AddProperties(&module.properties)
1904
1905 android.InitPrebuiltModule(module, &module.properties.Srcs)
1906 android.InitSdkAwareModule(module)
1907 InitDroiddocModule(module, android.HostAndDeviceSupported)
1908 return module
1909}
1910
Paul Duffin13879572019-11-28 14:31:38 +00001911type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001912 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001913}
1914
1915func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1916 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1917}
1918
1919func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1920 _, ok := module.(*Droidstubs)
1921 return ok
1922}
1923
Paul Duffin495ffb92020-03-20 13:35:40 +00001924func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1925 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
1926}
1927
1928func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1929 return &droidStubsInfoProperties{}
1930}
1931
1932type droidStubsInfoProperties struct {
1933 android.SdkMemberPropertiesBase
1934
1935 StubsSrcJar android.Path
1936}
1937
1938func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1939 droidstubs := variant.(*Droidstubs)
1940 p.StubsSrcJar = droidstubs.stubsSrcJar
1941}
1942
1943func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1944 if p.StubsSrcJar != nil {
1945 builder := ctx.SnapshotBuilder()
1946
1947 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
1948
1949 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
1950
1951 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00001952 }
Paul Duffin91547182019-11-12 19:39:36 +00001953}