blob: a637349c815dce4951b53b65fb682a875ce2e03a [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000030 RegisterDocsBuildComponents(android.InitRegistrationContext)
31 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000032
33 // Register sdk member type.
34 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
35 SdkMemberTypeBase: android.SdkMemberTypeBase{
36 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000037 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
38 // the APEX.
39 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000040 },
41 })
Nan Zhang581fd212018-01-10 16:06:12 -080042}
43
Paul Duffin884363e2019-12-19 10:21:09 +000044func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
45 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
46
47 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
48 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
49 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
50 ctx.RegisterModuleType("javadoc", JavadocFactory)
51 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
52}
53
54func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
55 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
56
57 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
58 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
59
60 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
61}
62
Colin Crossa1ce2a02018-06-20 15:19:39 -070063var (
64 srcsLibTag = dependencyTag{name: "sources from javalib"}
65)
66
Nan Zhang581fd212018-01-10 16:06:12 -080067type JavadocProperties struct {
68 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
69 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080070 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080071
72 // list of directories rooted at the Android.bp file that will
73 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080075
76 // list of source files that should not be used to build the Java module.
77 // This is most useful in the arch/multilib variants to remove non-common files
78 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080079 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080080
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090081 // list of package names that should actually be used. If this property is left unspecified,
82 // all the sources from the srcs property is used.
83 Filter_packages []string
84
Nan Zhangb2b33de2018-02-23 11:18:47 -080085 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080086 Libs []string `android:"arch_variant"`
87
88 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080089 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080090
Paul Duffine25c6442019-10-11 13:50:28 +010091 // if not blank, set to the version of the sdk to compile against.
92 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080093 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090094
Paul Duffine25c6442019-10-11 13:50:28 +010095 // When targeting 1.9 and above, override the modules to use with --system,
96 // otherwise provides defaults libraries to add to the bootclasspath.
97 // Defaults to "none"
98 System_modules *string
99
Jiyong Park1e440682018-05-23 18:42:04 +0900100 Aidl struct {
101 // Top level directories to pass to aidl tool
102 Include_dirs []string
103
104 // Directories rooted at the Android.bp file to pass to aidl tool
105 Local_include_dirs []string
106 }
Nan Zhang357466b2018-04-17 17:38:36 -0700107
108 // If not blank, set the java version passed to javadoc as -source
109 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
111 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800112 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700113
114 // user customized droiddoc args.
115 // Available variables for substitution:
116 //
117 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700118 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700119 Args *string
120
121 // names of the output files used in args that will be generated
122 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800123}
124
Nan Zhang61819ce2018-05-04 18:49:16 -0700125type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900126 // path to the API txt file that the new API extracted from source code is checked
127 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800128 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700129
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900130 // path to the API txt file that the new @removed API extractd from source code is
131 // checked against. The path can be local to the module or from other module (via
132 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800133 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700134
Adrian Roos14f75a92019-08-12 17:54:09 +0200135 // If not blank, path to the baseline txt file for approved API check violations.
136 Baseline_file *string `android:"path"`
137
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700139 Args *string
140}
141
Nan Zhang581fd212018-01-10 16:06:12 -0800142type DroiddocProperties struct {
143 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800144 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800145
Nan Zhanga40da042018-08-01 12:48:00 -0700146 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800147 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800148
149 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800150 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800151
152 // proofread file contains all of the text content of the javadocs concatenated into one file,
153 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700154 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // a todo file lists the program elements that are missing documentation.
157 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800158 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800159
160 // directory under current module source that provide additional resources (images).
161 Resourcesdir *string
162
163 // resources output directory under out/soong/.intermediates.
164 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800165
Nan Zhange2ba5d42018-07-11 15:16:55 -0700166 // if set to true, collect the values used by the Dev tools and
167 // write them in files packaged with the SDK. Defaults to false.
168 Write_sdk_values *bool
169
170 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700172
173 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800174 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700175
Nan Zhang581fd212018-01-10 16:06:12 -0800176 // a list of files under current module source dir which contains known tags in Java sources.
177 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700179
Nan Zhang28c68b92018-03-13 16:17:01 -0700180 // the generated public API filename by Doclava.
181 Api_filename *string
182
Nan Zhang28c68b92018-03-13 16:17:01 -0700183 // the generated removed API filename by Doclava.
184 Removed_api_filename *string
185
David Brazdilaac0c3c2018-04-24 16:23:29 +0100186 // the generated removed Dex API filename by Doclava.
187 Removed_dex_api_filename *string
188
Nan Zhang853f4202018-04-12 16:55:56 -0700189 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
190 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700191
192 Check_api struct {
193 Last_released ApiToCheck
194
195 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900196
197 // do not perform API check against Last_released, in the case that both two specified API
198 // files by Last_released are modules which don't exist.
199 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700200 }
Nan Zhang79614d12018-04-19 18:03:39 -0700201
Nan Zhang1598a9e2018-09-04 17:14:32 -0700202 // if set to true, generate docs through Dokka instead of Doclava.
203 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000204
205 // Compat config XML. Generates compat change documentation if set.
206 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700207}
208
209type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700210 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700211 Api_filename *string
212
Nan Zhang199645c2018-09-19 12:40:06 -0700213 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700214 Removed_api_filename *string
215
Nan Zhang199645c2018-09-19 12:40:06 -0700216 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700217 Removed_dex_api_filename *string
218
Nan Zhang1598a9e2018-09-04 17:14:32 -0700219 Check_api struct {
220 Last_released ApiToCheck
221
222 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900223
Paul Duffin8986cc92020-05-10 19:32:20 +0100224 // The java_sdk_library module generates references to modules (i.e. filegroups)
225 // from which information about the latest API version can be obtained. As those
226 // modules may not exist (e.g. because a previous version has not been released) it
227 // sets ignore_missing_latest_api=true on the droidstubs modules it creates so
228 // that droidstubs can ignore those references if the modules do not yet exist.
229 //
230 // If true then this will ignore module references for modules that do not exist
231 // in properties that supply the previous version of the API.
232 //
233 // There are two sets of those:
234 // * Api_file, Removed_api_file in check_api.last_released
235 // * New_since in check_api.api_lint.new_since
236 //
237 // The first two must be set as a pair, so either they should both exist or neither
238 // should exist - in which case when this property is true they are ignored. If one
239 // exists and the other does not then it is an error.
Inseob Kim38449af2019-02-28 14:24:05 +0900240 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200241
242 Api_lint struct {
243 Enabled *bool
244
245 // If set, performs api_lint on any new APIs not found in the given signature file
246 New_since *string `android:"path"`
247
248 // If not blank, path to the baseline txt file for approved API lint violations.
249 Baseline_file *string `android:"path"`
250 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700251 }
Nan Zhang79614d12018-04-19 18:03:39 -0700252
253 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800254 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700255
256 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700257 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700258
Pete Gillin77167902018-09-19 18:16:26 +0100259 // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700260 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700261
Pete Gillin77167902018-09-19 18:16:26 +0100262 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
263 Merge_inclusion_annotations_dirs []string
264
Pete Gillinc382a562018-11-14 18:45:46 +0000265 // a file containing a list of classes to do nullability validation for.
266 Validate_nullability_from_list *string
267
Pete Gillin581d6082018-10-22 15:55:04 +0100268 // a file containing expected warnings produced by validation of nullability annotations.
269 Check_nullability_warnings *string
270
Nan Zhang1598a9e2018-09-04 17:14:32 -0700271 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
272 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700273
Paul Duffin455b0bf2020-04-08 18:18:03 +0100274 // if set to false then do not write out stubs. Defaults to true.
275 //
276 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
277 Generate_stubs *bool
278
Nan Zhang9c69a122018-08-22 10:22:08 -0700279 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
280 Api_levels_annotations_enabled *bool
281
282 // the dirs which Metalava extracts API levels annotations from.
283 Api_levels_annotations_dirs []string
284
285 // if set to true, collect the values used by the Dev tools and
286 // write them in files packaged with the SDK. Defaults to false.
287 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700288
289 // If set to true, .xml based public API file will be also generated, and
290 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
291 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800292}
293
Nan Zhanga40da042018-08-01 12:48:00 -0700294//
295// Common flags passed down to build rule
296//
297type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700298 bootClasspathArgs string
299 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700300 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700301 dokkaClasspathArgs string
302 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700303 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700304
Nan Zhanga40da042018-08-01 12:48:00 -0700305 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700306 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700307 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700308}
309
310func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
311 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
312 android.InitDefaultableModule(module)
313}
314
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200315func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
316 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
317 return false
318 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700319 return true
320 } else if String(apiToCheck.Api_file) != "" {
321 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
322 } else if String(apiToCheck.Removed_api_file) != "" {
323 panic("for " + apiVersionTag + " api_file has to be non-empty!")
324 }
325
326 return false
327}
328
Inseob Kim38449af2019-02-28 14:24:05 +0900329func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
330 api_file := String(apiToCheck.Api_file)
331 removed_api_file := String(apiToCheck.Removed_api_file)
332
333 api_module := android.SrcIsModule(api_file)
334 removed_api_module := android.SrcIsModule(removed_api_file)
335
336 if api_module == "" || removed_api_module == "" {
337 return
338 }
339
340 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
341 return
342 }
343
344 apiToCheck.Api_file = nil
345 apiToCheck.Removed_api_file = nil
346}
347
Paul Duffinf488ef22020-04-09 00:10:17 +0100348// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700349type ApiFilePath interface {
350 ApiFilePath() android.Path
351}
352
Paul Duffindce3fe72020-05-20 16:18:00 +0100353type ApiStubsSrcProvider interface {
354 StubsSrcJar() android.Path
355}
356
Paul Duffinf488ef22020-04-09 00:10:17 +0100357// Provider of information about API stubs, used by java_sdk_library.
358type ApiStubsProvider interface {
359 ApiFilePath
Paul Duffin75dcc802020-04-09 01:08:11 +0100360 RemovedApiFilePath() android.Path
Paul Duffindce3fe72020-05-20 16:18:00 +0100361
362 ApiStubsSrcProvider
Paul Duffinf488ef22020-04-09 00:10:17 +0100363}
364
Nan Zhanga40da042018-08-01 12:48:00 -0700365//
366// Javadoc
367//
Nan Zhang581fd212018-01-10 16:06:12 -0800368type Javadoc struct {
369 android.ModuleBase
370 android.DefaultableModuleBase
371
372 properties JavadocProperties
373
374 srcJars android.Paths
375 srcFiles android.Paths
376 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700377 argFiles android.Paths
378
379 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800380
Nan Zhangccff0f72018-03-08 17:26:16 -0800381 docZip android.WritablePath
382 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800383}
384
Colin Cross41955e82019-05-29 14:40:35 -0700385func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
386 switch tag {
387 case "":
388 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700389 case ".docs.zip":
390 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700391 default:
392 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
393 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800394}
395
Colin Crossa3002fc2019-07-08 16:48:04 -0700396// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800397func JavadocFactory() android.Module {
398 module := &Javadoc{}
399
400 module.AddProperties(&module.properties)
401
402 InitDroiddocModule(module, android.HostAndDeviceSupported)
403 return module
404}
405
Colin Crossa3002fc2019-07-08 16:48:04 -0700406// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800407func JavadocHostFactory() android.Module {
408 module := &Javadoc{}
409
410 module.AddProperties(&module.properties)
411
412 InitDroiddocModule(module, android.HostSupported)
413 return module
414}
415
Colin Cross41955e82019-05-29 14:40:35 -0700416var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800417
Jiyong Park6a927c42020-01-21 02:03:43 +0900418func (j *Javadoc) sdkVersion() sdkSpec {
419 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700420}
421
Paul Duffine25c6442019-10-11 13:50:28 +0100422func (j *Javadoc) systemModules() string {
423 return proptools.String(j.properties.System_modules)
424}
425
Jiyong Park6a927c42020-01-21 02:03:43 +0900426func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700427 return j.sdkVersion()
428}
429
Jiyong Park6a927c42020-01-21 02:03:43 +0900430func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700431 return j.sdkVersion()
432}
433
Nan Zhang581fd212018-01-10 16:06:12 -0800434func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
435 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100436 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700437 if sdkDep.useDefaultLibs {
438 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
439 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
440 if sdkDep.hasFrameworkLibs() {
441 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700442 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700443 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700444 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100445 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700446 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800447 }
448 }
449
Colin Cross42d48b72018-08-29 14:10:52 -0700450 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800451}
452
Nan Zhanga40da042018-08-01 12:48:00 -0700453func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
454 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900455
Colin Cross3047fa22019-04-18 10:56:44 -0700456 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900457
458 return flags
459}
460
461func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700462 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900463
464 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
465 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
466
467 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700468 var deps android.Paths
469
Jiyong Park1e440682018-05-23 18:42:04 +0900470 if aidlPreprocess.Valid() {
471 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700472 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900473 } else {
474 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
475 }
476
477 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
478 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
479 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
480 flags = append(flags, "-I"+src.String())
481 }
482
Colin Cross3047fa22019-04-18 10:56:44 -0700483 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900484}
485
Jiyong Parkd90d7412019-08-20 22:49:19 +0900486// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900487func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700488 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900489
490 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700491 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900492
Jiyong Park1112c4c2019-08-16 21:12:10 +0900493 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
494
Jiyong Park1e440682018-05-23 18:42:04 +0900495 for _, srcFile := range srcFiles {
496 switch srcFile.Ext() {
497 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700498 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900499 case ".logtags":
500 javaFile := genLogtags(ctx, srcFile)
501 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900502 default:
503 outSrcFiles = append(outSrcFiles, srcFile)
504 }
505 }
506
Colin Crossc0806172019-06-14 18:51:47 -0700507 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
508 if len(aidlSrcs) > 0 {
509 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
510 outSrcFiles = append(outSrcFiles, srcJarFiles...)
511 }
512
Jiyong Park1e440682018-05-23 18:42:04 +0900513 return outSrcFiles
514}
515
Nan Zhang581fd212018-01-10 16:06:12 -0800516func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
517 var deps deps
518
Colin Cross83bb3162018-06-25 15:48:06 -0700519 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800520 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700521 ctx.AddMissingDependencies(sdkDep.bootclasspath)
522 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800523 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700524 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000525 deps.aidlPreprocess = sdkDep.aidl
526 } else {
527 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800528 }
529
530 ctx.VisitDirectDeps(func(module android.Module) {
531 otherName := ctx.OtherModuleName(module)
532 tag := ctx.OtherModuleDependencyTag(module)
533
Colin Cross2d24c1b2018-05-23 10:59:18 -0700534 switch tag {
535 case bootClasspathTag:
536 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800537 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000538 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100539 // A system modules dependency has been added to the bootclasspath
540 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000541 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700542 } else {
543 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
544 }
545 case libTag:
546 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800547 case SdkLibraryDependency:
548 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700549 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900550 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900551 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700552 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800553 checkProducesJars(ctx, dep)
554 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800555 default:
556 ctx.ModuleErrorf("depends on non-java module %q", otherName)
557 }
Colin Cross6cef4812019-10-17 14:23:50 -0700558 case java9LibTag:
559 switch dep := module.(type) {
560 case Dependency:
561 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
562 default:
563 ctx.ModuleErrorf("depends on non-java module %q", otherName)
564 }
Nan Zhang357466b2018-04-17 17:38:36 -0700565 case systemModulesTag:
566 if deps.systemModules != nil {
567 panic("Found two system module dependencies")
568 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000569 sm := module.(SystemModulesProvider)
570 outputDir, outputDeps := sm.OutputDirAndDeps()
571 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800572 }
573 })
574 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
575 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800576 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900577
578 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
579 if filterPackages == nil {
580 return srcs
581 }
582 filtered := []android.Path{}
583 for _, src := range srcs {
584 if src.Ext() != ".java" {
585 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
586 // but otherwise metalava emits stub sources having references to the generated AIDL classes
587 // in filtered-out pacages (e.g. com.android.internal.*).
588 // TODO(b/141149570) We need to fix this by introducing default private constructors or
589 // fixing metalava to not emit constructors having references to unknown classes.
590 filtered = append(filtered, src)
591 continue
592 }
593 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800594 if android.HasAnyPrefix(packageName, filterPackages) {
595 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900596 }
597 }
598 return filtered
599 }
600 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
601
Nan Zhanga40da042018-08-01 12:48:00 -0700602 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900603 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800604
605 // srcs may depend on some genrule output.
606 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800607 j.srcJars = append(j.srcJars, deps.srcJars...)
608
Nan Zhang581fd212018-01-10 16:06:12 -0800609 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800610 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800611
Nan Zhang9c69a122018-08-22 10:22:08 -0700612 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800613 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
614 }
615 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800616
Colin Cross8a497952019-03-05 22:25:09 -0800617 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000618 argFilesMap := map[string]string{}
619 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700620
Paul Duffin99e4a502019-02-11 15:38:42 +0000621 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800622 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000623 if _, exists := argFilesMap[label]; !exists {
624 argFilesMap[label] = strings.Join(paths.Strings(), " ")
625 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700626 } else {
627 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000628 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700629 }
630 }
631
632 var err error
Colin Cross15638152019-07-11 11:11:35 -0700633 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 if strings.HasPrefix(name, "location ") {
635 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000636 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700637 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700638 } else {
Colin Cross15638152019-07-11 11:11:35 -0700639 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000640 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700641 }
642 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700643 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700644 }
Colin Cross15638152019-07-11 11:11:35 -0700645 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700646 })
647
648 if err != nil {
649 ctx.PropertyErrorf("args", "%s", err.Error())
650 }
651
Nan Zhang581fd212018-01-10 16:06:12 -0800652 return deps
653}
654
655func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
656 j.addDeps(ctx)
657}
658
659func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
660 deps := j.collectDeps(ctx)
661
Colin Crossdaa4c672019-07-15 22:53:46 -0700662 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800663
Colin Crossdaa4c672019-07-15 22:53:46 -0700664 outDir := android.PathForModuleOut(ctx, "out")
665 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
666
667 j.stubsSrcJar = nil
668
669 rule := android.NewRuleBuilder()
670
671 rule.Command().Text("rm -rf").Text(outDir.String())
672 rule.Command().Text("mkdir -p").Text(outDir.String())
673
674 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700675
Colin Cross83bb3162018-06-25 15:48:06 -0700676 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800677
Colin Crossdaa4c672019-07-15 22:53:46 -0700678 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
679 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800680
Colin Cross1e743852019-10-28 11:37:20 -0700681 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700682 Flag("-J-Xmx1024m").
683 Flag("-XDignore.symbol.file").
684 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800685
Colin Crossdaa4c672019-07-15 22:53:46 -0700686 rule.Command().
687 BuiltTool(ctx, "soong_zip").
688 Flag("-write_if_changed").
689 Flag("-d").
690 FlagWithOutput("-o ", j.docZip).
691 FlagWithArg("-C ", outDir.String()).
692 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700693
Colin Crossdaa4c672019-07-15 22:53:46 -0700694 rule.Restat()
695
696 zipSyncCleanupCmd(rule, srcJarDir)
697
698 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800699}
700
Nan Zhanga40da042018-08-01 12:48:00 -0700701//
702// Droiddoc
703//
704type Droiddoc struct {
705 Javadoc
706
707 properties DroiddocProperties
708 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700709 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700710 removedApiFile android.WritablePath
711 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700712
713 checkCurrentApiTimestamp android.WritablePath
714 updateCurrentApiTimestamp android.WritablePath
715 checkLastReleasedApiTimestamp android.WritablePath
716
Nan Zhanga40da042018-08-01 12:48:00 -0700717 apiFilePath android.Path
718}
719
Colin Crossa3002fc2019-07-08 16:48:04 -0700720// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700721func DroiddocFactory() android.Module {
722 module := &Droiddoc{}
723
724 module.AddProperties(&module.properties,
725 &module.Javadoc.properties)
726
727 InitDroiddocModule(module, android.HostAndDeviceSupported)
728 return module
729}
730
Colin Crossa3002fc2019-07-08 16:48:04 -0700731// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700732func DroiddocHostFactory() android.Module {
733 module := &Droiddoc{}
734
735 module.AddProperties(&module.properties,
736 &module.Javadoc.properties)
737
738 InitDroiddocModule(module, android.HostSupported)
739 return module
740}
741
742func (d *Droiddoc) ApiFilePath() android.Path {
743 return d.apiFilePath
744}
745
Nan Zhang581fd212018-01-10 16:06:12 -0800746func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
747 d.Javadoc.addDeps(ctx)
748
Inseob Kim38449af2019-02-28 14:24:05 +0900749 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
750 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
751 }
752
Nan Zhang79614d12018-04-19 18:03:39 -0700753 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800754 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
755 }
Nan Zhang581fd212018-01-10 16:06:12 -0800756}
757
Colin Crossab054432019-07-15 16:13:59 -0700758func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000759 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700760 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
761 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
762 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700763 cmd.FlagWithArg("-source ", "1.8").
764 Flag("-J-Xmx1600m").
765 Flag("-J-XX:-OmitStackTraceInFastThrow").
766 Flag("-XDignore.symbol.file").
767 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
768 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Automerger Merge Worker82f316b2020-02-28 21:26:56 +0000769 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700770 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 -0700771
Nan Zhanga40da042018-08-01 12:48:00 -0700772 if String(d.properties.Custom_template) == "" {
773 // TODO: This is almost always droiddoc-templates-sdk
774 ctx.PropertyErrorf("custom_template", "must specify a template")
775 }
776
777 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700778 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700779 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700780 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000781 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700782 }
783 })
784
785 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700786 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
787 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
788 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700789 }
790
791 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700792 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
793 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
794 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700795 }
796
797 if len(d.properties.Html_dirs) > 2 {
798 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
799 }
800
Colin Cross8a497952019-03-05 22:25:09 -0800801 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700802 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700803
Colin Crossab054432019-07-15 16:13:59 -0700804 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700805
806 if String(d.properties.Proofread_file) != "" {
807 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700808 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700809 }
810
811 if String(d.properties.Todo_file) != "" {
812 // tricky part:
813 // we should not compute full path for todo_file through PathForModuleOut().
814 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700815 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
816 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700817 }
818
819 if String(d.properties.Resourcesdir) != "" {
820 // TODO: should we add files under resourcesDir to the implicits? It seems that
821 // resourcesDir is one sub dir of htmlDir
822 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700823 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700824 }
825
826 if String(d.properties.Resourcesoutdir) != "" {
827 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700828 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700829 }
Nan Zhanga40da042018-08-01 12:48:00 -0700830}
831
Colin Crossab054432019-07-15 16:13:59 -0700832func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200833 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
834 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700835 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700836
Nan Zhanga40da042018-08-01 12:48:00 -0700837 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700838 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700839 d.apiFilePath = d.apiFile
840 }
841
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200842 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
843 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700844 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700845 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700846 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700847 }
848
Nan Zhanga40da042018-08-01 12:48:00 -0700849 if String(d.properties.Removed_dex_api_filename) != "" {
850 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700851 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700852 }
853
Nan Zhanga40da042018-08-01 12:48:00 -0700854 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700855 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700856 }
857
858 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700859 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700860 }
Nan Zhanga40da042018-08-01 12:48:00 -0700861}
862
Colin Crossab054432019-07-15 16:13:59 -0700863func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700864 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700865 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
866 rule.Command().Text("cp").
867 Input(staticDocIndexRedirect).
868 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700869 }
870
871 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700872 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
873 rule.Command().Text("cp").
874 Input(staticDocProperties).
875 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700876 }
Nan Zhanga40da042018-08-01 12:48:00 -0700877}
878
Colin Crossab054432019-07-15 16:13:59 -0700879func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700880 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700881
882 cmd := rule.Command().
883 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
884 Flag(config.JavacVmFlags).
885 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700886 FlagWithRspFileInputList("@", srcs).
887 FlagWithInput("@", srcJarList)
888
Colin Crossab054432019-07-15 16:13:59 -0700889 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
890 // based stubs generation.
891 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
892 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
893 // the correct package name base path.
894 if len(sourcepaths) > 0 {
895 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
896 } else {
897 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
898 }
899
900 cmd.FlagWithArg("-d ", outDir.String()).
901 Flag("-quiet")
902
903 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700904}
905
Colin Crossdaa4c672019-07-15 22:53:46 -0700906func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
907 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
908 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
909
910 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
911
912 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
913 cmd.Flag(flag).Implicits(deps)
914
915 cmd.FlagWithArg("--patch-module ", "java.base=.")
916
917 if len(classpath) > 0 {
918 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
919 }
920
921 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700922}
923
Colin Crossdaa4c672019-07-15 22:53:46 -0700924func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
925 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
926 sourcepaths android.Paths) *android.RuleBuilderCommand {
927
928 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
929
930 if len(bootclasspath) == 0 && ctx.Device() {
931 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
932 // ensure java does not fall back to the default bootclasspath.
933 cmd.FlagWithArg("-bootclasspath ", `""`)
934 } else if len(bootclasspath) > 0 {
935 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
936 }
937
938 if len(classpath) > 0 {
939 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
940 }
941
942 return cmd
943}
944
Colin Crossab054432019-07-15 16:13:59 -0700945func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
946 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700947
Colin Crossab054432019-07-15 16:13:59 -0700948 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
949 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
950
951 return rule.Command().
952 BuiltTool(ctx, "dokka").
953 Flag(config.JavacVmFlags).
954 Flag(srcJarDir.String()).
955 FlagWithInputList("-classpath ", dokkaClasspath, ":").
956 FlagWithArg("-format ", "dac").
957 FlagWithArg("-dacRoot ", "/reference/kotlin").
958 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700959}
960
961func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
962 deps := d.Javadoc.collectDeps(ctx)
963
Colin Crossdaa4c672019-07-15 22:53:46 -0700964 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
965 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
966
Nan Zhang1598a9e2018-09-04 17:14:32 -0700967 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
968 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
969 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
970 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
971
Colin Crossab054432019-07-15 16:13:59 -0700972 outDir := android.PathForModuleOut(ctx, "out")
973 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
974 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700975
Colin Crossab054432019-07-15 16:13:59 -0700976 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700977
Colin Crossab054432019-07-15 16:13:59 -0700978 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
979 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700980
Colin Crossab054432019-07-15 16:13:59 -0700981 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
982
983 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700984 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700985 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700986 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700987 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700988 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700989 }
990
Colin Crossab054432019-07-15 16:13:59 -0700991 d.stubsFlags(ctx, cmd, stubsDir)
992
993 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
994
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000995 if d.properties.Compat_config != nil {
996 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
997 cmd.FlagWithInput("-compatconfig ", compatConfig)
998 }
999
Colin Crossab054432019-07-15 16:13:59 -07001000 var desc string
1001 if Bool(d.properties.Dokka_enabled) {
1002 desc = "dokka"
1003 } else {
1004 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1005
1006 for _, o := range d.Javadoc.properties.Out {
1007 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1008 }
1009
1010 d.postDoclavaCmds(ctx, rule)
1011 desc = "doclava"
1012 }
1013
1014 rule.Command().
1015 BuiltTool(ctx, "soong_zip").
1016 Flag("-write_if_changed").
1017 Flag("-d").
1018 FlagWithOutput("-o ", d.docZip).
1019 FlagWithArg("-C ", outDir.String()).
1020 FlagWithArg("-D ", outDir.String())
1021
1022 rule.Command().
1023 BuiltTool(ctx, "soong_zip").
1024 Flag("-write_if_changed").
1025 Flag("-jar").
1026 FlagWithOutput("-o ", d.stubsSrcJar).
1027 FlagWithArg("-C ", stubsDir.String()).
1028 FlagWithArg("-D ", stubsDir.String())
1029
1030 rule.Restat()
1031
1032 zipSyncCleanupCmd(rule, srcJarDir)
1033
1034 rule.Build(pctx, ctx, "javadoc", desc)
1035
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001036 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001037 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001038
1039 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1040 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001041
1042 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001043
1044 rule := android.NewRuleBuilder()
1045
1046 rule.Command().Text("( true")
1047
1048 rule.Command().
1049 BuiltTool(ctx, "apicheck").
1050 Flag("-JXmx1024m").
1051 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1052 OptionalFlag(d.properties.Check_api.Current.Args).
1053 Input(apiFile).
1054 Input(d.apiFile).
1055 Input(removedApiFile).
1056 Input(d.removedApiFile)
1057
1058 msg := fmt.Sprintf(`\n******************************\n`+
1059 `You have tried to change the API from what has been previously approved.\n\n`+
1060 `To make these errors go away, you have two choices:\n`+
1061 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1062 ` errors above.\n\n`+
1063 ` 2. You can update current.txt by executing the following command:\n`+
1064 ` make %s-update-current-api\n\n`+
1065 ` To submit the revised current.txt to the main Android repository,\n`+
1066 ` you will need approval.\n`+
1067 `******************************\n`, ctx.ModuleName())
1068
1069 rule.Command().
1070 Text("touch").Output(d.checkCurrentApiTimestamp).
1071 Text(") || (").
1072 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1073 Text("; exit 38").
1074 Text(")")
1075
1076 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001077
1078 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001079
1080 // update API rule
1081 rule = android.NewRuleBuilder()
1082
1083 rule.Command().Text("( true")
1084
1085 rule.Command().
1086 Text("cp").Flag("-f").
1087 Input(d.apiFile).Flag(apiFile.String())
1088
1089 rule.Command().
1090 Text("cp").Flag("-f").
1091 Input(d.removedApiFile).Flag(removedApiFile.String())
1092
1093 msg = "failed to update public API"
1094
1095 rule.Command().
1096 Text("touch").Output(d.updateCurrentApiTimestamp).
1097 Text(") || (").
1098 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1099 Text("; exit 38").
1100 Text(")")
1101
1102 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001103 }
1104
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001105 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001106 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001107
1108 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1109 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001110
1111 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001112
1113 rule := android.NewRuleBuilder()
1114
1115 rule.Command().
1116 Text("(").
1117 BuiltTool(ctx, "apicheck").
1118 Flag("-JXmx1024m").
1119 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1120 OptionalFlag(d.properties.Check_api.Last_released.Args).
1121 Input(apiFile).
1122 Input(d.apiFile).
1123 Input(removedApiFile).
1124 Input(d.removedApiFile)
1125
1126 msg := `\n******************************\n` +
1127 `You have tried to change the API from what has been previously released in\n` +
1128 `an SDK. Please fix the errors listed above.\n` +
1129 `******************************\n`
1130
1131 rule.Command().
1132 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1133 Text(") || (").
1134 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1135 Text("; exit 38").
1136 Text(")")
1137
1138 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001139 }
1140}
1141
1142//
1143// Droidstubs
1144//
1145type Droidstubs struct {
1146 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001147 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001148
Pete Gillin581d6082018-10-22 15:55:04 +01001149 properties DroidstubsProperties
1150 apiFile android.WritablePath
1151 apiXmlFile android.WritablePath
1152 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001153 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001154 removedApiFile android.WritablePath
1155 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001156 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001157
1158 checkCurrentApiTimestamp android.WritablePath
1159 updateCurrentApiTimestamp android.WritablePath
1160 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001161 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001162 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001163
Pete Gillin581d6082018-10-22 15:55:04 +01001164 checkNullabilityWarningsTimestamp android.WritablePath
1165
Nan Zhang1598a9e2018-09-04 17:14:32 -07001166 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001167 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001168
1169 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001170
1171 jdiffDocZip android.WritablePath
1172 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001173
1174 metadataZip android.WritablePath
1175 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001176}
1177
Colin Crossa3002fc2019-07-08 16:48:04 -07001178// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1179// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1180// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001181func DroidstubsFactory() android.Module {
1182 module := &Droidstubs{}
1183
1184 module.AddProperties(&module.properties,
1185 &module.Javadoc.properties)
1186
1187 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001188 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001189 return module
1190}
1191
Colin Crossa3002fc2019-07-08 16:48:04 -07001192// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1193// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1194// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1195// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001196func DroidstubsHostFactory() android.Module {
1197 module := &Droidstubs{}
1198
1199 module.AddProperties(&module.properties,
1200 &module.Javadoc.properties)
1201
1202 InitDroiddocModule(module, android.HostSupported)
1203 return module
1204}
1205
1206func (d *Droidstubs) ApiFilePath() android.Path {
1207 return d.apiFilePath
1208}
1209
Paul Duffin75dcc802020-04-09 01:08:11 +01001210func (d *Droidstubs) RemovedApiFilePath() android.Path {
1211 return d.removedApiFile
1212}
1213
Paul Duffinf488ef22020-04-09 00:10:17 +01001214func (d *Droidstubs) StubsSrcJar() android.Path {
1215 return d.stubsSrcJar
1216}
1217
Nan Zhang1598a9e2018-09-04 17:14:32 -07001218func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1219 d.Javadoc.addDeps(ctx)
1220
Paul Duffin8986cc92020-05-10 19:32:20 +01001221 // If requested clear any properties that provide information about the latest version
1222 // of an API and which reference non-existent modules.
Inseob Kim38449af2019-02-28 14:24:05 +09001223 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1224 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
Paul Duffin8986cc92020-05-10 19:32:20 +01001225
1226 // If the new_since references a module, e.g. :module-latest-api and the module
1227 // does not exist then clear it.
1228 newSinceSrc := d.properties.Check_api.Api_lint.New_since
1229 newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc))
1230 if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) {
1231 d.properties.Check_api.Api_lint.New_since = nil
1232 }
Inseob Kim38449af2019-02-28 14:24:05 +09001233 }
1234
Nan Zhang1598a9e2018-09-04 17:14:32 -07001235 if len(d.properties.Merge_annotations_dirs) != 0 {
1236 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1237 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1238 }
1239 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001240
Pete Gillin77167902018-09-19 18:16:26 +01001241 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1242 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1243 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1244 }
1245 }
1246
Nan Zhang9c69a122018-08-22 10:22:08 -07001247 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1248 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1249 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1250 }
1251 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001252}
1253
Paul Duffin455b0bf2020-04-08 18:18:03 +01001254func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001255 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1256 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001257 String(d.properties.Api_filename) != "" {
1258 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001259 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001260 d.apiFilePath = d.apiFile
1261 }
1262
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001263 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1264 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001265 String(d.properties.Removed_api_filename) != "" {
1266 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001267 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001268 }
1269
Nan Zhang1598a9e2018-09-04 17:14:32 -07001270 if String(d.properties.Removed_dex_api_filename) != "" {
1271 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001272 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001273 }
1274
Nan Zhang9c69a122018-08-22 10:22:08 -07001275 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001276 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1277 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001278 }
1279
Paul Duffin455b0bf2020-04-08 18:18:03 +01001280 if stubsDir.Valid() {
1281 if Bool(d.properties.Create_doc_stubs) {
1282 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1283 } else {
1284 cmd.FlagWithArg("--stubs ", stubsDir.String())
1285 cmd.Flag("--exclude-documentation-from-stubs")
1286 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001287 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001288}
1289
Colin Cross33961b52019-07-11 11:01:22 -07001290func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001291 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001292 cmd.Flag("--include-annotations")
1293
Pete Gillinc382a562018-11-14 18:45:46 +00001294 validatingNullability :=
1295 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1296 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001297
Pete Gillina262c052018-09-14 14:25:48 +01001298 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001299 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001300 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001301 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001302 }
Colin Cross33961b52019-07-11 11:01:22 -07001303
Pete Gillinc382a562018-11-14 18:45:46 +00001304 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001305 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001306 }
Colin Cross33961b52019-07-11 11:01:22 -07001307
Pete Gillina262c052018-09-14 14:25:48 +01001308 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001309 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001310 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001311 }
Nan Zhanga40da042018-08-01 12:48:00 -07001312
1313 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001314 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001315
Nan Zhang1598a9e2018-09-04 17:14:32 -07001316 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001317 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001318 "has to be non-empty if annotations was enabled!")
1319 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001320
Colin Cross33961b52019-07-11 11:01:22 -07001321 d.mergeAnnoDirFlags(ctx, cmd)
1322
1323 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1324 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1325 FlagWithArg("--hide ", "SuperfluousPrefix").
1326 FlagWithArg("--hide ", "AnnotationExtraction")
1327 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001328}
1329
Colin Cross33961b52019-07-11 11:01:22 -07001330func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1331 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1332 if t, ok := m.(*ExportedDroiddocDir); ok {
1333 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1334 } else {
1335 ctx.PropertyErrorf("merge_annotations_dirs",
1336 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1337 }
1338 })
1339}
1340
1341func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001342 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1343 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001344 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001345 } else {
1346 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1347 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1348 }
1349 })
Nan Zhanga40da042018-08-01 12:48:00 -07001350}
1351
Colin Cross33961b52019-07-11 11:01:22 -07001352func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001353 if Bool(d.properties.Api_levels_annotations_enabled) {
1354 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001355
1356 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1357 ctx.PropertyErrorf("api_levels_annotations_dirs",
1358 "has to be non-empty if api levels annotations was enabled!")
1359 }
1360
Colin Cross33961b52019-07-11 11:01:22 -07001361 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1362 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1363 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1364 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001365
1366 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1367 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001368 for _, dep := range t.deps {
1369 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001370 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001371 }
1372 }
Colin Cross33961b52019-07-11 11:01:22 -07001373 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001374 } else {
1375 ctx.PropertyErrorf("api_levels_annotations_dirs",
1376 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1377 }
1378 })
1379
1380 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001381}
1382
Colin Cross33961b52019-07-11 11:01:22 -07001383func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001384 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1385 if d.apiFile.String() == "" {
1386 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1387 }
1388
1389 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001390 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001391
1392 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1393 ctx.PropertyErrorf("check_api.last_released.api_file",
1394 "has to be non-empty if jdiff was enabled!")
1395 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001396
Colin Cross33961b52019-07-11 11:01:22 -07001397 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001398 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001399 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1400 }
1401}
Nan Zhang71bbe632018-09-17 14:32:21 -07001402
Colin Cross1e743852019-10-28 11:37:20 -07001403func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001404 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001405 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1406 rule.HighMem()
Colin Cross33961b52019-07-11 11:01:22 -07001407 cmd := rule.Command().BuiltTool(ctx, "metalava").
1408 Flag(config.JavacVmFlags).
1409 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001410 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001411 FlagWithRspFileInputList("@", srcs).
1412 FlagWithInput("@", srcJarList)
1413
1414 if len(bootclasspath) > 0 {
1415 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001416 }
1417
Colin Cross33961b52019-07-11 11:01:22 -07001418 if len(classpath) > 0 {
1419 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1420 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001421
Colin Cross33961b52019-07-11 11:01:22 -07001422 if len(sourcepaths) > 0 {
1423 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1424 } else {
1425 cmd.FlagWithArg("-sourcepath ", `""`)
1426 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001427
Colin Cross33961b52019-07-11 11:01:22 -07001428 cmd.Flag("--no-banner").
1429 Flag("--color").
1430 Flag("--quiet").
1431 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001432
Colin Cross33961b52019-07-11 11:01:22 -07001433 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001434}
1435
Nan Zhang1598a9e2018-09-04 17:14:32 -07001436func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001437 deps := d.Javadoc.collectDeps(ctx)
1438
1439 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001440
Colin Cross33961b52019-07-11 11:01:22 -07001441 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001442
Colin Cross33961b52019-07-11 11:01:22 -07001443 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001444
Colin Cross33961b52019-07-11 11:01:22 -07001445 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001446
Paul Duffin455b0bf2020-04-08 18:18:03 +01001447 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1448 var stubsDir android.OptionalPath
1449 if generateStubs {
1450 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1451 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1452 rule.Command().Text("rm -rf").Text(stubsDir.String())
1453 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1454 }
Nan Zhanga40da042018-08-01 12:48:00 -07001455
Colin Cross33961b52019-07-11 11:01:22 -07001456 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1457
1458 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1459 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1460
1461 d.stubsFlags(ctx, cmd, stubsDir)
1462
1463 d.annotationsFlags(ctx, cmd)
1464 d.inclusionAnnotationsFlags(ctx, cmd)
1465 d.apiLevelsAnnotationsFlags(ctx, cmd)
1466 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001467
Nan Zhang1598a9e2018-09-04 17:14:32 -07001468 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1469 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1470 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1471 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1472 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001473 }
Colin Cross33961b52019-07-11 11:01:22 -07001474
1475 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1476 for _, o := range d.Javadoc.properties.Out {
1477 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1478 }
1479
Makoto Onukib850a9d2020-04-27 17:22:16 -07001480 // Add options for the other optional tasks: API-lint and check-released.
1481 // We generate separate timestamp files for them.
1482
1483 doApiLint := false
1484 doCheckReleased := false
1485
1486 // Add API lint options.
1487
1488 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1489 doApiLint = true
1490
1491 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1492 if newSince.Valid() {
1493 cmd.FlagWithInput("--api-lint ", newSince.Path())
1494 } else {
1495 cmd.Flag("--api-lint")
1496 }
1497 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1498 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1499
1500 // TODO(b/154317059): Clean up this whitelist by baselining and/or checking in last-released.
1501 if d.Name() != "android.car-system-stubs-docs" &&
1502 d.Name() != "android.car-stubs-docs" &&
1503 d.Name() != "system-api-stubs-docs" &&
1504 d.Name() != "test-api-stubs-docs" {
1505 cmd.Flag("--lints-as-errors")
1506 cmd.Flag("--warnings-as-errors") // Most lints are actually warnings.
1507 }
1508
1509 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1510 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1511 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1512
1513 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1514 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1515 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1516 // which is why we have '"$PWD"$' in it.
1517 //
1518 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1519 // message and metalava's one?
1520 msg := `$'` + // Enclose with $' ... '
1521 `************************************************************\n` +
1522 `Your API changes are triggering API Lint warnings or errors.\n` +
1523 `To make these errors go away, fix the code according to the\n` +
1524 `error and/or warning messages above.\n` +
1525 `\n` +
1526 `If it is not possible to do so, there are workarounds:\n` +
1527 `\n` +
1528 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1529
1530 if baselineFile.Valid() {
1531 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1532 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1533
1534 msg += fmt.Sprintf(``+
1535 `2. You can update the baseline by executing the following\n`+
1536 ` command:\n`+
Anton Hansson18a28952020-05-11 15:38:31 +01001537 ` cp \\\n`+
1538 ` "'"$PWD"$'/%s" \\\n`+
1539 ` "'"$PWD"$'/%s"\n`+
Makoto Onukib850a9d2020-04-27 17:22:16 -07001540 ` To submit the revised baseline.txt to the main Android\n`+
1541 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1542 } else {
1543 msg += fmt.Sprintf(``+
1544 `2. You can add a baseline file of existing lint failures\n`+
1545 ` to the build rule of %s.\n`, d.Name())
1546 }
1547 // Note the message ends with a ' (single quote), to close the $' ... ' .
1548 msg += `************************************************************\n'`
1549
1550 cmd.FlagWithArg("--error-message:api-lint ", msg)
1551 }
1552
1553 // Add "check released" options. (Detect incompatible API changes from the last public release)
1554
1555 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
1556 !ctx.Config().IsPdkBuild() {
1557 doCheckReleased = true
1558
1559 if len(d.Javadoc.properties.Out) > 0 {
1560 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1561 }
1562
1563 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1564 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1565 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1566 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1567
1568 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1569
1570 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1571 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1572
1573 if baselineFile.Valid() {
1574 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1575 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1576 }
1577
1578 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1579 msg := `$'\n******************************\n` +
1580 `You have tried to change the API from what has been previously released in\n` +
1581 `an SDK. Please fix the errors listed above.\n` +
1582 `******************************\n'`
1583
1584 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1585 }
1586
Paul Duffin455b0bf2020-04-08 18:18:03 +01001587 if generateStubs {
1588 rule.Command().
1589 BuiltTool(ctx, "soong_zip").
1590 Flag("-write_if_changed").
1591 Flag("-jar").
1592 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1593 FlagWithArg("-C ", stubsDir.String()).
1594 FlagWithArg("-D ", stubsDir.String())
1595 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001596
1597 if Bool(d.properties.Write_sdk_values) {
1598 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1599 rule.Command().
1600 BuiltTool(ctx, "soong_zip").
1601 Flag("-write_if_changed").
1602 Flag("-d").
1603 FlagWithOutput("-o ", d.metadataZip).
1604 FlagWithArg("-C ", d.metadataDir.String()).
1605 FlagWithArg("-D ", d.metadataDir.String())
1606 }
1607
Makoto Onukib850a9d2020-04-27 17:22:16 -07001608 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1609 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1610 if doApiLint {
1611 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1612 }
1613 if doCheckReleased {
1614 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1615 }
1616
Colin Cross33961b52019-07-11 11:01:22 -07001617 rule.Restat()
1618
1619 zipSyncCleanupCmd(rule, srcJarDir)
1620
Makoto Onukib850a9d2020-04-27 17:22:16 -07001621 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001622
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001623 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001624 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001625
1626 if len(d.Javadoc.properties.Out) > 0 {
1627 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1628 }
1629
1630 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1631 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001632 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001633
1634 if baselineFile.Valid() {
Makoto Onukib850a9d2020-04-27 17:22:16 -07001635 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001636 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001637
Nan Zhang2760dfc2018-08-24 17:32:54 +00001638 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001639
Colin Cross33961b52019-07-11 11:01:22 -07001640 rule := android.NewRuleBuilder()
1641
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001642 // Diff command line.
Makoto Onukib850a9d2020-04-27 17:22:16 -07001643 // -F matches the closest "opening" line, such as "package android {"
1644 // and " public class Intent {".
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001645 diff := `diff -u -F '{ *$'`
1646
Colin Cross33961b52019-07-11 11:01:22 -07001647 rule.Command().Text("( true")
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001648 rule.Command().
1649 Text(diff).
1650 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001651
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001652 rule.Command().
1653 Text(diff).
1654 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001655
1656 msg := fmt.Sprintf(`\n******************************\n`+
1657 `You have tried to change the API from what has been previously approved.\n\n`+
1658 `To make these errors go away, you have two choices:\n`+
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001659 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1660 ` to the new methods, etc. shown in the above diff.\n\n`+
1661 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001662 ` make %s-update-current-api\n\n`+
1663 ` To submit the revised current.txt to the main Android repository,\n`+
1664 ` you will need approval.\n`+
1665 `******************************\n`, ctx.ModuleName())
1666
1667 rule.Command().
1668 Text("touch").Output(d.checkCurrentApiTimestamp).
1669 Text(") || (").
1670 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1671 Text("; exit 38").
1672 Text(")")
1673
Makoto Onukib52c8ea2020-04-16 17:02:40 -07001674 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001675
1676 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001677
1678 // update API rule
1679 rule = android.NewRuleBuilder()
1680
1681 rule.Command().Text("( true")
1682
1683 rule.Command().
1684 Text("cp").Flag("-f").
1685 Input(d.apiFile).Flag(apiFile.String())
1686
1687 rule.Command().
1688 Text("cp").Flag("-f").
1689 Input(d.removedApiFile).Flag(removedApiFile.String())
1690
1691 msg = "failed to update public API"
1692
1693 rule.Command().
1694 Text("touch").Output(d.updateCurrentApiTimestamp).
1695 Text(") || (").
1696 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1697 Text("; exit 38").
1698 Text(")")
1699
1700 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001701 }
Nan Zhanga40da042018-08-01 12:48:00 -07001702
Pete Gillin581d6082018-10-22 15:55:04 +01001703 if String(d.properties.Check_nullability_warnings) != "" {
1704 if d.nullabilityWarningsFile == nil {
1705 ctx.PropertyErrorf("check_nullability_warnings",
1706 "Cannot specify check_nullability_warnings unless validating nullability")
1707 }
Colin Cross33961b52019-07-11 11:01:22 -07001708
1709 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1710
Pete Gillin581d6082018-10-22 15:55:04 +01001711 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001712
Pete Gillin581d6082018-10-22 15:55:04 +01001713 msg := fmt.Sprintf(`\n******************************\n`+
1714 `The warnings encountered during nullability annotation validation did\n`+
1715 `not match the checked in file of expected warnings. The diffs are shown\n`+
1716 `above. You have two options:\n`+
1717 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1718 ` 2. Update the file of expected warnings by running:\n`+
1719 ` cp %s %s\n`+
1720 ` and submitting the updated file as part of your change.`,
1721 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001722
1723 rule := android.NewRuleBuilder()
1724
1725 rule.Command().
1726 Text("(").
1727 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1728 Text("&&").
1729 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1730 Text(") || (").
1731 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1732 Text("; exit 38").
1733 Text(")")
1734
1735 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001736 }
1737
Nan Zhang71bbe632018-09-17 14:32:21 -07001738 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001739 if len(d.Javadoc.properties.Out) > 0 {
1740 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1741 }
1742
1743 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1744 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1745 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1746
1747 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001748
Nan Zhang86b06202018-09-21 17:09:21 -07001749 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1750 // since there's cron job downstream that fetch this .zip file periodically.
1751 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001752 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1753 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1754
Nan Zhang71bbe632018-09-17 14:32:21 -07001755 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001756
Colin Cross33961b52019-07-11 11:01:22 -07001757 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1758 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001759
Colin Cross33961b52019-07-11 11:01:22 -07001760 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1761
Colin Crossdaa4c672019-07-15 22:53:46 -07001762 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001763 deps.bootClasspath, deps.classpath, d.sourcepaths)
1764
1765 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001766 Flag("-XDignore.symbol.file").
1767 FlagWithArg("-doclet ", "jdiff.JDiff").
1768 FlagWithInput("-docletpath ", jdiff).
1769 Flag("-quiet").
1770 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1771 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1772 Implicit(d.apiXmlFile).
1773 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1774 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1775 Implicit(d.lastReleasedApiXmlFile)
1776
Colin Cross33961b52019-07-11 11:01:22 -07001777 rule.Command().
1778 BuiltTool(ctx, "soong_zip").
1779 Flag("-write_if_changed").
1780 Flag("-d").
1781 FlagWithOutput("-o ", d.jdiffDocZip).
1782 FlagWithArg("-C ", outDir.String()).
1783 FlagWithArg("-D ", outDir.String())
1784
1785 rule.Command().
1786 BuiltTool(ctx, "soong_zip").
1787 Flag("-write_if_changed").
1788 Flag("-jar").
1789 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1790 FlagWithArg("-C ", stubsDir.String()).
1791 FlagWithArg("-D ", stubsDir.String())
1792
1793 rule.Restat()
1794
1795 zipSyncCleanupCmd(rule, srcJarDir)
1796
1797 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001798 }
Nan Zhang581fd212018-01-10 16:06:12 -08001799}
Dan Willemsencc090972018-02-26 14:33:31 -08001800
Nan Zhanga40da042018-08-01 12:48:00 -07001801//
Nan Zhangf4936b02018-08-01 15:00:28 -07001802// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001803//
Dan Willemsencc090972018-02-26 14:33:31 -08001804var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001805var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001806var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001807var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001808
Nan Zhangf4936b02018-08-01 15:00:28 -07001809type ExportedDroiddocDirProperties struct {
1810 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001811 Path *string
1812}
1813
Nan Zhangf4936b02018-08-01 15:00:28 -07001814type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001815 android.ModuleBase
1816
Nan Zhangf4936b02018-08-01 15:00:28 -07001817 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001818
1819 deps android.Paths
1820 dir android.Path
1821}
1822
Colin Crossa3002fc2019-07-08 16:48:04 -07001823// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001824func ExportedDroiddocDirFactory() android.Module {
1825 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001826 module.AddProperties(&module.properties)
1827 android.InitAndroidModule(module)
1828 return module
1829}
1830
Nan Zhangf4936b02018-08-01 15:00:28 -07001831func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001832
Nan Zhangf4936b02018-08-01 15:00:28 -07001833func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001834 path := String(d.properties.Path)
1835 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001836 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001837}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001838
1839//
1840// Defaults
1841//
1842type DocDefaults struct {
1843 android.ModuleBase
1844 android.DefaultsModuleBase
1845}
1846
Nan Zhangb2b33de2018-02-23 11:18:47 -08001847func DocDefaultsFactory() android.Module {
1848 module := &DocDefaults{}
1849
1850 module.AddProperties(
1851 &JavadocProperties{},
1852 &DroiddocProperties{},
1853 )
1854
1855 android.InitDefaultsModule(module)
1856
1857 return module
1858}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001859
1860func StubsDefaultsFactory() android.Module {
1861 module := &DocDefaults{}
1862
1863 module.AddProperties(
1864 &JavadocProperties{},
1865 &DroidstubsProperties{},
1866 )
1867
1868 android.InitDefaultsModule(module)
1869
1870 return module
1871}
Colin Cross33961b52019-07-11 11:01:22 -07001872
1873func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1874 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1875
1876 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1877 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1878 srcJarList := srcJarDir.Join(ctx, "list")
1879
1880 rule.Temporary(srcJarList)
1881
1882 rule.Command().BuiltTool(ctx, "zipsync").
1883 FlagWithArg("-d ", srcJarDir.String()).
1884 FlagWithOutput("-l ", srcJarList).
1885 FlagWithArg("-f ", `"*.java"`).
1886 Inputs(srcJars)
1887
1888 return srcJarList
1889}
1890
1891func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1892 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1893}
Paul Duffin91547182019-11-12 19:39:36 +00001894
1895var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1896
1897type PrebuiltStubsSourcesProperties struct {
1898 Srcs []string `android:"path"`
1899}
1900
1901type PrebuiltStubsSources struct {
1902 android.ModuleBase
1903 android.DefaultableModuleBase
1904 prebuilt android.Prebuilt
1905 android.SdkBase
1906
1907 properties PrebuiltStubsSourcesProperties
1908
Paul Duffin9b478b02019-12-10 13:41:51 +00001909 // The source directories containing stubs source files.
1910 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001911 stubsSrcJar android.ModuleOutPath
1912}
1913
Paul Duffin9b478b02019-12-10 13:41:51 +00001914func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1915 switch tag {
1916 case "":
1917 return android.Paths{p.stubsSrcJar}, nil
1918 default:
1919 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1920 }
1921}
1922
Paul Duffindce3fe72020-05-20 16:18:00 +01001923func (d *PrebuiltStubsSources) StubsSrcJar() android.Path {
1924 return d.stubsSrcJar
1925}
1926
Paul Duffin91547182019-11-12 19:39:36 +00001927func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001928 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1929
1930 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1931
1932 rule := android.NewRuleBuilder()
1933 command := rule.Command().
1934 BuiltTool(ctx, "soong_zip").
1935 Flag("-write_if_changed").
1936 Flag("-jar").
1937 FlagWithOutput("-o ", p.stubsSrcJar)
1938
1939 for _, d := range p.srcDirs {
1940 dir := d.String()
1941 command.
1942 FlagWithArg("-C ", dir).
1943 FlagWithInput("-D ", d)
1944 }
1945
1946 rule.Restat()
1947
1948 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001949}
1950
1951func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1952 return &p.prebuilt
1953}
1954
1955func (p *PrebuiltStubsSources) Name() string {
1956 return p.prebuilt.Name(p.ModuleBase.Name())
1957}
1958
Paul Duffin91547182019-11-12 19:39:36 +00001959// prebuilt_stubs_sources imports a set of java source files as if they were
1960// generated by droidstubs.
1961//
1962// By default, a prebuilt_stubs_sources has a single variant that expects a
1963// set of `.java` files generated by droidstubs.
1964//
1965// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1966// for host modules.
1967//
1968// Intended only for use by sdk snapshots.
1969func PrebuiltStubsSourcesFactory() android.Module {
1970 module := &PrebuiltStubsSources{}
1971
1972 module.AddProperties(&module.properties)
1973
1974 android.InitPrebuiltModule(module, &module.properties.Srcs)
1975 android.InitSdkAwareModule(module)
1976 InitDroiddocModule(module, android.HostAndDeviceSupported)
1977 return module
1978}
1979
Paul Duffin13879572019-11-28 14:31:38 +00001980type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001981 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001982}
1983
1984func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1985 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1986}
1987
1988func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1989 _, ok := module.(*Droidstubs)
1990 return ok
1991}
1992
Paul Duffin93520ed2020-03-20 13:35:40 +00001993func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
1994 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
1995}
1996
1997func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
1998 return &droidStubsInfoProperties{}
1999}
2000
2001type droidStubsInfoProperties struct {
2002 android.SdkMemberPropertiesBase
2003
2004 StubsSrcJar android.Path
2005}
2006
2007func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2008 droidstubs := variant.(*Droidstubs)
2009 p.StubsSrcJar = droidstubs.stubsSrcJar
2010}
2011
2012func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
2013 if p.StubsSrcJar != nil {
2014 builder := ctx.SnapshotBuilder()
2015
2016 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2017
2018 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2019
2020 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002021 }
Paul Duffin91547182019-11-12 19:39:36 +00002022}