blob: 90f143a7a8e261f6e03da5912c8994a19f57f734 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000030 RegisterDocsBuildComponents(android.InitRegistrationContext)
31 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000032
33 // Register sdk member type.
34 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
35 SdkMemberTypeBase: android.SdkMemberTypeBase{
36 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000037 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
38 // the APEX.
39 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000040 },
41 })
Nan Zhang581fd212018-01-10 16:06:12 -080042}
43
Paul Duffin884363e2019-12-19 10:21:09 +000044func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
45 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
46
47 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
48 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
49 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
50 ctx.RegisterModuleType("javadoc", JavadocFactory)
51 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
52}
53
54func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
55 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
56
57 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
58 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
59
60 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
61}
62
Colin Crossa1ce2a02018-06-20 15:19:39 -070063var (
64 srcsLibTag = dependencyTag{name: "sources from javalib"}
65)
66
Nan Zhang581fd212018-01-10 16:06:12 -080067type JavadocProperties struct {
68 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
69 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080070 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080071
72 // list of directories rooted at the Android.bp file that will
73 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080075
76 // list of source files that should not be used to build the Java module.
77 // This is most useful in the arch/multilib variants to remove non-common files
78 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080079 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080080
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090081 // list of package names that should actually be used. If this property is left unspecified,
82 // all the sources from the srcs property is used.
83 Filter_packages []string
84
Nan Zhangb2b33de2018-02-23 11:18:47 -080085 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080086 Libs []string `android:"arch_variant"`
87
88 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080089 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080090
Paul Duffine25c6442019-10-11 13:50:28 +010091 // if not blank, set to the version of the sdk to compile against.
92 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080093 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090094
Paul Duffine25c6442019-10-11 13:50:28 +010095 // When targeting 1.9 and above, override the modules to use with --system,
96 // otherwise provides defaults libraries to add to the bootclasspath.
97 // Defaults to "none"
98 System_modules *string
99
Jiyong Park1e440682018-05-23 18:42:04 +0900100 Aidl struct {
101 // Top level directories to pass to aidl tool
102 Include_dirs []string
103
104 // Directories rooted at the Android.bp file to pass to aidl tool
105 Local_include_dirs []string
106 }
Nan Zhang357466b2018-04-17 17:38:36 -0700107
108 // If not blank, set the java version passed to javadoc as -source
109 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
111 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800112 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700113
114 // user customized droiddoc args.
115 // Available variables for substitution:
116 //
117 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700118 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700119 Args *string
120
121 // names of the output files used in args that will be generated
122 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800123}
124
Nan Zhang61819ce2018-05-04 18:49:16 -0700125type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900126 // path to the API txt file that the new API extracted from source code is checked
127 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800128 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700129
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900130 // path to the API txt file that the new @removed API extractd from source code is
131 // checked against. The path can be local to the module or from other module (via
132 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800133 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700134
Adrian Roos14f75a92019-08-12 17:54:09 +0200135 // If not blank, path to the baseline txt file for approved API check violations.
136 Baseline_file *string `android:"path"`
137
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700139 Args *string
140}
141
Nan Zhang581fd212018-01-10 16:06:12 -0800142type DroiddocProperties struct {
143 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800144 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800145
Nan Zhanga40da042018-08-01 12:48:00 -0700146 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800147 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800148
149 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800150 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800151
152 // proofread file contains all of the text content of the javadocs concatenated into one file,
153 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700154 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // a todo file lists the program elements that are missing documentation.
157 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800158 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800159
160 // directory under current module source that provide additional resources (images).
161 Resourcesdir *string
162
163 // resources output directory under out/soong/.intermediates.
164 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800165
Nan Zhange2ba5d42018-07-11 15:16:55 -0700166 // if set to true, collect the values used by the Dev tools and
167 // write them in files packaged with the SDK. Defaults to false.
168 Write_sdk_values *bool
169
170 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700172
173 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800174 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700175
Nan Zhang581fd212018-01-10 16:06:12 -0800176 // a list of files under current module source dir which contains known tags in Java sources.
177 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700179
Nan Zhang28c68b92018-03-13 16:17:01 -0700180 // the generated public API filename by Doclava.
181 Api_filename *string
182
Nan Zhang28c68b92018-03-13 16:17:01 -0700183 // the generated removed API filename by Doclava.
184 Removed_api_filename *string
185
David Brazdilaac0c3c2018-04-24 16:23:29 +0100186 // the generated removed Dex API filename by Doclava.
187 Removed_dex_api_filename *string
188
Nan Zhang853f4202018-04-12 16:55:56 -0700189 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
190 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700191
192 Check_api struct {
193 Last_released ApiToCheck
194
195 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900196
197 // do not perform API check against Last_released, in the case that both two specified API
198 // files by Last_released are modules which don't exist.
199 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700200 }
Nan Zhang79614d12018-04-19 18:03:39 -0700201
Nan Zhang1598a9e2018-09-04 17:14:32 -0700202 // if set to true, generate docs through Dokka instead of Doclava.
203 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000204
205 // Compat config XML. Generates compat change documentation if set.
206 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700207}
208
209type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700210 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700211 Api_filename *string
212
Nan Zhang199645c2018-09-19 12:40:06 -0700213 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700214 Removed_api_filename *string
215
Nan Zhang199645c2018-09-19 12:40:06 -0700216 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700217 Removed_dex_api_filename *string
218
Nan Zhang1598a9e2018-09-04 17:14:32 -0700219 Check_api struct {
220 Last_released ApiToCheck
221
222 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900223
224 // do not perform API check against Last_released, in the case that both two specified API
225 // files by Last_released are modules which don't exist.
226 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200227
228 Api_lint struct {
229 Enabled *bool
230
231 // If set, performs api_lint on any new APIs not found in the given signature file
232 New_since *string `android:"path"`
233
234 // If not blank, path to the baseline txt file for approved API lint violations.
235 Baseline_file *string `android:"path"`
236 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700237 }
Nan Zhang79614d12018-04-19 18:03:39 -0700238
239 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800240 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700241
242 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700243 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700244
Pete Gillin77167902018-09-19 18:16:26 +0100245 // 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 -0700246 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700247
Pete Gillin77167902018-09-19 18:16:26 +0100248 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
249 Merge_inclusion_annotations_dirs []string
250
Pete Gillinc382a562018-11-14 18:45:46 +0000251 // a file containing a list of classes to do nullability validation for.
252 Validate_nullability_from_list *string
253
Pete Gillin581d6082018-10-22 15:55:04 +0100254 // a file containing expected warnings produced by validation of nullability annotations.
255 Check_nullability_warnings *string
256
Nan Zhang1598a9e2018-09-04 17:14:32 -0700257 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
258 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700259
Paul Duffin455b0bf2020-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
271 // if set to true, collect the values used by the Dev tools and
272 // write them in files packaged with the SDK. Defaults to false.
273 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700274
275 // If set to true, .xml based public API file will be also generated, and
276 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
277 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800278}
279
Nan Zhanga40da042018-08-01 12:48:00 -0700280//
281// Common flags passed down to build rule
282//
283type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700284 bootClasspathArgs string
285 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700286 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700287 dokkaClasspathArgs string
288 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700289 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700290
Nan Zhanga40da042018-08-01 12:48:00 -0700291 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700292 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700293 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700294}
295
296func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
297 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
298 android.InitDefaultableModule(module)
299}
300
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200301func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
302 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
303 return false
304 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700305 return true
306 } else if String(apiToCheck.Api_file) != "" {
307 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
308 } else if String(apiToCheck.Removed_api_file) != "" {
309 panic("for " + apiVersionTag + " api_file has to be non-empty!")
310 }
311
312 return false
313}
314
Inseob Kim38449af2019-02-28 14:24:05 +0900315func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
316 api_file := String(apiToCheck.Api_file)
317 removed_api_file := String(apiToCheck.Removed_api_file)
318
319 api_module := android.SrcIsModule(api_file)
320 removed_api_module := android.SrcIsModule(removed_api_file)
321
322 if api_module == "" || removed_api_module == "" {
323 return
324 }
325
326 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
327 return
328 }
329
330 apiToCheck.Api_file = nil
331 apiToCheck.Removed_api_file = nil
332}
333
Paul Duffinf488ef22020-04-09 00:10:17 +0100334// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700335type ApiFilePath interface {
336 ApiFilePath() android.Path
337}
338
Paul Duffinf488ef22020-04-09 00:10:17 +0100339// Provider of information about API stubs, used by java_sdk_library.
340type ApiStubsProvider interface {
341 ApiFilePath
342 StubsSrcJar() android.Path
343}
344
Nan Zhanga40da042018-08-01 12:48:00 -0700345//
346// Javadoc
347//
Nan Zhang581fd212018-01-10 16:06:12 -0800348type Javadoc struct {
349 android.ModuleBase
350 android.DefaultableModuleBase
351
352 properties JavadocProperties
353
354 srcJars android.Paths
355 srcFiles android.Paths
356 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700357 argFiles android.Paths
358
359 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800360
Nan Zhangccff0f72018-03-08 17:26:16 -0800361 docZip android.WritablePath
362 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800363}
364
Colin Cross41955e82019-05-29 14:40:35 -0700365func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
366 switch tag {
367 case "":
368 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700369 case ".docs.zip":
370 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700371 default:
372 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
373 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800374}
375
Colin Crossa3002fc2019-07-08 16:48:04 -0700376// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800377func JavadocFactory() android.Module {
378 module := &Javadoc{}
379
380 module.AddProperties(&module.properties)
381
382 InitDroiddocModule(module, android.HostAndDeviceSupported)
383 return module
384}
385
Colin Crossa3002fc2019-07-08 16:48:04 -0700386// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800387func JavadocHostFactory() android.Module {
388 module := &Javadoc{}
389
390 module.AddProperties(&module.properties)
391
392 InitDroiddocModule(module, android.HostSupported)
393 return module
394}
395
Colin Cross41955e82019-05-29 14:40:35 -0700396var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800397
Jiyong Park6a927c42020-01-21 02:03:43 +0900398func (j *Javadoc) sdkVersion() sdkSpec {
399 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700400}
401
Paul Duffine25c6442019-10-11 13:50:28 +0100402func (j *Javadoc) systemModules() string {
403 return proptools.String(j.properties.System_modules)
404}
405
Jiyong Park6a927c42020-01-21 02:03:43 +0900406func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700407 return j.sdkVersion()
408}
409
Jiyong Park6a927c42020-01-21 02:03:43 +0900410func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700411 return j.sdkVersion()
412}
413
Nan Zhang581fd212018-01-10 16:06:12 -0800414func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
415 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100416 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700417 if sdkDep.useDefaultLibs {
418 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
419 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
420 if sdkDep.hasFrameworkLibs() {
421 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700422 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700423 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700424 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100425 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700426 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800427 }
428 }
429
Colin Cross42d48b72018-08-29 14:10:52 -0700430 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800431}
432
Nan Zhanga40da042018-08-01 12:48:00 -0700433func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
434 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900435
Colin Cross3047fa22019-04-18 10:56:44 -0700436 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900437
438 return flags
439}
440
441func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700442 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900443
444 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
445 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
446
447 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700448 var deps android.Paths
449
Jiyong Park1e440682018-05-23 18:42:04 +0900450 if aidlPreprocess.Valid() {
451 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700452 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900453 } else {
454 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
455 }
456
457 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
458 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
459 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
460 flags = append(flags, "-I"+src.String())
461 }
462
Colin Cross3047fa22019-04-18 10:56:44 -0700463 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900464}
465
Jiyong Parkd90d7412019-08-20 22:49:19 +0900466// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900467func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700468 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900469
470 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700471 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900472
Jiyong Park1112c4c2019-08-16 21:12:10 +0900473 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
474
Jiyong Park1e440682018-05-23 18:42:04 +0900475 for _, srcFile := range srcFiles {
476 switch srcFile.Ext() {
477 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700478 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900479 case ".logtags":
480 javaFile := genLogtags(ctx, srcFile)
481 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900482 default:
483 outSrcFiles = append(outSrcFiles, srcFile)
484 }
485 }
486
Colin Crossc0806172019-06-14 18:51:47 -0700487 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
488 if len(aidlSrcs) > 0 {
489 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
490 outSrcFiles = append(outSrcFiles, srcJarFiles...)
491 }
492
Jiyong Park1e440682018-05-23 18:42:04 +0900493 return outSrcFiles
494}
495
Nan Zhang581fd212018-01-10 16:06:12 -0800496func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
497 var deps deps
498
Colin Cross83bb3162018-06-25 15:48:06 -0700499 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800500 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700501 ctx.AddMissingDependencies(sdkDep.bootclasspath)
502 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800503 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700504 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000505 deps.aidlPreprocess = sdkDep.aidl
506 } else {
507 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800508 }
509
510 ctx.VisitDirectDeps(func(module android.Module) {
511 otherName := ctx.OtherModuleName(module)
512 tag := ctx.OtherModuleDependencyTag(module)
513
Colin Cross2d24c1b2018-05-23 10:59:18 -0700514 switch tag {
515 case bootClasspathTag:
516 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800517 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000518 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100519 // A system modules dependency has been added to the bootclasspath
520 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000521 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700522 } else {
523 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
524 }
525 case libTag:
526 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800527 case SdkLibraryDependency:
528 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700529 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900530 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900531 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700532 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800533 checkProducesJars(ctx, dep)
534 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800535 default:
536 ctx.ModuleErrorf("depends on non-java module %q", otherName)
537 }
Colin Cross6cef4812019-10-17 14:23:50 -0700538 case java9LibTag:
539 switch dep := module.(type) {
540 case Dependency:
541 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
542 default:
543 ctx.ModuleErrorf("depends on non-java module %q", otherName)
544 }
Nan Zhang357466b2018-04-17 17:38:36 -0700545 case systemModulesTag:
546 if deps.systemModules != nil {
547 panic("Found two system module dependencies")
548 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000549 sm := module.(SystemModulesProvider)
550 outputDir, outputDeps := sm.OutputDirAndDeps()
551 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800552 }
553 })
554 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
555 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800556 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900557
558 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
559 if filterPackages == nil {
560 return srcs
561 }
562 filtered := []android.Path{}
563 for _, src := range srcs {
564 if src.Ext() != ".java" {
565 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
566 // but otherwise metalava emits stub sources having references to the generated AIDL classes
567 // in filtered-out pacages (e.g. com.android.internal.*).
568 // TODO(b/141149570) We need to fix this by introducing default private constructors or
569 // fixing metalava to not emit constructors having references to unknown classes.
570 filtered = append(filtered, src)
571 continue
572 }
573 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800574 if android.HasAnyPrefix(packageName, filterPackages) {
575 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900576 }
577 }
578 return filtered
579 }
580 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
581
Nan Zhanga40da042018-08-01 12:48:00 -0700582 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900583 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800584
585 // srcs may depend on some genrule output.
586 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800587 j.srcJars = append(j.srcJars, deps.srcJars...)
588
Nan Zhang581fd212018-01-10 16:06:12 -0800589 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800590 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800591
Nan Zhang9c69a122018-08-22 10:22:08 -0700592 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800593 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
594 }
595 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800596
Colin Cross8a497952019-03-05 22:25:09 -0800597 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000598 argFilesMap := map[string]string{}
599 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700600
Paul Duffin99e4a502019-02-11 15:38:42 +0000601 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800602 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000603 if _, exists := argFilesMap[label]; !exists {
604 argFilesMap[label] = strings.Join(paths.Strings(), " ")
605 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700606 } else {
607 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000608 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700609 }
610 }
611
612 var err error
Colin Cross15638152019-07-11 11:11:35 -0700613 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700614 if strings.HasPrefix(name, "location ") {
615 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000616 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700617 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700618 } else {
Colin Cross15638152019-07-11 11:11:35 -0700619 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000620 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700621 }
622 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700623 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700624 }
Colin Cross15638152019-07-11 11:11:35 -0700625 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700626 })
627
628 if err != nil {
629 ctx.PropertyErrorf("args", "%s", err.Error())
630 }
631
Nan Zhang581fd212018-01-10 16:06:12 -0800632 return deps
633}
634
635func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
636 j.addDeps(ctx)
637}
638
639func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
640 deps := j.collectDeps(ctx)
641
Colin Crossdaa4c672019-07-15 22:53:46 -0700642 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800643
Colin Crossdaa4c672019-07-15 22:53:46 -0700644 outDir := android.PathForModuleOut(ctx, "out")
645 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
646
647 j.stubsSrcJar = nil
648
649 rule := android.NewRuleBuilder()
650
651 rule.Command().Text("rm -rf").Text(outDir.String())
652 rule.Command().Text("mkdir -p").Text(outDir.String())
653
654 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700655
Colin Cross83bb3162018-06-25 15:48:06 -0700656 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800657
Colin Crossdaa4c672019-07-15 22:53:46 -0700658 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
659 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800660
Colin Cross1e743852019-10-28 11:37:20 -0700661 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700662 Flag("-J-Xmx1024m").
663 Flag("-XDignore.symbol.file").
664 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800665
Colin Crossdaa4c672019-07-15 22:53:46 -0700666 rule.Command().
667 BuiltTool(ctx, "soong_zip").
668 Flag("-write_if_changed").
669 Flag("-d").
670 FlagWithOutput("-o ", j.docZip).
671 FlagWithArg("-C ", outDir.String()).
672 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700673
Colin Crossdaa4c672019-07-15 22:53:46 -0700674 rule.Restat()
675
676 zipSyncCleanupCmd(rule, srcJarDir)
677
678 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800679}
680
Nan Zhanga40da042018-08-01 12:48:00 -0700681//
682// Droiddoc
683//
684type Droiddoc struct {
685 Javadoc
686
687 properties DroiddocProperties
688 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700689 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700690 removedApiFile android.WritablePath
691 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700692
693 checkCurrentApiTimestamp android.WritablePath
694 updateCurrentApiTimestamp android.WritablePath
695 checkLastReleasedApiTimestamp android.WritablePath
696
Nan Zhanga40da042018-08-01 12:48:00 -0700697 apiFilePath android.Path
698}
699
Colin Crossa3002fc2019-07-08 16:48:04 -0700700// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700701func DroiddocFactory() android.Module {
702 module := &Droiddoc{}
703
704 module.AddProperties(&module.properties,
705 &module.Javadoc.properties)
706
707 InitDroiddocModule(module, android.HostAndDeviceSupported)
708 return module
709}
710
Colin Crossa3002fc2019-07-08 16:48:04 -0700711// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700712func DroiddocHostFactory() android.Module {
713 module := &Droiddoc{}
714
715 module.AddProperties(&module.properties,
716 &module.Javadoc.properties)
717
718 InitDroiddocModule(module, android.HostSupported)
719 return module
720}
721
722func (d *Droiddoc) ApiFilePath() android.Path {
723 return d.apiFilePath
724}
725
Nan Zhang581fd212018-01-10 16:06:12 -0800726func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
727 d.Javadoc.addDeps(ctx)
728
Inseob Kim38449af2019-02-28 14:24:05 +0900729 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
730 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
731 }
732
Nan Zhang79614d12018-04-19 18:03:39 -0700733 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800734 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
735 }
Nan Zhang581fd212018-01-10 16:06:12 -0800736}
737
Colin Crossab054432019-07-15 16:13:59 -0700738func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000739 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700740 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
741 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
742 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700743 cmd.FlagWithArg("-source ", "1.8").
744 Flag("-J-Xmx1600m").
745 Flag("-J-XX:-OmitStackTraceInFastThrow").
746 Flag("-XDignore.symbol.file").
747 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
748 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000749 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700750 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 -0700751
Nan Zhanga40da042018-08-01 12:48:00 -0700752 if String(d.properties.Custom_template) == "" {
753 // TODO: This is almost always droiddoc-templates-sdk
754 ctx.PropertyErrorf("custom_template", "must specify a template")
755 }
756
757 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700758 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700759 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700760 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000761 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700762 }
763 })
764
765 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700766 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
767 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
768 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700769 }
770
771 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700772 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
773 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
774 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700775 }
776
777 if len(d.properties.Html_dirs) > 2 {
778 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
779 }
780
Colin Cross8a497952019-03-05 22:25:09 -0800781 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700782 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700783
Colin Crossab054432019-07-15 16:13:59 -0700784 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700785
786 if String(d.properties.Proofread_file) != "" {
787 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700788 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700789 }
790
791 if String(d.properties.Todo_file) != "" {
792 // tricky part:
793 // we should not compute full path for todo_file through PathForModuleOut().
794 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700795 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
796 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700797 }
798
799 if String(d.properties.Resourcesdir) != "" {
800 // TODO: should we add files under resourcesDir to the implicits? It seems that
801 // resourcesDir is one sub dir of htmlDir
802 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700803 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700804 }
805
806 if String(d.properties.Resourcesoutdir) != "" {
807 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700808 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700809 }
Nan Zhanga40da042018-08-01 12:48:00 -0700810}
811
Colin Crossab054432019-07-15 16:13:59 -0700812func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200813 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
814 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700815 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700816
Nan Zhanga40da042018-08-01 12:48:00 -0700817 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700818 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700819 d.apiFilePath = d.apiFile
820 }
821
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200822 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
823 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700824 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700825 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700826 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700827 }
828
Nan Zhanga40da042018-08-01 12:48:00 -0700829 if String(d.properties.Removed_dex_api_filename) != "" {
830 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700831 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700832 }
833
Nan Zhanga40da042018-08-01 12:48:00 -0700834 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700835 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700836 }
837
838 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700839 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700840 }
Nan Zhanga40da042018-08-01 12:48:00 -0700841}
842
Colin Crossab054432019-07-15 16:13:59 -0700843func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700844 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700845 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
846 rule.Command().Text("cp").
847 Input(staticDocIndexRedirect).
848 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700849 }
850
851 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700852 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
853 rule.Command().Text("cp").
854 Input(staticDocProperties).
855 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700856 }
Nan Zhanga40da042018-08-01 12:48:00 -0700857}
858
Colin Crossab054432019-07-15 16:13:59 -0700859func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700860 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700861
862 cmd := rule.Command().
863 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
864 Flag(config.JavacVmFlags).
865 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700866 FlagWithRspFileInputList("@", srcs).
867 FlagWithInput("@", srcJarList)
868
Colin Crossab054432019-07-15 16:13:59 -0700869 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
870 // based stubs generation.
871 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
872 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
873 // the correct package name base path.
874 if len(sourcepaths) > 0 {
875 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
876 } else {
877 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
878 }
879
880 cmd.FlagWithArg("-d ", outDir.String()).
881 Flag("-quiet")
882
883 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700884}
885
Colin Crossdaa4c672019-07-15 22:53:46 -0700886func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
887 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
888 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
889
890 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
891
892 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
893 cmd.Flag(flag).Implicits(deps)
894
895 cmd.FlagWithArg("--patch-module ", "java.base=.")
896
897 if len(classpath) > 0 {
898 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
899 }
900
901 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700902}
903
Colin Crossdaa4c672019-07-15 22:53:46 -0700904func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
905 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
906 sourcepaths android.Paths) *android.RuleBuilderCommand {
907
908 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
909
910 if len(bootclasspath) == 0 && ctx.Device() {
911 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
912 // ensure java does not fall back to the default bootclasspath.
913 cmd.FlagWithArg("-bootclasspath ", `""`)
914 } else if len(bootclasspath) > 0 {
915 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
916 }
917
918 if len(classpath) > 0 {
919 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
920 }
921
922 return cmd
923}
924
Colin Crossab054432019-07-15 16:13:59 -0700925func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
926 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700927
Colin Crossab054432019-07-15 16:13:59 -0700928 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
929 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
930
931 return rule.Command().
932 BuiltTool(ctx, "dokka").
933 Flag(config.JavacVmFlags).
934 Flag(srcJarDir.String()).
935 FlagWithInputList("-classpath ", dokkaClasspath, ":").
936 FlagWithArg("-format ", "dac").
937 FlagWithArg("-dacRoot ", "/reference/kotlin").
938 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700939}
940
941func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
942 deps := d.Javadoc.collectDeps(ctx)
943
Colin Crossdaa4c672019-07-15 22:53:46 -0700944 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
945 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
946
Nan Zhang1598a9e2018-09-04 17:14:32 -0700947 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
948 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
949 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
950 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
951
Colin Crossab054432019-07-15 16:13:59 -0700952 outDir := android.PathForModuleOut(ctx, "out")
953 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
954 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700955
Colin Crossab054432019-07-15 16:13:59 -0700956 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700957
Colin Crossab054432019-07-15 16:13:59 -0700958 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
959 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700960
Colin Crossab054432019-07-15 16:13:59 -0700961 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
962
963 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700964 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700965 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700966 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700967 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700968 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700969 }
970
Colin Crossab054432019-07-15 16:13:59 -0700971 d.stubsFlags(ctx, cmd, stubsDir)
972
973 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
974
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000975 if d.properties.Compat_config != nil {
976 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
977 cmd.FlagWithInput("-compatconfig ", compatConfig)
978 }
979
Colin Crossab054432019-07-15 16:13:59 -0700980 var desc string
981 if Bool(d.properties.Dokka_enabled) {
982 desc = "dokka"
983 } else {
984 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
985
986 for _, o := range d.Javadoc.properties.Out {
987 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
988 }
989
990 d.postDoclavaCmds(ctx, rule)
991 desc = "doclava"
992 }
993
994 rule.Command().
995 BuiltTool(ctx, "soong_zip").
996 Flag("-write_if_changed").
997 Flag("-d").
998 FlagWithOutput("-o ", d.docZip).
999 FlagWithArg("-C ", outDir.String()).
1000 FlagWithArg("-D ", outDir.String())
1001
1002 rule.Command().
1003 BuiltTool(ctx, "soong_zip").
1004 Flag("-write_if_changed").
1005 Flag("-jar").
1006 FlagWithOutput("-o ", d.stubsSrcJar).
1007 FlagWithArg("-C ", stubsDir.String()).
1008 FlagWithArg("-D ", stubsDir.String())
1009
1010 rule.Restat()
1011
1012 zipSyncCleanupCmd(rule, srcJarDir)
1013
1014 rule.Build(pctx, ctx, "javadoc", desc)
1015
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001016 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001017 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001018
1019 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1020 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001021
1022 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001023
1024 rule := android.NewRuleBuilder()
1025
1026 rule.Command().Text("( true")
1027
1028 rule.Command().
1029 BuiltTool(ctx, "apicheck").
1030 Flag("-JXmx1024m").
1031 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1032 OptionalFlag(d.properties.Check_api.Current.Args).
1033 Input(apiFile).
1034 Input(d.apiFile).
1035 Input(removedApiFile).
1036 Input(d.removedApiFile)
1037
1038 msg := fmt.Sprintf(`\n******************************\n`+
1039 `You have tried to change the API from what has been previously approved.\n\n`+
1040 `To make these errors go away, you have two choices:\n`+
1041 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1042 ` errors above.\n\n`+
1043 ` 2. You can update current.txt by executing the following command:\n`+
1044 ` make %s-update-current-api\n\n`+
1045 ` To submit the revised current.txt to the main Android repository,\n`+
1046 ` you will need approval.\n`+
1047 `******************************\n`, ctx.ModuleName())
1048
1049 rule.Command().
1050 Text("touch").Output(d.checkCurrentApiTimestamp).
1051 Text(") || (").
1052 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1053 Text("; exit 38").
1054 Text(")")
1055
1056 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001057
1058 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001059
1060 // update API rule
1061 rule = android.NewRuleBuilder()
1062
1063 rule.Command().Text("( true")
1064
1065 rule.Command().
1066 Text("cp").Flag("-f").
1067 Input(d.apiFile).Flag(apiFile.String())
1068
1069 rule.Command().
1070 Text("cp").Flag("-f").
1071 Input(d.removedApiFile).Flag(removedApiFile.String())
1072
1073 msg = "failed to update public API"
1074
1075 rule.Command().
1076 Text("touch").Output(d.updateCurrentApiTimestamp).
1077 Text(") || (").
1078 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1079 Text("; exit 38").
1080 Text(")")
1081
1082 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001083 }
1084
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001085 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001086 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001087
1088 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1089 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001090
1091 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001092
1093 rule := android.NewRuleBuilder()
1094
1095 rule.Command().
1096 Text("(").
1097 BuiltTool(ctx, "apicheck").
1098 Flag("-JXmx1024m").
1099 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1100 OptionalFlag(d.properties.Check_api.Last_released.Args).
1101 Input(apiFile).
1102 Input(d.apiFile).
1103 Input(removedApiFile).
1104 Input(d.removedApiFile)
1105
1106 msg := `\n******************************\n` +
1107 `You have tried to change the API from what has been previously released in\n` +
1108 `an SDK. Please fix the errors listed above.\n` +
1109 `******************************\n`
1110
1111 rule.Command().
1112 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1113 Text(") || (").
1114 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1115 Text("; exit 38").
1116 Text(")")
1117
1118 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001119 }
1120}
1121
1122//
1123// Droidstubs
1124//
1125type Droidstubs struct {
1126 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001127 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001128
Pete Gillin581d6082018-10-22 15:55:04 +01001129 properties DroidstubsProperties
1130 apiFile android.WritablePath
1131 apiXmlFile android.WritablePath
1132 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001133 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001134 removedApiFile android.WritablePath
1135 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001136 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001137
1138 checkCurrentApiTimestamp android.WritablePath
1139 updateCurrentApiTimestamp android.WritablePath
1140 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001141 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001142 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001143
Pete Gillin581d6082018-10-22 15:55:04 +01001144 checkNullabilityWarningsTimestamp android.WritablePath
1145
Nan Zhang1598a9e2018-09-04 17:14:32 -07001146 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001147 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001148
1149 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001150
1151 jdiffDocZip android.WritablePath
1152 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001153
1154 metadataZip android.WritablePath
1155 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001156}
1157
Colin Crossa3002fc2019-07-08 16:48:04 -07001158// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1159// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1160// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001161func DroidstubsFactory() android.Module {
1162 module := &Droidstubs{}
1163
1164 module.AddProperties(&module.properties,
1165 &module.Javadoc.properties)
1166
1167 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001168 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001169 return module
1170}
1171
Colin Crossa3002fc2019-07-08 16:48:04 -07001172// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1173// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1174// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1175// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001176func DroidstubsHostFactory() android.Module {
1177 module := &Droidstubs{}
1178
1179 module.AddProperties(&module.properties,
1180 &module.Javadoc.properties)
1181
1182 InitDroiddocModule(module, android.HostSupported)
1183 return module
1184}
1185
1186func (d *Droidstubs) ApiFilePath() android.Path {
1187 return d.apiFilePath
1188}
1189
Paul Duffinf488ef22020-04-09 00:10:17 +01001190func (d *Droidstubs) StubsSrcJar() android.Path {
1191 return d.stubsSrcJar
1192}
1193
Nan Zhang1598a9e2018-09-04 17:14:32 -07001194func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1195 d.Javadoc.addDeps(ctx)
1196
Inseob Kim38449af2019-02-28 14:24:05 +09001197 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1198 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1199 }
1200
Nan Zhang1598a9e2018-09-04 17:14:32 -07001201 if len(d.properties.Merge_annotations_dirs) != 0 {
1202 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1203 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1204 }
1205 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001206
Pete Gillin77167902018-09-19 18:16:26 +01001207 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1208 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1209 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1210 }
1211 }
1212
Nan Zhang9c69a122018-08-22 10:22:08 -07001213 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1214 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1215 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1216 }
1217 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001218}
1219
Paul Duffin455b0bf2020-04-08 18:18:03 +01001220func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001221 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1222 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001223 String(d.properties.Api_filename) != "" {
1224 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001225 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001226 d.apiFilePath = d.apiFile
1227 }
1228
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001229 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1230 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001231 String(d.properties.Removed_api_filename) != "" {
1232 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001233 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001234 }
1235
Nan Zhang1598a9e2018-09-04 17:14:32 -07001236 if String(d.properties.Removed_dex_api_filename) != "" {
1237 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001238 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001239 }
1240
Nan Zhang9c69a122018-08-22 10:22:08 -07001241 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001242 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1243 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001244 }
1245
Paul Duffin455b0bf2020-04-08 18:18:03 +01001246 if stubsDir.Valid() {
1247 if Bool(d.properties.Create_doc_stubs) {
1248 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1249 } else {
1250 cmd.FlagWithArg("--stubs ", stubsDir.String())
1251 cmd.Flag("--exclude-documentation-from-stubs")
1252 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001254}
1255
Colin Cross33961b52019-07-11 11:01:22 -07001256func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001257 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001258 cmd.Flag("--include-annotations")
1259
Pete Gillinc382a562018-11-14 18:45:46 +00001260 validatingNullability :=
1261 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1262 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001263
Pete Gillina262c052018-09-14 14:25:48 +01001264 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001265 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001266 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001267 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001268 }
Colin Cross33961b52019-07-11 11:01:22 -07001269
Pete Gillinc382a562018-11-14 18:45:46 +00001270 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001271 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001272 }
Colin Cross33961b52019-07-11 11:01:22 -07001273
Pete Gillina262c052018-09-14 14:25:48 +01001274 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001275 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001276 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001277 }
Nan Zhanga40da042018-08-01 12:48:00 -07001278
1279 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001280 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001281
Nan Zhang1598a9e2018-09-04 17:14:32 -07001282 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001283 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001284 "has to be non-empty if annotations was enabled!")
1285 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001286
Colin Cross33961b52019-07-11 11:01:22 -07001287 d.mergeAnnoDirFlags(ctx, cmd)
1288
1289 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1290 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1291 FlagWithArg("--hide ", "SuperfluousPrefix").
1292 FlagWithArg("--hide ", "AnnotationExtraction")
1293 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001294}
1295
Colin Cross33961b52019-07-11 11:01:22 -07001296func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1297 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1298 if t, ok := m.(*ExportedDroiddocDir); ok {
1299 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1300 } else {
1301 ctx.PropertyErrorf("merge_annotations_dirs",
1302 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1303 }
1304 })
1305}
1306
1307func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001308 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1309 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001310 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001311 } else {
1312 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1313 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1314 }
1315 })
Nan Zhanga40da042018-08-01 12:48:00 -07001316}
1317
Colin Cross33961b52019-07-11 11:01:22 -07001318func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001319 if Bool(d.properties.Api_levels_annotations_enabled) {
1320 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001321
1322 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1323 ctx.PropertyErrorf("api_levels_annotations_dirs",
1324 "has to be non-empty if api levels annotations was enabled!")
1325 }
1326
Colin Cross33961b52019-07-11 11:01:22 -07001327 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1328 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1329 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1330 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001331
1332 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1333 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001334 for _, dep := range t.deps {
1335 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001336 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001337 }
1338 }
Colin Cross33961b52019-07-11 11:01:22 -07001339 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001340 } else {
1341 ctx.PropertyErrorf("api_levels_annotations_dirs",
1342 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1343 }
1344 })
1345
1346 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001347}
1348
Colin Cross33961b52019-07-11 11:01:22 -07001349func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001350 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1351 if d.apiFile.String() == "" {
1352 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1353 }
1354
1355 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001356 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001357
1358 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1359 ctx.PropertyErrorf("check_api.last_released.api_file",
1360 "has to be non-empty if jdiff was enabled!")
1361 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001362
Colin Cross33961b52019-07-11 11:01:22 -07001363 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001364 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001365 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1366 }
1367}
Nan Zhang71bbe632018-09-17 14:32:21 -07001368
Colin Cross1e743852019-10-28 11:37:20 -07001369func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001370 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001371 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1372 rule.HighMem()
Colin Cross33961b52019-07-11 11:01:22 -07001373 cmd := rule.Command().BuiltTool(ctx, "metalava").
1374 Flag(config.JavacVmFlags).
1375 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001376 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001377 FlagWithRspFileInputList("@", srcs).
1378 FlagWithInput("@", srcJarList)
1379
1380 if len(bootclasspath) > 0 {
1381 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001382 }
1383
Colin Cross33961b52019-07-11 11:01:22 -07001384 if len(classpath) > 0 {
1385 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1386 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001387
Colin Cross33961b52019-07-11 11:01:22 -07001388 if len(sourcepaths) > 0 {
1389 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1390 } else {
1391 cmd.FlagWithArg("-sourcepath ", `""`)
1392 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001393
Colin Cross33961b52019-07-11 11:01:22 -07001394 cmd.Flag("--no-banner").
1395 Flag("--color").
1396 Flag("--quiet").
1397 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001398
Colin Cross33961b52019-07-11 11:01:22 -07001399 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001400}
1401
Nan Zhang1598a9e2018-09-04 17:14:32 -07001402func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001403 deps := d.Javadoc.collectDeps(ctx)
1404
1405 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001406
Colin Cross33961b52019-07-11 11:01:22 -07001407 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001408
Colin Cross33961b52019-07-11 11:01:22 -07001409 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001410
Colin Cross33961b52019-07-11 11:01:22 -07001411 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001412
Paul Duffin455b0bf2020-04-08 18:18:03 +01001413 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1414 var stubsDir android.OptionalPath
1415 if generateStubs {
1416 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1417 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1418 rule.Command().Text("rm -rf").Text(stubsDir.String())
1419 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1420 }
Nan Zhanga40da042018-08-01 12:48:00 -07001421
Colin Cross33961b52019-07-11 11:01:22 -07001422 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1423
1424 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1425 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1426
1427 d.stubsFlags(ctx, cmd, stubsDir)
1428
1429 d.annotationsFlags(ctx, cmd)
1430 d.inclusionAnnotationsFlags(ctx, cmd)
1431 d.apiLevelsAnnotationsFlags(ctx, cmd)
1432 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001433
Nan Zhang1598a9e2018-09-04 17:14:32 -07001434 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1435 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1436 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1437 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1438 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001439 }
Colin Cross33961b52019-07-11 11:01:22 -07001440
1441 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1442 for _, o := range d.Javadoc.properties.Out {
1443 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1444 }
1445
Paul Duffin455b0bf2020-04-08 18:18:03 +01001446 if generateStubs {
1447 rule.Command().
1448 BuiltTool(ctx, "soong_zip").
1449 Flag("-write_if_changed").
1450 Flag("-jar").
1451 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1452 FlagWithArg("-C ", stubsDir.String()).
1453 FlagWithArg("-D ", stubsDir.String())
1454 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001455
1456 if Bool(d.properties.Write_sdk_values) {
1457 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1458 rule.Command().
1459 BuiltTool(ctx, "soong_zip").
1460 Flag("-write_if_changed").
1461 Flag("-d").
1462 FlagWithOutput("-o ", d.metadataZip).
1463 FlagWithArg("-C ", d.metadataDir.String()).
1464 FlagWithArg("-D ", d.metadataDir.String())
1465 }
1466
Colin Cross33961b52019-07-11 11:01:22 -07001467 rule.Restat()
1468
1469 zipSyncCleanupCmd(rule, srcJarDir)
1470
1471 rule.Build(pctx, ctx, "metalava", "metalava")
1472
1473 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001474
Adrian Roos075eedc2019-10-10 12:07:03 +02001475 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1476 rule := android.NewRuleBuilder()
1477 rule.Command().Text("( true")
1478
1479 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1480 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1481
1482 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1483 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1484
Anton Hanssone7145652020-05-04 18:38:46 +01001485 // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released.
1486 if d.Name() != "android.car-system-stubs-docs" &&
1487 d.Name() != "android.car-stubs-docs" &&
1488 d.Name() != "system-api-stubs-docs" &&
1489 d.Name() != "test-api-stubs-docs" {
1490 cmd.Flag("--lints-as-errors")
1491 cmd.Flag("--warnings-as-errors") // Most lints are actually warnings.
1492 }
1493
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001494 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1495
Adrian Roos075eedc2019-10-10 12:07:03 +02001496 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1497 if newSince.Valid() {
1498 cmd.FlagWithInput("--api-lint ", newSince.Path())
1499 } else {
1500 cmd.Flag("--api-lint")
1501 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001502 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1503 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001504
1505 d.inclusionAnnotationsFlags(ctx, cmd)
1506 d.mergeAnnoDirFlags(ctx, cmd)
1507
1508 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1509 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1510 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1511
Anton Hansson34ced822020-05-01 17:08:54 +01001512 msg := `` +
1513 `************************************************************\n` +
1514 `Your API changes are triggering API Lint warnings or errors.\n` +
1515 `To make these errors go away, fix the code according to the\n` +
1516 `error and/or warning messages above.\n` +
1517 `\n` +
1518 `If it's not possible to do so, there are workarounds:\n` +
1519 `\n` +
1520 `1. You can suppress the errors with @SuppressLint(\"<id>\")\n`
1521
Adrian Roos075eedc2019-10-10 12:07:03 +02001522 if baselineFile.Valid() {
1523 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1524 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
Anton Hansson34ced822020-05-01 17:08:54 +01001525
1526 msg += fmt.Sprintf(``+
1527 `2. You can update the baseline by executing the following\n`+
1528 ` command:\n`+
1529 ` cp \\ \n`+
1530 ` \"$PWD/%s\" \\ \n`+
1531 ` \"$PWD/%s\" \n`+
1532 ` To submit the revised baseline.txt to the main Android\n`+
1533 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1534 } else {
1535 msg += fmt.Sprintf(``+
1536 `2. You can add a baseline file of existing lint failures\n`+
1537 ` to the build rule of %s.\n`, d.Name())
Adrian Roos075eedc2019-10-10 12:07:03 +02001538 }
Anton Hansson34ced822020-05-01 17:08:54 +01001539 msg += `************************************************************\n`
Adrian Roos075eedc2019-10-10 12:07:03 +02001540
1541 zipSyncCleanupCmd(rule, srcJarDir)
1542
Adrian Roos075eedc2019-10-10 12:07:03 +02001543 rule.Command().
1544 Text("touch").Output(d.apiLintTimestamp).
1545 Text(") || (").
1546 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1547 Text("; exit 38").
1548 Text(")")
1549
1550 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1551
1552 }
1553
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001554 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001555 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001556
1557 if len(d.Javadoc.properties.Out) > 0 {
1558 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1559 }
1560
1561 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1562 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001563 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001564
1565 if baselineFile.Valid() {
1566 ctx.PropertyErrorf("current API check can't have a baseline file. (module %s)", ctx.ModuleName())
1567 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001568
Nan Zhang2760dfc2018-08-24 17:32:54 +00001569 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001570
Colin Cross33961b52019-07-11 11:01:22 -07001571 rule := android.NewRuleBuilder()
1572
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001573 // Diff command line.
1574 // -F matches the closest "opening" line, such as "package xxx{"
1575 // and " public class Yyy {".
1576 diff := `diff -u -F '{ *$'`
1577
Colin Cross33961b52019-07-11 11:01:22 -07001578 rule.Command().Text("( true")
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001579 rule.Command().
1580 Text(diff).
1581 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001582
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001583 rule.Command().
1584 Text(diff).
1585 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001586
1587 msg := fmt.Sprintf(`\n******************************\n`+
1588 `You have tried to change the API from what has been previously approved.\n\n`+
1589 `To make these errors go away, you have two choices:\n`+
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001590 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1591 ` to the new methods, etc. shown in the above diff.\n\n`+
1592 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001593 ` make %s-update-current-api\n\n`+
1594 ` To submit the revised current.txt to the main Android repository,\n`+
1595 ` you will need approval.\n`+
1596 `******************************\n`, ctx.ModuleName())
1597
1598 rule.Command().
1599 Text("touch").Output(d.checkCurrentApiTimestamp).
1600 Text(") || (").
1601 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1602 Text("; exit 38").
1603 Text(")")
1604
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001605 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001606
1607 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001608
1609 // update API rule
1610 rule = android.NewRuleBuilder()
1611
1612 rule.Command().Text("( true")
1613
1614 rule.Command().
1615 Text("cp").Flag("-f").
1616 Input(d.apiFile).Flag(apiFile.String())
1617
1618 rule.Command().
1619 Text("cp").Flag("-f").
1620 Input(d.removedApiFile).Flag(removedApiFile.String())
1621
1622 msg = "failed to update public API"
1623
1624 rule.Command().
1625 Text("touch").Output(d.updateCurrentApiTimestamp).
1626 Text(") || (").
1627 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1628 Text("; exit 38").
1629 Text(")")
1630
1631 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001632 }
Nan Zhanga40da042018-08-01 12:48:00 -07001633
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001634 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001635 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001636
1637 if len(d.Javadoc.properties.Out) > 0 {
1638 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1639 }
1640
1641 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1642 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001643 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1644 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001645
Nan Zhang2760dfc2018-08-24 17:32:54 +00001646 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001647
Colin Cross33961b52019-07-11 11:01:22 -07001648 rule := android.NewRuleBuilder()
1649
1650 rule.Command().Text("( true")
1651
1652 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1653 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1654
1655 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1656 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1657
1658 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1659 FlagWithInput("--check-compatibility:api:released ", apiFile)
1660
1661 d.inclusionAnnotationsFlags(ctx, cmd)
1662
1663 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1664
1665 d.mergeAnnoDirFlags(ctx, cmd)
1666
Adrian Roos14f75a92019-08-12 17:54:09 +02001667 if baselineFile.Valid() {
1668 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1669 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1670 }
1671
Colin Cross33961b52019-07-11 11:01:22 -07001672 zipSyncCleanupCmd(rule, srcJarDir)
1673
1674 msg := `\n******************************\n` +
1675 `You have tried to change the API from what has been previously released in\n` +
1676 `an SDK. Please fix the errors listed above.\n` +
1677 `******************************\n`
1678 rule.Command().
1679 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1680 Text(") || (").
1681 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1682 Text("; exit 38").
1683 Text(")")
1684
1685 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001686 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001687
Pete Gillin581d6082018-10-22 15:55:04 +01001688 if String(d.properties.Check_nullability_warnings) != "" {
1689 if d.nullabilityWarningsFile == nil {
1690 ctx.PropertyErrorf("check_nullability_warnings",
1691 "Cannot specify check_nullability_warnings unless validating nullability")
1692 }
Colin Cross33961b52019-07-11 11:01:22 -07001693
1694 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1695
Pete Gillin581d6082018-10-22 15:55:04 +01001696 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001697
Pete Gillin581d6082018-10-22 15:55:04 +01001698 msg := fmt.Sprintf(`\n******************************\n`+
1699 `The warnings encountered during nullability annotation validation did\n`+
1700 `not match the checked in file of expected warnings. The diffs are shown\n`+
1701 `above. You have two options:\n`+
1702 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1703 ` 2. Update the file of expected warnings by running:\n`+
1704 ` cp %s %s\n`+
1705 ` and submitting the updated file as part of your change.`,
1706 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001707
1708 rule := android.NewRuleBuilder()
1709
1710 rule.Command().
1711 Text("(").
1712 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1713 Text("&&").
1714 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1715 Text(") || (").
1716 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1717 Text("; exit 38").
1718 Text(")")
1719
1720 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001721 }
1722
Nan Zhang71bbe632018-09-17 14:32:21 -07001723 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001724 if len(d.Javadoc.properties.Out) > 0 {
1725 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1726 }
1727
1728 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1729 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1730 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1731
1732 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001733
Nan Zhang86b06202018-09-21 17:09:21 -07001734 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1735 // since there's cron job downstream that fetch this .zip file periodically.
1736 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001737 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1738 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1739
Nan Zhang71bbe632018-09-17 14:32:21 -07001740 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001741
Colin Cross33961b52019-07-11 11:01:22 -07001742 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1743 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001744
Colin Cross33961b52019-07-11 11:01:22 -07001745 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1746
Colin Crossdaa4c672019-07-15 22:53:46 -07001747 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001748 deps.bootClasspath, deps.classpath, d.sourcepaths)
1749
1750 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001751 Flag("-XDignore.symbol.file").
1752 FlagWithArg("-doclet ", "jdiff.JDiff").
1753 FlagWithInput("-docletpath ", jdiff).
1754 Flag("-quiet").
1755 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1756 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1757 Implicit(d.apiXmlFile).
1758 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1759 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1760 Implicit(d.lastReleasedApiXmlFile)
1761
Colin Cross33961b52019-07-11 11:01:22 -07001762 rule.Command().
1763 BuiltTool(ctx, "soong_zip").
1764 Flag("-write_if_changed").
1765 Flag("-d").
1766 FlagWithOutput("-o ", d.jdiffDocZip).
1767 FlagWithArg("-C ", outDir.String()).
1768 FlagWithArg("-D ", outDir.String())
1769
1770 rule.Command().
1771 BuiltTool(ctx, "soong_zip").
1772 Flag("-write_if_changed").
1773 Flag("-jar").
1774 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1775 FlagWithArg("-C ", stubsDir.String()).
1776 FlagWithArg("-D ", stubsDir.String())
1777
1778 rule.Restat()
1779
1780 zipSyncCleanupCmd(rule, srcJarDir)
1781
1782 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001783 }
Nan Zhang581fd212018-01-10 16:06:12 -08001784}
Dan Willemsencc090972018-02-26 14:33:31 -08001785
Nan Zhanga40da042018-08-01 12:48:00 -07001786//
Nan Zhangf4936b02018-08-01 15:00:28 -07001787// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001788//
Dan Willemsencc090972018-02-26 14:33:31 -08001789var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001790var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001791var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001792var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001793
Nan Zhangf4936b02018-08-01 15:00:28 -07001794type ExportedDroiddocDirProperties struct {
1795 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001796 Path *string
1797}
1798
Nan Zhangf4936b02018-08-01 15:00:28 -07001799type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001800 android.ModuleBase
1801
Nan Zhangf4936b02018-08-01 15:00:28 -07001802 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001803
1804 deps android.Paths
1805 dir android.Path
1806}
1807
Colin Crossa3002fc2019-07-08 16:48:04 -07001808// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001809func ExportedDroiddocDirFactory() android.Module {
1810 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001811 module.AddProperties(&module.properties)
1812 android.InitAndroidModule(module)
1813 return module
1814}
1815
Nan Zhangf4936b02018-08-01 15:00:28 -07001816func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001817
Nan Zhangf4936b02018-08-01 15:00:28 -07001818func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001819 path := String(d.properties.Path)
1820 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001821 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001822}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001823
1824//
1825// Defaults
1826//
1827type DocDefaults struct {
1828 android.ModuleBase
1829 android.DefaultsModuleBase
1830}
1831
Nan Zhangb2b33de2018-02-23 11:18:47 -08001832func DocDefaultsFactory() android.Module {
1833 module := &DocDefaults{}
1834
1835 module.AddProperties(
1836 &JavadocProperties{},
1837 &DroiddocProperties{},
1838 )
1839
1840 android.InitDefaultsModule(module)
1841
1842 return module
1843}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001844
1845func StubsDefaultsFactory() android.Module {
1846 module := &DocDefaults{}
1847
1848 module.AddProperties(
1849 &JavadocProperties{},
1850 &DroidstubsProperties{},
1851 )
1852
1853 android.InitDefaultsModule(module)
1854
1855 return module
1856}
Colin Cross33961b52019-07-11 11:01:22 -07001857
1858func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1859 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1860
1861 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1862 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1863 srcJarList := srcJarDir.Join(ctx, "list")
1864
1865 rule.Temporary(srcJarList)
1866
1867 rule.Command().BuiltTool(ctx, "zipsync").
1868 FlagWithArg("-d ", srcJarDir.String()).
1869 FlagWithOutput("-l ", srcJarList).
1870 FlagWithArg("-f ", `"*.java"`).
1871 Inputs(srcJars)
1872
1873 return srcJarList
1874}
1875
1876func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1877 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1878}
Paul Duffin91547182019-11-12 19:39:36 +00001879
1880var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1881
1882type PrebuiltStubsSourcesProperties struct {
1883 Srcs []string `android:"path"`
1884}
1885
1886type PrebuiltStubsSources struct {
1887 android.ModuleBase
1888 android.DefaultableModuleBase
1889 prebuilt android.Prebuilt
1890 android.SdkBase
1891
1892 properties PrebuiltStubsSourcesProperties
1893
Paul Duffin9b478b02019-12-10 13:41:51 +00001894 // The source directories containing stubs source files.
1895 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001896 stubsSrcJar android.ModuleOutPath
1897}
1898
Paul Duffin9b478b02019-12-10 13:41:51 +00001899func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1900 switch tag {
1901 case "":
1902 return android.Paths{p.stubsSrcJar}, nil
1903 default:
1904 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1905 }
1906}
1907
Paul Duffin91547182019-11-12 19:39:36 +00001908func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001909 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1910
1911 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1912
1913 rule := android.NewRuleBuilder()
1914 command := rule.Command().
1915 BuiltTool(ctx, "soong_zip").
1916 Flag("-write_if_changed").
1917 Flag("-jar").
1918 FlagWithOutput("-o ", p.stubsSrcJar)
1919
1920 for _, d := range p.srcDirs {
1921 dir := d.String()
1922 command.
1923 FlagWithArg("-C ", dir).
1924 FlagWithInput("-D ", d)
1925 }
1926
1927 rule.Restat()
1928
1929 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001930}
1931
1932func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1933 return &p.prebuilt
1934}
1935
1936func (p *PrebuiltStubsSources) Name() string {
1937 return p.prebuilt.Name(p.ModuleBase.Name())
1938}
1939
Paul Duffin91547182019-11-12 19:39:36 +00001940// prebuilt_stubs_sources imports a set of java source files as if they were
1941// generated by droidstubs.
1942//
1943// By default, a prebuilt_stubs_sources has a single variant that expects a
1944// set of `.java` files generated by droidstubs.
1945//
1946// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1947// for host modules.
1948//
1949// Intended only for use by sdk snapshots.
1950func PrebuiltStubsSourcesFactory() android.Module {
1951 module := &PrebuiltStubsSources{}
1952
1953 module.AddProperties(&module.properties)
1954
1955 android.InitPrebuiltModule(module, &module.properties.Srcs)
1956 android.InitSdkAwareModule(module)
1957 InitDroiddocModule(module, android.HostAndDeviceSupported)
1958 return module
1959}
1960
Paul Duffin13879572019-11-28 14:31:38 +00001961type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001962 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001963}
1964
1965func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1966 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1967}
1968
1969func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1970 _, ok := module.(*Droidstubs)
1971 return ok
1972}
1973
Paul Duffin93520ed2020-03-20 13:35:40 +00001974func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1975 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
1976}
1977
1978func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1979 return &droidStubsInfoProperties{}
1980}
1981
1982type droidStubsInfoProperties struct {
1983 android.SdkMemberPropertiesBase
1984
1985 StubsSrcJar android.Path
1986}
1987
1988func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1989 droidstubs := variant.(*Droidstubs)
1990 p.StubsSrcJar = droidstubs.stubsSrcJar
1991}
1992
1993func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1994 if p.StubsSrcJar != nil {
1995 builder := ctx.SnapshotBuilder()
1996
1997 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
1998
1999 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2000
2001 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002002 }
Paul Duffin91547182019-11-12 19:39:36 +00002003}