blob: 1f838907f7d85ca616614f231436aa1fbdba488e [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Ramy Medhat427683c2020-04-30 03:08:37 -040027 "android/soong/remoteexec"
Nan Zhang581fd212018-01-10 16:06:12 -080028)
29
30func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000031 RegisterDocsBuildComponents(android.InitRegistrationContext)
32 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000033
34 // Register sdk member type.
35 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
36 SdkMemberTypeBase: android.SdkMemberTypeBase{
37 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000038 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
39 // the APEX.
40 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000041 },
42 })
Nan Zhang581fd212018-01-10 16:06:12 -080043}
44
Paul Duffin884363e2019-12-19 10:21:09 +000045func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
47
48 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
49 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
50 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
51 ctx.RegisterModuleType("javadoc", JavadocFactory)
52 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
53}
54
55func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
56 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
57
58 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
59 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
60
61 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
62}
63
Colin Crossa1ce2a02018-06-20 15:19:39 -070064var (
65 srcsLibTag = dependencyTag{name: "sources from javalib"}
66)
67
Nan Zhang581fd212018-01-10 16:06:12 -080068type JavadocProperties struct {
69 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
70 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080071 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080072
73 // list of directories rooted at the Android.bp file that will
74 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080075 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080076
77 // list of source files that should not be used to build the Java module.
78 // This is most useful in the arch/multilib variants to remove non-common files
79 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080080 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080081
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090082 // list of package names that should actually be used. If this property is left unspecified,
83 // all the sources from the srcs property is used.
84 Filter_packages []string
85
Nan Zhangb2b33de2018-02-23 11:18:47 -080086 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080087 Libs []string `android:"arch_variant"`
88
89 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080090 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080091
Paul Duffine25c6442019-10-11 13:50:28 +010092 // if not blank, set to the version of the sdk to compile against.
93 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080094 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090095
Paul Duffine25c6442019-10-11 13:50:28 +010096 // When targeting 1.9 and above, override the modules to use with --system,
97 // otherwise provides defaults libraries to add to the bootclasspath.
98 // Defaults to "none"
99 System_modules *string
100
Jiyong Park1e440682018-05-23 18:42:04 +0900101 Aidl struct {
102 // Top level directories to pass to aidl tool
103 Include_dirs []string
104
105 // Directories rooted at the Android.bp file to pass to aidl tool
106 Local_include_dirs []string
107 }
Nan Zhang357466b2018-04-17 17:38:36 -0700108
109 // If not blank, set the java version passed to javadoc as -source
110 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700111
112 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800113 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700114
115 // user customized droiddoc args.
116 // Available variables for substitution:
117 //
118 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700119 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700120 Args *string
121
122 // names of the output files used in args that will be generated
123 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800124}
125
Nan Zhang61819ce2018-05-04 18:49:16 -0700126type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900127 // path to the API txt file that the new API extracted from source code is checked
128 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800129 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700130
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900131 // path to the API txt file that the new @removed API extractd from source code is
132 // checked against. The path can be local to the module or from other module (via
133 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800134 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700135
Adrian Roos14f75a92019-08-12 17:54:09 +0200136 // If not blank, path to the baseline txt file for approved API check violations.
137 Baseline_file *string `android:"path"`
138
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900139 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700140 Args *string
141}
142
Nan Zhang581fd212018-01-10 16:06:12 -0800143type DroiddocProperties struct {
144 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800145 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800146
Nan Zhanga40da042018-08-01 12:48:00 -0700147 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800148 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800149
150 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800151 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800152
153 // proofread file contains all of the text content of the javadocs concatenated into one file,
154 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700155 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800156
157 // a todo file lists the program elements that are missing documentation.
158 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800159 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800160
161 // directory under current module source that provide additional resources (images).
162 Resourcesdir *string
163
164 // resources output directory under out/soong/.intermediates.
165 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800166
Nan Zhange2ba5d42018-07-11 15:16:55 -0700167 // if set to true, collect the values used by the Dev tools and
168 // write them in files packaged with the SDK. Defaults to false.
169 Write_sdk_values *bool
170
171 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800172 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700173
174 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700176
Nan Zhang581fd212018-01-10 16:06:12 -0800177 // a list of files under current module source dir which contains known tags in Java sources.
178 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800179 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700180
Nan Zhang28c68b92018-03-13 16:17:01 -0700181 // the generated public API filename by Doclava.
182 Api_filename *string
183
Nan Zhang28c68b92018-03-13 16:17:01 -0700184 // the generated removed API filename by Doclava.
185 Removed_api_filename *string
186
David Brazdilaac0c3c2018-04-24 16:23:29 +0100187 // the generated removed Dex API filename by Doclava.
188 Removed_dex_api_filename *string
189
Nan Zhang853f4202018-04-12 16:55:56 -0700190 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
191 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700192
193 Check_api struct {
194 Last_released ApiToCheck
195
196 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900197
198 // do not perform API check against Last_released, in the case that both two specified API
199 // files by Last_released are modules which don't exist.
200 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700201 }
Nan Zhang79614d12018-04-19 18:03:39 -0700202
Nan Zhang1598a9e2018-09-04 17:14:32 -0700203 // if set to true, generate docs through Dokka instead of Doclava.
204 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000205
206 // Compat config XML. Generates compat change documentation if set.
207 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700208}
209
210type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700211 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700212 Api_filename *string
213
Nan Zhang199645c2018-09-19 12:40:06 -0700214 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700215 Removed_api_filename *string
216
Nan Zhang199645c2018-09-19 12:40:06 -0700217 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700218 Removed_dex_api_filename *string
219
Nan Zhang1598a9e2018-09-04 17:14:32 -0700220 Check_api struct {
221 Last_released ApiToCheck
222
223 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900224
225 // do not perform API check against Last_released, in the case that both two specified API
226 // files by Last_released are modules which don't exist.
227 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200228
229 Api_lint struct {
230 Enabled *bool
231
232 // If set, performs api_lint on any new APIs not found in the given signature file
233 New_since *string `android:"path"`
234
235 // If not blank, path to the baseline txt file for approved API lint violations.
236 Baseline_file *string `android:"path"`
237 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700238 }
Nan Zhang79614d12018-04-19 18:03:39 -0700239
240 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800241 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700242
243 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700244 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700245
Pete Gillin77167902018-09-19 18:16:26 +0100246 // 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 -0700247 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700248
Pete Gillin77167902018-09-19 18:16:26 +0100249 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
250 Merge_inclusion_annotations_dirs []string
251
Pete Gillinc382a562018-11-14 18:45:46 +0000252 // a file containing a list of classes to do nullability validation for.
253 Validate_nullability_from_list *string
254
Pete Gillin581d6082018-10-22 15:55:04 +0100255 // a file containing expected warnings produced by validation of nullability annotations.
256 Check_nullability_warnings *string
257
Nan Zhang1598a9e2018-09-04 17:14:32 -0700258 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
259 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700260
Paul Duffin3ae29512020-04-08 18:18:03 +0100261 // if set to false then do not write out stubs. Defaults to true.
262 //
263 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
264 Generate_stubs *bool
265
Nan Zhang9c69a122018-08-22 10:22:08 -0700266 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
267 Api_levels_annotations_enabled *bool
268
269 // the dirs which Metalava extracts API levels annotations from.
270 Api_levels_annotations_dirs []string
271
272 // if set to true, collect the values used by the Dev tools and
273 // write them in files packaged with the SDK. Defaults to false.
274 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700275
276 // If set to true, .xml based public API file will be also generated, and
277 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
278 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800279}
280
Nan Zhanga40da042018-08-01 12:48:00 -0700281//
282// Common flags passed down to build rule
283//
284type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700285 bootClasspathArgs string
286 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700287 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700288 dokkaClasspathArgs string
289 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700290 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700291
Nan Zhanga40da042018-08-01 12:48:00 -0700292 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700293 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700294 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700295}
296
297func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
298 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
299 android.InitDefaultableModule(module)
300}
301
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200302func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
303 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
304 return false
305 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700306 return true
307 } else if String(apiToCheck.Api_file) != "" {
308 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
309 } else if String(apiToCheck.Removed_api_file) != "" {
310 panic("for " + apiVersionTag + " api_file has to be non-empty!")
311 }
312
313 return false
314}
315
Inseob Kim38449af2019-02-28 14:24:05 +0900316func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
317 api_file := String(apiToCheck.Api_file)
318 removed_api_file := String(apiToCheck.Removed_api_file)
319
320 api_module := android.SrcIsModule(api_file)
321 removed_api_module := android.SrcIsModule(removed_api_file)
322
323 if api_module == "" || removed_api_module == "" {
324 return
325 }
326
327 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
328 return
329 }
330
331 apiToCheck.Api_file = nil
332 apiToCheck.Removed_api_file = nil
333}
334
Paul Duffin3d1248c2020-04-09 00:10:17 +0100335// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700336type ApiFilePath interface {
337 ApiFilePath() android.Path
338}
339
Paul Duffin3d1248c2020-04-09 00:10:17 +0100340// Provider of information about API stubs, used by java_sdk_library.
341type ApiStubsProvider interface {
342 ApiFilePath
Paul Duffin1fd005d2020-04-09 01:08:11 +0100343 RemovedApiFilePath() android.Path
Paul Duffin3d1248c2020-04-09 00:10:17 +0100344 StubsSrcJar() android.Path
345}
346
Nan Zhanga40da042018-08-01 12:48:00 -0700347//
348// Javadoc
349//
Nan Zhang581fd212018-01-10 16:06:12 -0800350type Javadoc struct {
351 android.ModuleBase
352 android.DefaultableModuleBase
353
354 properties JavadocProperties
355
356 srcJars android.Paths
357 srcFiles android.Paths
358 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700359 argFiles android.Paths
360
361 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800362
Nan Zhangccff0f72018-03-08 17:26:16 -0800363 docZip android.WritablePath
364 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800365}
366
Colin Cross41955e82019-05-29 14:40:35 -0700367func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
368 switch tag {
369 case "":
370 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700371 case ".docs.zip":
372 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700373 default:
374 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
375 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800376}
377
Colin Crossa3002fc2019-07-08 16:48:04 -0700378// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800379func JavadocFactory() android.Module {
380 module := &Javadoc{}
381
382 module.AddProperties(&module.properties)
383
384 InitDroiddocModule(module, android.HostAndDeviceSupported)
385 return module
386}
387
Colin Crossa3002fc2019-07-08 16:48:04 -0700388// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800389func JavadocHostFactory() android.Module {
390 module := &Javadoc{}
391
392 module.AddProperties(&module.properties)
393
394 InitDroiddocModule(module, android.HostSupported)
395 return module
396}
397
Colin Cross41955e82019-05-29 14:40:35 -0700398var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800399
Jiyong Park6a927c42020-01-21 02:03:43 +0900400func (j *Javadoc) sdkVersion() sdkSpec {
401 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700402}
403
Paul Duffine25c6442019-10-11 13:50:28 +0100404func (j *Javadoc) systemModules() string {
405 return proptools.String(j.properties.System_modules)
406}
407
Jiyong Park6a927c42020-01-21 02:03:43 +0900408func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700409 return j.sdkVersion()
410}
411
Jiyong Park6a927c42020-01-21 02:03:43 +0900412func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700413 return j.sdkVersion()
414}
415
Nan Zhang581fd212018-01-10 16:06:12 -0800416func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
417 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100418 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700419 if sdkDep.useDefaultLibs {
420 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
421 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
422 if sdkDep.hasFrameworkLibs() {
423 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700424 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700425 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700426 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100427 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700428 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800429 }
430 }
431
Colin Cross42d48b72018-08-29 14:10:52 -0700432 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800433}
434
Nan Zhanga40da042018-08-01 12:48:00 -0700435func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
436 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900437
Colin Cross3047fa22019-04-18 10:56:44 -0700438 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900439
440 return flags
441}
442
443func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700444 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900445
446 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
447 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
448
449 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700450 var deps android.Paths
451
Jiyong Park1e440682018-05-23 18:42:04 +0900452 if aidlPreprocess.Valid() {
453 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700454 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900455 } else {
456 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
457 }
458
459 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
460 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
461 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
462 flags = append(flags, "-I"+src.String())
463 }
464
Colin Cross3047fa22019-04-18 10:56:44 -0700465 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900466}
467
Jiyong Parkd90d7412019-08-20 22:49:19 +0900468// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900469func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700470 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900471
472 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700473 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900474
Jiyong Park1112c4c2019-08-16 21:12:10 +0900475 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
476
Jiyong Park1e440682018-05-23 18:42:04 +0900477 for _, srcFile := range srcFiles {
478 switch srcFile.Ext() {
479 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700480 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900481 case ".logtags":
482 javaFile := genLogtags(ctx, srcFile)
483 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900484 default:
485 outSrcFiles = append(outSrcFiles, srcFile)
486 }
487 }
488
Colin Crossc0806172019-06-14 18:51:47 -0700489 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
490 if len(aidlSrcs) > 0 {
491 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
492 outSrcFiles = append(outSrcFiles, srcJarFiles...)
493 }
494
Jiyong Park1e440682018-05-23 18:42:04 +0900495 return outSrcFiles
496}
497
Nan Zhang581fd212018-01-10 16:06:12 -0800498func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
499 var deps deps
500
Colin Cross83bb3162018-06-25 15:48:06 -0700501 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800502 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700503 ctx.AddMissingDependencies(sdkDep.bootclasspath)
504 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800505 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700506 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000507 deps.aidlPreprocess = sdkDep.aidl
508 } else {
509 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800510 }
511
512 ctx.VisitDirectDeps(func(module android.Module) {
513 otherName := ctx.OtherModuleName(module)
514 tag := ctx.OtherModuleDependencyTag(module)
515
Colin Cross2d24c1b2018-05-23 10:59:18 -0700516 switch tag {
517 case bootClasspathTag:
518 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800519 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000520 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100521 // A system modules dependency has been added to the bootclasspath
522 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000523 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700524 } else {
525 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
526 }
527 case libTag:
528 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800529 case SdkLibraryDependency:
530 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700531 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900532 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900533 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700534 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800535 checkProducesJars(ctx, dep)
536 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800537 default:
538 ctx.ModuleErrorf("depends on non-java module %q", otherName)
539 }
Colin Cross6cef4812019-10-17 14:23:50 -0700540 case java9LibTag:
541 switch dep := module.(type) {
542 case Dependency:
543 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
544 default:
545 ctx.ModuleErrorf("depends on non-java module %q", otherName)
546 }
Nan Zhang357466b2018-04-17 17:38:36 -0700547 case systemModulesTag:
548 if deps.systemModules != nil {
549 panic("Found two system module dependencies")
550 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000551 sm := module.(SystemModulesProvider)
552 outputDir, outputDeps := sm.OutputDirAndDeps()
553 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800554 }
555 })
556 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
557 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800558 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900559
560 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
561 if filterPackages == nil {
562 return srcs
563 }
564 filtered := []android.Path{}
565 for _, src := range srcs {
566 if src.Ext() != ".java" {
567 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
568 // but otherwise metalava emits stub sources having references to the generated AIDL classes
569 // in filtered-out pacages (e.g. com.android.internal.*).
570 // TODO(b/141149570) We need to fix this by introducing default private constructors or
571 // fixing metalava to not emit constructors having references to unknown classes.
572 filtered = append(filtered, src)
573 continue
574 }
575 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800576 if android.HasAnyPrefix(packageName, filterPackages) {
577 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900578 }
579 }
580 return filtered
581 }
582 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
583
Nan Zhanga40da042018-08-01 12:48:00 -0700584 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900585 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800586
587 // srcs may depend on some genrule output.
588 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800589 j.srcJars = append(j.srcJars, deps.srcJars...)
590
Nan Zhang581fd212018-01-10 16:06:12 -0800591 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800592 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800593
Nan Zhang9c69a122018-08-22 10:22:08 -0700594 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800595 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
596 }
597 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800598
Colin Cross8a497952019-03-05 22:25:09 -0800599 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000600 argFilesMap := map[string]string{}
601 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700602
Paul Duffin99e4a502019-02-11 15:38:42 +0000603 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800604 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000605 if _, exists := argFilesMap[label]; !exists {
606 argFilesMap[label] = strings.Join(paths.Strings(), " ")
607 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700608 } else {
609 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000610 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700611 }
612 }
613
614 var err error
Colin Cross15638152019-07-11 11:11:35 -0700615 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700616 if strings.HasPrefix(name, "location ") {
617 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000618 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700619 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700620 } else {
Colin Cross15638152019-07-11 11:11:35 -0700621 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000622 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700623 }
624 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700625 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700626 }
Colin Cross15638152019-07-11 11:11:35 -0700627 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700628 })
629
630 if err != nil {
631 ctx.PropertyErrorf("args", "%s", err.Error())
632 }
633
Nan Zhang581fd212018-01-10 16:06:12 -0800634 return deps
635}
636
637func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
638 j.addDeps(ctx)
639}
640
641func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
642 deps := j.collectDeps(ctx)
643
Colin Crossdaa4c672019-07-15 22:53:46 -0700644 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800645
Colin Crossdaa4c672019-07-15 22:53:46 -0700646 outDir := android.PathForModuleOut(ctx, "out")
647 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
648
649 j.stubsSrcJar = nil
650
651 rule := android.NewRuleBuilder()
652
653 rule.Command().Text("rm -rf").Text(outDir.String())
654 rule.Command().Text("mkdir -p").Text(outDir.String())
655
656 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700657
Colin Cross83bb3162018-06-25 15:48:06 -0700658 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800659
Colin Crossdaa4c672019-07-15 22:53:46 -0700660 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
661 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800662
Colin Cross1e743852019-10-28 11:37:20 -0700663 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700664 Flag("-J-Xmx1024m").
665 Flag("-XDignore.symbol.file").
666 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800667
Colin Crossdaa4c672019-07-15 22:53:46 -0700668 rule.Command().
669 BuiltTool(ctx, "soong_zip").
670 Flag("-write_if_changed").
671 Flag("-d").
672 FlagWithOutput("-o ", j.docZip).
673 FlagWithArg("-C ", outDir.String()).
674 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700675
Colin Crossdaa4c672019-07-15 22:53:46 -0700676 rule.Restat()
677
678 zipSyncCleanupCmd(rule, srcJarDir)
679
680 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800681}
682
Nan Zhanga40da042018-08-01 12:48:00 -0700683//
684// Droiddoc
685//
686type Droiddoc struct {
687 Javadoc
688
689 properties DroiddocProperties
690 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700691 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700692 removedApiFile android.WritablePath
693 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700694
695 checkCurrentApiTimestamp android.WritablePath
696 updateCurrentApiTimestamp android.WritablePath
697 checkLastReleasedApiTimestamp android.WritablePath
698
Nan Zhanga40da042018-08-01 12:48:00 -0700699 apiFilePath android.Path
700}
701
Colin Crossa3002fc2019-07-08 16:48:04 -0700702// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700703func DroiddocFactory() android.Module {
704 module := &Droiddoc{}
705
706 module.AddProperties(&module.properties,
707 &module.Javadoc.properties)
708
709 InitDroiddocModule(module, android.HostAndDeviceSupported)
710 return module
711}
712
Colin Crossa3002fc2019-07-08 16:48:04 -0700713// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700714func DroiddocHostFactory() android.Module {
715 module := &Droiddoc{}
716
717 module.AddProperties(&module.properties,
718 &module.Javadoc.properties)
719
720 InitDroiddocModule(module, android.HostSupported)
721 return module
722}
723
724func (d *Droiddoc) ApiFilePath() android.Path {
725 return d.apiFilePath
726}
727
Nan Zhang581fd212018-01-10 16:06:12 -0800728func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
729 d.Javadoc.addDeps(ctx)
730
Inseob Kim38449af2019-02-28 14:24:05 +0900731 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
732 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
733 }
734
Nan Zhang79614d12018-04-19 18:03:39 -0700735 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800736 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
737 }
Nan Zhang581fd212018-01-10 16:06:12 -0800738}
739
Colin Crossab054432019-07-15 16:13:59 -0700740func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800741 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700742 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
743 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
744 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700745 cmd.FlagWithArg("-source ", "1.8").
746 Flag("-J-Xmx1600m").
747 Flag("-J-XX:-OmitStackTraceInFastThrow").
748 Flag("-XDignore.symbol.file").
749 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
750 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800751 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700752 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 -0700753
Nan Zhanga40da042018-08-01 12:48:00 -0700754 if String(d.properties.Custom_template) == "" {
755 // TODO: This is almost always droiddoc-templates-sdk
756 ctx.PropertyErrorf("custom_template", "must specify a template")
757 }
758
759 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700760 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700761 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700762 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000763 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700764 }
765 })
766
767 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700768 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
769 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
770 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700771 }
772
773 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700774 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
775 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
776 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700777 }
778
779 if len(d.properties.Html_dirs) > 2 {
780 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
781 }
782
Colin Cross8a497952019-03-05 22:25:09 -0800783 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700784 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700785
Colin Crossab054432019-07-15 16:13:59 -0700786 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700787
788 if String(d.properties.Proofread_file) != "" {
789 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700790 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700791 }
792
793 if String(d.properties.Todo_file) != "" {
794 // tricky part:
795 // we should not compute full path for todo_file through PathForModuleOut().
796 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700797 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
798 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700799 }
800
801 if String(d.properties.Resourcesdir) != "" {
802 // TODO: should we add files under resourcesDir to the implicits? It seems that
803 // resourcesDir is one sub dir of htmlDir
804 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700805 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700806 }
807
808 if String(d.properties.Resourcesoutdir) != "" {
809 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700810 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700811 }
Nan Zhanga40da042018-08-01 12:48:00 -0700812}
813
Colin Crossab054432019-07-15 16:13:59 -0700814func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200815 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
816 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700817 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700818
Nan Zhanga40da042018-08-01 12:48:00 -0700819 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700820 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700821 d.apiFilePath = d.apiFile
822 }
823
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200824 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
825 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700826 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700827 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700828 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700829 }
830
Nan Zhanga40da042018-08-01 12:48:00 -0700831 if String(d.properties.Removed_dex_api_filename) != "" {
832 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700833 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700834 }
835
Nan Zhanga40da042018-08-01 12:48:00 -0700836 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700837 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700838 }
839
840 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700841 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700842 }
Nan Zhanga40da042018-08-01 12:48:00 -0700843}
844
Colin Crossab054432019-07-15 16:13:59 -0700845func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700846 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700847 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
848 rule.Command().Text("cp").
849 Input(staticDocIndexRedirect).
850 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700851 }
852
853 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700854 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
855 rule.Command().Text("cp").
856 Input(staticDocProperties).
857 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700858 }
Nan Zhanga40da042018-08-01 12:48:00 -0700859}
860
Colin Crossab054432019-07-15 16:13:59 -0700861func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700862 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700863
864 cmd := rule.Command().
865 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
866 Flag(config.JavacVmFlags).
867 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700868 FlagWithRspFileInputList("@", srcs).
869 FlagWithInput("@", srcJarList)
870
Colin Crossab054432019-07-15 16:13:59 -0700871 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
872 // based stubs generation.
873 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
874 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
875 // the correct package name base path.
876 if len(sourcepaths) > 0 {
877 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
878 } else {
879 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
880 }
881
882 cmd.FlagWithArg("-d ", outDir.String()).
883 Flag("-quiet")
884
885 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700886}
887
Colin Crossdaa4c672019-07-15 22:53:46 -0700888func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
889 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
890 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
891
892 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
893
894 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
895 cmd.Flag(flag).Implicits(deps)
896
897 cmd.FlagWithArg("--patch-module ", "java.base=.")
898
899 if len(classpath) > 0 {
900 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
901 }
902
903 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700904}
905
Colin Crossdaa4c672019-07-15 22:53:46 -0700906func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
907 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
908 sourcepaths android.Paths) *android.RuleBuilderCommand {
909
910 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
911
912 if len(bootclasspath) == 0 && ctx.Device() {
913 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
914 // ensure java does not fall back to the default bootclasspath.
915 cmd.FlagWithArg("-bootclasspath ", `""`)
916 } else if len(bootclasspath) > 0 {
917 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
918 }
919
920 if len(classpath) > 0 {
921 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
922 }
923
924 return cmd
925}
926
Colin Crossab054432019-07-15 16:13:59 -0700927func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
928 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700929
Colin Crossab054432019-07-15 16:13:59 -0700930 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
931 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
932
933 return rule.Command().
934 BuiltTool(ctx, "dokka").
935 Flag(config.JavacVmFlags).
936 Flag(srcJarDir.String()).
937 FlagWithInputList("-classpath ", dokkaClasspath, ":").
938 FlagWithArg("-format ", "dac").
939 FlagWithArg("-dacRoot ", "/reference/kotlin").
940 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700941}
942
943func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
944 deps := d.Javadoc.collectDeps(ctx)
945
Colin Crossdaa4c672019-07-15 22:53:46 -0700946 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
947 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
948
Nan Zhang1598a9e2018-09-04 17:14:32 -0700949 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
950 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
951 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
952 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
953
Colin Crossab054432019-07-15 16:13:59 -0700954 outDir := android.PathForModuleOut(ctx, "out")
955 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
956 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700957
Colin Crossab054432019-07-15 16:13:59 -0700958 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700959
Colin Crossab054432019-07-15 16:13:59 -0700960 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
961 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700962
Colin Crossab054432019-07-15 16:13:59 -0700963 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
964
965 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700966 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700967 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700968 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700969 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700970 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700971 }
972
Colin Crossab054432019-07-15 16:13:59 -0700973 d.stubsFlags(ctx, cmd, stubsDir)
974
975 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
976
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000977 if d.properties.Compat_config != nil {
978 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
979 cmd.FlagWithInput("-compatconfig ", compatConfig)
980 }
981
Colin Crossab054432019-07-15 16:13:59 -0700982 var desc string
983 if Bool(d.properties.Dokka_enabled) {
984 desc = "dokka"
985 } else {
986 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
987
988 for _, o := range d.Javadoc.properties.Out {
989 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
990 }
991
992 d.postDoclavaCmds(ctx, rule)
993 desc = "doclava"
994 }
995
996 rule.Command().
997 BuiltTool(ctx, "soong_zip").
998 Flag("-write_if_changed").
999 Flag("-d").
1000 FlagWithOutput("-o ", d.docZip).
1001 FlagWithArg("-C ", outDir.String()).
1002 FlagWithArg("-D ", outDir.String())
1003
1004 rule.Command().
1005 BuiltTool(ctx, "soong_zip").
1006 Flag("-write_if_changed").
1007 Flag("-jar").
1008 FlagWithOutput("-o ", d.stubsSrcJar).
1009 FlagWithArg("-C ", stubsDir.String()).
1010 FlagWithArg("-D ", stubsDir.String())
1011
1012 rule.Restat()
1013
1014 zipSyncCleanupCmd(rule, srcJarDir)
1015
1016 rule.Build(pctx, ctx, "javadoc", desc)
1017
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001018 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001019 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001020
1021 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1022 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001023
1024 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001025
1026 rule := android.NewRuleBuilder()
1027
1028 rule.Command().Text("( true")
1029
1030 rule.Command().
1031 BuiltTool(ctx, "apicheck").
1032 Flag("-JXmx1024m").
1033 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1034 OptionalFlag(d.properties.Check_api.Current.Args).
1035 Input(apiFile).
1036 Input(d.apiFile).
1037 Input(removedApiFile).
1038 Input(d.removedApiFile)
1039
1040 msg := fmt.Sprintf(`\n******************************\n`+
1041 `You have tried to change the API from what has been previously approved.\n\n`+
1042 `To make these errors go away, you have two choices:\n`+
1043 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1044 ` errors above.\n\n`+
1045 ` 2. You can update current.txt by executing the following command:\n`+
1046 ` make %s-update-current-api\n\n`+
1047 ` To submit the revised current.txt to the main Android repository,\n`+
1048 ` you will need approval.\n`+
1049 `******************************\n`, ctx.ModuleName())
1050
1051 rule.Command().
1052 Text("touch").Output(d.checkCurrentApiTimestamp).
1053 Text(") || (").
1054 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1055 Text("; exit 38").
1056 Text(")")
1057
1058 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001059
1060 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001061
1062 // update API rule
1063 rule = android.NewRuleBuilder()
1064
1065 rule.Command().Text("( true")
1066
1067 rule.Command().
1068 Text("cp").Flag("-f").
1069 Input(d.apiFile).Flag(apiFile.String())
1070
1071 rule.Command().
1072 Text("cp").Flag("-f").
1073 Input(d.removedApiFile).Flag(removedApiFile.String())
1074
1075 msg = "failed to update public API"
1076
1077 rule.Command().
1078 Text("touch").Output(d.updateCurrentApiTimestamp).
1079 Text(") || (").
1080 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1081 Text("; exit 38").
1082 Text(")")
1083
1084 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001085 }
1086
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001087 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001088 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001089
1090 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1091 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001092
1093 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001094
1095 rule := android.NewRuleBuilder()
1096
1097 rule.Command().
1098 Text("(").
1099 BuiltTool(ctx, "apicheck").
1100 Flag("-JXmx1024m").
1101 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1102 OptionalFlag(d.properties.Check_api.Last_released.Args).
1103 Input(apiFile).
1104 Input(d.apiFile).
1105 Input(removedApiFile).
1106 Input(d.removedApiFile)
1107
1108 msg := `\n******************************\n` +
1109 `You have tried to change the API from what has been previously released in\n` +
1110 `an SDK. Please fix the errors listed above.\n` +
1111 `******************************\n`
1112
1113 rule.Command().
1114 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1115 Text(") || (").
1116 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1117 Text("; exit 38").
1118 Text(")")
1119
1120 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001121 }
1122}
1123
1124//
1125// Droidstubs
1126//
1127type Droidstubs struct {
1128 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001129 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001130
Pete Gillin581d6082018-10-22 15:55:04 +01001131 properties DroidstubsProperties
1132 apiFile android.WritablePath
1133 apiXmlFile android.WritablePath
1134 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001135 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001136 removedApiFile android.WritablePath
1137 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001138 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001139
1140 checkCurrentApiTimestamp android.WritablePath
1141 updateCurrentApiTimestamp android.WritablePath
1142 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001143 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001144 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001145
Pete Gillin581d6082018-10-22 15:55:04 +01001146 checkNullabilityWarningsTimestamp android.WritablePath
1147
Nan Zhang1598a9e2018-09-04 17:14:32 -07001148 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001149 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001150
1151 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001152
1153 jdiffDocZip android.WritablePath
1154 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001155
1156 metadataZip android.WritablePath
1157 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001158}
1159
Colin Crossa3002fc2019-07-08 16:48:04 -07001160// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1161// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1162// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001163func DroidstubsFactory() android.Module {
1164 module := &Droidstubs{}
1165
1166 module.AddProperties(&module.properties,
1167 &module.Javadoc.properties)
1168
1169 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001170 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001171 return module
1172}
1173
Colin Crossa3002fc2019-07-08 16:48:04 -07001174// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1175// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1176// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1177// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001178func DroidstubsHostFactory() android.Module {
1179 module := &Droidstubs{}
1180
1181 module.AddProperties(&module.properties,
1182 &module.Javadoc.properties)
1183
1184 InitDroiddocModule(module, android.HostSupported)
1185 return module
1186}
1187
1188func (d *Droidstubs) ApiFilePath() android.Path {
1189 return d.apiFilePath
1190}
1191
Paul Duffin1fd005d2020-04-09 01:08:11 +01001192func (d *Droidstubs) RemovedApiFilePath() android.Path {
1193 return d.removedApiFile
1194}
1195
Paul Duffin3d1248c2020-04-09 00:10:17 +01001196func (d *Droidstubs) StubsSrcJar() android.Path {
1197 return d.stubsSrcJar
1198}
1199
Nan Zhang1598a9e2018-09-04 17:14:32 -07001200func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1201 d.Javadoc.addDeps(ctx)
1202
Inseob Kim38449af2019-02-28 14:24:05 +09001203 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1204 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1205 }
1206
Nan Zhang1598a9e2018-09-04 17:14:32 -07001207 if len(d.properties.Merge_annotations_dirs) != 0 {
1208 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1209 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1210 }
1211 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001212
Pete Gillin77167902018-09-19 18:16:26 +01001213 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1214 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1215 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1216 }
1217 }
1218
Nan Zhang9c69a122018-08-22 10:22:08 -07001219 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1220 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1221 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1222 }
1223 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001224}
1225
Paul Duffin3ae29512020-04-08 18:18:03 +01001226func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001227 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1228 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001229 String(d.properties.Api_filename) != "" {
1230 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001231 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001232 d.apiFilePath = d.apiFile
1233 }
1234
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001235 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1236 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001237 String(d.properties.Removed_api_filename) != "" {
1238 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001239 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001240 }
1241
Nan Zhang1598a9e2018-09-04 17:14:32 -07001242 if String(d.properties.Removed_dex_api_filename) != "" {
1243 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001244 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001245 }
1246
Nan Zhang9c69a122018-08-22 10:22:08 -07001247 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001248 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1249 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001250 }
1251
Paul Duffin3ae29512020-04-08 18:18:03 +01001252 if stubsDir.Valid() {
1253 if Bool(d.properties.Create_doc_stubs) {
1254 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1255 } else {
1256 cmd.FlagWithArg("--stubs ", stubsDir.String())
1257 cmd.Flag("--exclude-documentation-from-stubs")
1258 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001259 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001260}
1261
Colin Cross33961b52019-07-11 11:01:22 -07001262func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001263 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001264 cmd.Flag("--include-annotations")
1265
Pete Gillinc382a562018-11-14 18:45:46 +00001266 validatingNullability :=
1267 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1268 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001269
Pete Gillina262c052018-09-14 14:25:48 +01001270 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001271 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001272 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001273 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001274 }
Colin Cross33961b52019-07-11 11:01:22 -07001275
Pete Gillinc382a562018-11-14 18:45:46 +00001276 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001277 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001278 }
Colin Cross33961b52019-07-11 11:01:22 -07001279
Pete Gillina262c052018-09-14 14:25:48 +01001280 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001281 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001282 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001283 }
Nan Zhanga40da042018-08-01 12:48:00 -07001284
1285 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001286 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001287
Nan Zhang1598a9e2018-09-04 17:14:32 -07001288 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001289 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001290 "has to be non-empty if annotations was enabled!")
1291 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001292
Colin Cross33961b52019-07-11 11:01:22 -07001293 d.mergeAnnoDirFlags(ctx, cmd)
1294
1295 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1296 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1297 FlagWithArg("--hide ", "SuperfluousPrefix").
1298 FlagWithArg("--hide ", "AnnotationExtraction")
1299 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001300}
1301
Colin Cross33961b52019-07-11 11:01:22 -07001302func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1303 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1304 if t, ok := m.(*ExportedDroiddocDir); ok {
1305 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1306 } else {
1307 ctx.PropertyErrorf("merge_annotations_dirs",
1308 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1309 }
1310 })
1311}
1312
1313func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001314 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1315 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001316 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001317 } else {
1318 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1319 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1320 }
1321 })
Nan Zhanga40da042018-08-01 12:48:00 -07001322}
1323
Colin Cross33961b52019-07-11 11:01:22 -07001324func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001325 if Bool(d.properties.Api_levels_annotations_enabled) {
1326 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001327
1328 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1329 ctx.PropertyErrorf("api_levels_annotations_dirs",
1330 "has to be non-empty if api levels annotations was enabled!")
1331 }
1332
Colin Cross33961b52019-07-11 11:01:22 -07001333 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1334 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1335 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1336 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001337
1338 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1339 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001340 for _, dep := range t.deps {
1341 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001342 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001343 }
1344 }
Colin Cross33961b52019-07-11 11:01:22 -07001345 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001346 } else {
1347 ctx.PropertyErrorf("api_levels_annotations_dirs",
1348 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1349 }
1350 })
1351
1352 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001353}
1354
Colin Cross33961b52019-07-11 11:01:22 -07001355func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001356 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1357 if d.apiFile.String() == "" {
1358 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1359 }
1360
1361 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001362 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001363
1364 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1365 ctx.PropertyErrorf("check_api.last_released.api_file",
1366 "has to be non-empty if jdiff was enabled!")
1367 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001368
Colin Cross33961b52019-07-11 11:01:22 -07001369 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001370 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001371 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1372 }
1373}
Nan Zhang71bbe632018-09-17 14:32:21 -07001374
Colin Cross1e743852019-10-28 11:37:20 -07001375func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001376 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001377 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1378 rule.HighMem()
Ramy Medhat427683c2020-04-30 03:08:37 -04001379 cmd := rule.Command()
1380 if ctx.Config().IsEnvTrue("RBE_METALAVA") {
1381 rule.Remoteable(android.RemoteRuleSupports{RBE: true})
1382 execStrategy := remoteexec.LocalExecStrategy
1383 if v := ctx.Config().Getenv("RBE_METALAVA_EXEC_STRATEGY"); v != "" {
1384 execStrategy = v
1385 }
1386 pool := "metalava"
1387 if v := ctx.Config().Getenv("RBE_METALAVA_POOL"); v != "" {
1388 pool = v
1389 }
1390 inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
1391 if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
1392 inputs = append(inputs, strings.Split(v, ",")...)
1393 }
1394 cmd.Text((&remoteexec.REParams{
1395 Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"},
1396 ExecStrategy: execStrategy,
1397 Inputs: inputs,
1398 ToolchainInputs: []string{config.JavaCmd(ctx).String()},
1399 Platform: map[string]string{remoteexec.PoolKey: pool},
1400 }).NoVarTemplate(ctx.Config()))
1401 }
1402
1403 cmd.BuiltTool(ctx, "metalava").
Colin Cross33961b52019-07-11 11:01:22 -07001404 Flag(config.JavacVmFlags).
1405 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001406 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001407 FlagWithRspFileInputList("@", srcs).
1408 FlagWithInput("@", srcJarList)
1409
1410 if len(bootclasspath) > 0 {
1411 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001412 }
1413
Colin Cross33961b52019-07-11 11:01:22 -07001414 if len(classpath) > 0 {
1415 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1416 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001417
Colin Cross33961b52019-07-11 11:01:22 -07001418 if len(sourcepaths) > 0 {
1419 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1420 } else {
1421 cmd.FlagWithArg("-sourcepath ", `""`)
1422 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001423
Colin Cross33961b52019-07-11 11:01:22 -07001424 cmd.Flag("--no-banner").
1425 Flag("--color").
1426 Flag("--quiet").
1427 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001428
Colin Cross33961b52019-07-11 11:01:22 -07001429 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001430}
1431
Nan Zhang1598a9e2018-09-04 17:14:32 -07001432func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001433 deps := d.Javadoc.collectDeps(ctx)
1434
1435 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001436
Colin Cross33961b52019-07-11 11:01:22 -07001437 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001438
Colin Cross33961b52019-07-11 11:01:22 -07001439 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001440
Colin Cross33961b52019-07-11 11:01:22 -07001441 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001442
Paul Duffin3ae29512020-04-08 18:18:03 +01001443 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1444 var stubsDir android.OptionalPath
1445 if generateStubs {
1446 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1447 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1448 rule.Command().Text("rm -rf").Text(stubsDir.String())
1449 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1450 }
Nan Zhanga40da042018-08-01 12:48:00 -07001451
Colin Cross33961b52019-07-11 11:01:22 -07001452 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1453
1454 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1455 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1456
1457 d.stubsFlags(ctx, cmd, stubsDir)
1458
1459 d.annotationsFlags(ctx, cmd)
1460 d.inclusionAnnotationsFlags(ctx, cmd)
1461 d.apiLevelsAnnotationsFlags(ctx, cmd)
1462 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001463
Nan Zhang1598a9e2018-09-04 17:14:32 -07001464 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1465 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1466 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1467 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1468 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001469 }
Colin Cross33961b52019-07-11 11:01:22 -07001470
1471 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1472 for _, o := range d.Javadoc.properties.Out {
1473 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1474 }
1475
Makoto Onuki88b99052020-04-27 17:22:16 -07001476 // Add options for the other optional tasks: API-lint and check-released.
1477 // We generate separate timestamp files for them.
1478
1479 doApiLint := false
1480 doCheckReleased := false
1481
1482 // Add API lint options.
1483
1484 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1485 doApiLint = true
1486
1487 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1488 if newSince.Valid() {
1489 cmd.FlagWithInput("--api-lint ", newSince.Path())
1490 } else {
1491 cmd.Flag("--api-lint")
1492 }
1493 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1494 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1495
1496 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1497 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1498 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1499
1500 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1501 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1502 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1503 // which is why we have '"$PWD"$' in it.
1504 //
1505 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1506 // message and metalava's one?
1507 msg := `$'` + // Enclose with $' ... '
1508 `************************************************************\n` +
1509 `Your API changes are triggering API Lint warnings or errors.\n` +
1510 `To make these errors go away, fix the code according to the\n` +
1511 `error and/or warning messages above.\n` +
1512 `\n` +
1513 `If it is not possible to do so, there are workarounds:\n` +
1514 `\n` +
1515 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1516
1517 if baselineFile.Valid() {
1518 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1519 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1520
1521 msg += fmt.Sprintf(``+
1522 `2. You can update the baseline by executing the following\n`+
1523 ` command:\n`+
Anton Hansson3361a292020-05-11 15:38:31 +01001524 ` cp \\\n`+
1525 ` "'"$PWD"$'/%s" \\\n`+
1526 ` "'"$PWD"$'/%s"\n`+
Makoto Onuki88b99052020-04-27 17:22:16 -07001527 ` To submit the revised baseline.txt to the main Android\n`+
1528 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1529 } else {
1530 msg += fmt.Sprintf(``+
1531 `2. You can add a baseline file of existing lint failures\n`+
1532 ` to the build rule of %s.\n`, d.Name())
1533 }
1534 // Note the message ends with a ' (single quote), to close the $' ... ' .
1535 msg += `************************************************************\n'`
1536
1537 cmd.FlagWithArg("--error-message:api-lint ", msg)
1538 }
1539
1540 // Add "check released" options. (Detect incompatible API changes from the last public release)
1541
1542 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
1543 !ctx.Config().IsPdkBuild() {
1544 doCheckReleased = true
1545
1546 if len(d.Javadoc.properties.Out) > 0 {
1547 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1548 }
1549
1550 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1551 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1552 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1553 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1554
1555 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1556
1557 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1558 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1559
1560 if baselineFile.Valid() {
1561 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1562 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1563 }
1564
1565 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1566 msg := `$'\n******************************\n` +
1567 `You have tried to change the API from what has been previously released in\n` +
1568 `an SDK. Please fix the errors listed above.\n` +
1569 `******************************\n'`
1570
1571 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1572 }
1573
Paul Duffin3ae29512020-04-08 18:18:03 +01001574 if generateStubs {
1575 rule.Command().
1576 BuiltTool(ctx, "soong_zip").
1577 Flag("-write_if_changed").
1578 Flag("-jar").
1579 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1580 FlagWithArg("-C ", stubsDir.String()).
1581 FlagWithArg("-D ", stubsDir.String())
1582 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001583
1584 if Bool(d.properties.Write_sdk_values) {
1585 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1586 rule.Command().
1587 BuiltTool(ctx, "soong_zip").
1588 Flag("-write_if_changed").
1589 Flag("-d").
1590 FlagWithOutput("-o ", d.metadataZip).
1591 FlagWithArg("-C ", d.metadataDir.String()).
1592 FlagWithArg("-D ", d.metadataDir.String())
1593 }
1594
Makoto Onuki88b99052020-04-27 17:22:16 -07001595 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1596 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1597 if doApiLint {
1598 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1599 }
1600 if doCheckReleased {
1601 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1602 }
1603
Colin Cross33961b52019-07-11 11:01:22 -07001604 rule.Restat()
1605
1606 zipSyncCleanupCmd(rule, srcJarDir)
1607
Makoto Onuki88b99052020-04-27 17:22:16 -07001608 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001609
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001610 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001611 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001612
1613 if len(d.Javadoc.properties.Out) > 0 {
1614 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1615 }
1616
1617 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1618 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001619 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onuki5405a732020-04-16 17:02:40 -07001620
1621 if baselineFile.Valid() {
Makoto Onuki88b99052020-04-27 17:22:16 -07001622 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onuki5405a732020-04-16 17:02:40 -07001623 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001624
Nan Zhang2760dfc2018-08-24 17:32:54 +00001625 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001626
Colin Cross33961b52019-07-11 11:01:22 -07001627 rule := android.NewRuleBuilder()
1628
Makoto Onuki5405a732020-04-16 17:02:40 -07001629 // Diff command line.
Makoto Onuki88b99052020-04-27 17:22:16 -07001630 // -F matches the closest "opening" line, such as "package android {"
1631 // and " public class Intent {".
Makoto Onuki5405a732020-04-16 17:02:40 -07001632 diff := `diff -u -F '{ *$'`
1633
Colin Cross33961b52019-07-11 11:01:22 -07001634 rule.Command().Text("( true")
Makoto Onuki5405a732020-04-16 17:02:40 -07001635 rule.Command().
1636 Text(diff).
1637 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001638
Makoto Onuki5405a732020-04-16 17:02:40 -07001639 rule.Command().
1640 Text(diff).
1641 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001642
1643 msg := fmt.Sprintf(`\n******************************\n`+
1644 `You have tried to change the API from what has been previously approved.\n\n`+
1645 `To make these errors go away, you have two choices:\n`+
Makoto Onuki5405a732020-04-16 17:02:40 -07001646 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1647 ` to the new methods, etc. shown in the above diff.\n\n`+
1648 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001649 ` make %s-update-current-api\n\n`+
1650 ` To submit the revised current.txt to the main Android repository,\n`+
1651 ` you will need approval.\n`+
1652 `******************************\n`, ctx.ModuleName())
1653
1654 rule.Command().
1655 Text("touch").Output(d.checkCurrentApiTimestamp).
1656 Text(") || (").
1657 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1658 Text("; exit 38").
1659 Text(")")
1660
Makoto Onuki5405a732020-04-16 17:02:40 -07001661 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001662
1663 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001664
1665 // update API rule
1666 rule = android.NewRuleBuilder()
1667
1668 rule.Command().Text("( true")
1669
1670 rule.Command().
1671 Text("cp").Flag("-f").
1672 Input(d.apiFile).Flag(apiFile.String())
1673
1674 rule.Command().
1675 Text("cp").Flag("-f").
1676 Input(d.removedApiFile).Flag(removedApiFile.String())
1677
1678 msg = "failed to update public API"
1679
1680 rule.Command().
1681 Text("touch").Output(d.updateCurrentApiTimestamp).
1682 Text(") || (").
1683 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1684 Text("; exit 38").
1685 Text(")")
1686
1687 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001688 }
Nan Zhanga40da042018-08-01 12:48:00 -07001689
Pete Gillin581d6082018-10-22 15:55:04 +01001690 if String(d.properties.Check_nullability_warnings) != "" {
1691 if d.nullabilityWarningsFile == nil {
1692 ctx.PropertyErrorf("check_nullability_warnings",
1693 "Cannot specify check_nullability_warnings unless validating nullability")
1694 }
Colin Cross33961b52019-07-11 11:01:22 -07001695
1696 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1697
Pete Gillin581d6082018-10-22 15:55:04 +01001698 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001699
Pete Gillin581d6082018-10-22 15:55:04 +01001700 msg := fmt.Sprintf(`\n******************************\n`+
1701 `The warnings encountered during nullability annotation validation did\n`+
1702 `not match the checked in file of expected warnings. The diffs are shown\n`+
1703 `above. You have two options:\n`+
1704 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1705 ` 2. Update the file of expected warnings by running:\n`+
1706 ` cp %s %s\n`+
1707 ` and submitting the updated file as part of your change.`,
1708 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001709
1710 rule := android.NewRuleBuilder()
1711
1712 rule.Command().
1713 Text("(").
1714 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1715 Text("&&").
1716 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1717 Text(") || (").
1718 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1719 Text("; exit 38").
1720 Text(")")
1721
1722 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001723 }
1724
Nan Zhang71bbe632018-09-17 14:32:21 -07001725 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001726 if len(d.Javadoc.properties.Out) > 0 {
1727 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1728 }
1729
1730 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1731 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1732 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1733
1734 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001735
Nan Zhang86b06202018-09-21 17:09:21 -07001736 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1737 // since there's cron job downstream that fetch this .zip file periodically.
1738 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001739 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1740 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1741
Nan Zhang71bbe632018-09-17 14:32:21 -07001742 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001743
Colin Cross33961b52019-07-11 11:01:22 -07001744 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1745 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001746
Colin Cross33961b52019-07-11 11:01:22 -07001747 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1748
Colin Crossdaa4c672019-07-15 22:53:46 -07001749 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001750 deps.bootClasspath, deps.classpath, d.sourcepaths)
1751
1752 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001753 Flag("-XDignore.symbol.file").
1754 FlagWithArg("-doclet ", "jdiff.JDiff").
1755 FlagWithInput("-docletpath ", jdiff).
1756 Flag("-quiet").
1757 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1758 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1759 Implicit(d.apiXmlFile).
1760 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1761 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1762 Implicit(d.lastReleasedApiXmlFile)
1763
Colin Cross33961b52019-07-11 11:01:22 -07001764 rule.Command().
1765 BuiltTool(ctx, "soong_zip").
1766 Flag("-write_if_changed").
1767 Flag("-d").
1768 FlagWithOutput("-o ", d.jdiffDocZip).
1769 FlagWithArg("-C ", outDir.String()).
1770 FlagWithArg("-D ", outDir.String())
1771
1772 rule.Command().
1773 BuiltTool(ctx, "soong_zip").
1774 Flag("-write_if_changed").
1775 Flag("-jar").
1776 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1777 FlagWithArg("-C ", stubsDir.String()).
1778 FlagWithArg("-D ", stubsDir.String())
1779
1780 rule.Restat()
1781
1782 zipSyncCleanupCmd(rule, srcJarDir)
1783
1784 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001785 }
Nan Zhang581fd212018-01-10 16:06:12 -08001786}
Dan Willemsencc090972018-02-26 14:33:31 -08001787
Nan Zhanga40da042018-08-01 12:48:00 -07001788//
Nan Zhangf4936b02018-08-01 15:00:28 -07001789// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001790//
Dan Willemsencc090972018-02-26 14:33:31 -08001791var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001792var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001793var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001794var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001795
Nan Zhangf4936b02018-08-01 15:00:28 -07001796type ExportedDroiddocDirProperties struct {
1797 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001798 Path *string
1799}
1800
Nan Zhangf4936b02018-08-01 15:00:28 -07001801type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001802 android.ModuleBase
1803
Nan Zhangf4936b02018-08-01 15:00:28 -07001804 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001805
1806 deps android.Paths
1807 dir android.Path
1808}
1809
Colin Crossa3002fc2019-07-08 16:48:04 -07001810// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001811func ExportedDroiddocDirFactory() android.Module {
1812 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001813 module.AddProperties(&module.properties)
1814 android.InitAndroidModule(module)
1815 return module
1816}
1817
Nan Zhangf4936b02018-08-01 15:00:28 -07001818func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001819
Nan Zhangf4936b02018-08-01 15:00:28 -07001820func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001821 path := String(d.properties.Path)
1822 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001823 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001824}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001825
1826//
1827// Defaults
1828//
1829type DocDefaults struct {
1830 android.ModuleBase
1831 android.DefaultsModuleBase
1832}
1833
Nan Zhangb2b33de2018-02-23 11:18:47 -08001834func DocDefaultsFactory() android.Module {
1835 module := &DocDefaults{}
1836
1837 module.AddProperties(
1838 &JavadocProperties{},
1839 &DroiddocProperties{},
1840 )
1841
1842 android.InitDefaultsModule(module)
1843
1844 return module
1845}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001846
1847func StubsDefaultsFactory() android.Module {
1848 module := &DocDefaults{}
1849
1850 module.AddProperties(
1851 &JavadocProperties{},
1852 &DroidstubsProperties{},
1853 )
1854
1855 android.InitDefaultsModule(module)
1856
1857 return module
1858}
Colin Cross33961b52019-07-11 11:01:22 -07001859
1860func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1861 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1862
1863 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1864 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1865 srcJarList := srcJarDir.Join(ctx, "list")
1866
1867 rule.Temporary(srcJarList)
1868
1869 rule.Command().BuiltTool(ctx, "zipsync").
1870 FlagWithArg("-d ", srcJarDir.String()).
1871 FlagWithOutput("-l ", srcJarList).
1872 FlagWithArg("-f ", `"*.java"`).
1873 Inputs(srcJars)
1874
1875 return srcJarList
1876}
1877
1878func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1879 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1880}
Paul Duffin91547182019-11-12 19:39:36 +00001881
1882var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1883
1884type PrebuiltStubsSourcesProperties struct {
1885 Srcs []string `android:"path"`
1886}
1887
1888type PrebuiltStubsSources struct {
1889 android.ModuleBase
1890 android.DefaultableModuleBase
1891 prebuilt android.Prebuilt
1892 android.SdkBase
1893
1894 properties PrebuiltStubsSourcesProperties
1895
Paul Duffin9b478b02019-12-10 13:41:51 +00001896 // The source directories containing stubs source files.
1897 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001898 stubsSrcJar android.ModuleOutPath
1899}
1900
Paul Duffin9b478b02019-12-10 13:41:51 +00001901func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1902 switch tag {
1903 case "":
1904 return android.Paths{p.stubsSrcJar}, nil
1905 default:
1906 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1907 }
1908}
1909
Paul Duffin91547182019-11-12 19:39:36 +00001910func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001911 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1912
1913 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1914
1915 rule := android.NewRuleBuilder()
1916 command := rule.Command().
1917 BuiltTool(ctx, "soong_zip").
1918 Flag("-write_if_changed").
1919 Flag("-jar").
1920 FlagWithOutput("-o ", p.stubsSrcJar)
1921
1922 for _, d := range p.srcDirs {
1923 dir := d.String()
1924 command.
1925 FlagWithArg("-C ", dir).
1926 FlagWithInput("-D ", d)
1927 }
1928
1929 rule.Restat()
1930
1931 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001932}
1933
1934func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1935 return &p.prebuilt
1936}
1937
1938func (p *PrebuiltStubsSources) Name() string {
1939 return p.prebuilt.Name(p.ModuleBase.Name())
1940}
1941
Paul Duffin91547182019-11-12 19:39:36 +00001942// prebuilt_stubs_sources imports a set of java source files as if they were
1943// generated by droidstubs.
1944//
1945// By default, a prebuilt_stubs_sources has a single variant that expects a
1946// set of `.java` files generated by droidstubs.
1947//
1948// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1949// for host modules.
1950//
1951// Intended only for use by sdk snapshots.
1952func PrebuiltStubsSourcesFactory() android.Module {
1953 module := &PrebuiltStubsSources{}
1954
1955 module.AddProperties(&module.properties)
1956
1957 android.InitPrebuiltModule(module, &module.properties.Srcs)
1958 android.InitSdkAwareModule(module)
1959 InitDroiddocModule(module, android.HostAndDeviceSupported)
1960 return module
1961}
1962
Paul Duffin13879572019-11-28 14:31:38 +00001963type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001964 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001965}
1966
1967func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1968 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1969}
1970
1971func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1972 _, ok := module.(*Droidstubs)
1973 return ok
1974}
1975
Paul Duffin495ffb92020-03-20 13:35:40 +00001976func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1977 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
1978}
1979
1980func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1981 return &droidStubsInfoProperties{}
1982}
1983
1984type droidStubsInfoProperties struct {
1985 android.SdkMemberPropertiesBase
1986
1987 StubsSrcJar android.Path
1988}
1989
1990func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
1991 droidstubs := variant.(*Droidstubs)
1992 p.StubsSrcJar = droidstubs.stubsSrcJar
1993}
1994
1995func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
1996 if p.StubsSrcJar != nil {
1997 builder := ctx.SnapshotBuilder()
1998
1999 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2000
2001 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2002
2003 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002004 }
Paul Duffin91547182019-11-12 19:39:36 +00002005}