blob: 8ab656f7e8fa8c7fda12a4b2087e837deda5c749 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Ramy Medhat427683c2020-04-30 03:08:37 -040027 "android/soong/remoteexec"
Nan Zhang581fd212018-01-10 16:06:12 -080028)
29
30func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000031 RegisterDocsBuildComponents(android.InitRegistrationContext)
32 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000033
34 // Register sdk member type.
35 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
36 SdkMemberTypeBase: android.SdkMemberTypeBase{
37 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000038 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
39 // the APEX.
40 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000041 },
42 })
Nan Zhang581fd212018-01-10 16:06:12 -080043}
44
Paul Duffin884363e2019-12-19 10:21:09 +000045func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
47
48 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
49 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
50 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
51 ctx.RegisterModuleType("javadoc", JavadocFactory)
52 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
53}
54
55func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
56 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
57
58 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
59 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
60
61 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
62}
63
Colin Crossa1ce2a02018-06-20 15:19:39 -070064var (
65 srcsLibTag = dependencyTag{name: "sources from javalib"}
66)
67
Nan Zhang581fd212018-01-10 16:06:12 -080068type JavadocProperties struct {
69 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
70 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080071 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080072
73 // list of directories rooted at the Android.bp file that will
74 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080075 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080076
77 // list of source files that should not be used to build the Java module.
78 // This is most useful in the arch/multilib variants to remove non-common files
79 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080080 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080081
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090082 // list of package names that should actually be used. If this property is left unspecified,
83 // all the sources from the srcs property is used.
84 Filter_packages []string
85
Nan Zhangb2b33de2018-02-23 11:18:47 -080086 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080087 Libs []string `android:"arch_variant"`
88
89 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080090 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080091
Paul Duffine25c6442019-10-11 13:50:28 +010092 // if not blank, set to the version of the sdk to compile against.
93 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080094 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090095
Paul Duffine25c6442019-10-11 13:50:28 +010096 // When targeting 1.9 and above, override the modules to use with --system,
97 // otherwise provides defaults libraries to add to the bootclasspath.
98 // Defaults to "none"
99 System_modules *string
100
Jiyong Park1e440682018-05-23 18:42:04 +0900101 Aidl struct {
102 // Top level directories to pass to aidl tool
103 Include_dirs []string
104
105 // Directories rooted at the Android.bp file to pass to aidl tool
106 Local_include_dirs []string
107 }
Nan Zhang357466b2018-04-17 17:38:36 -0700108
109 // If not blank, set the java version passed to javadoc as -source
110 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700111
112 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800113 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700114
115 // user customized droiddoc args.
116 // Available variables for substitution:
117 //
118 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700119 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700120 Args *string
121
122 // names of the output files used in args that will be generated
123 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800124}
125
Nan Zhang61819ce2018-05-04 18:49:16 -0700126type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900127 // path to the API txt file that the new API extracted from source code is checked
128 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800129 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700130
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900131 // path to the API txt file that the new @removed API extractd from source code is
132 // checked against. The path can be local to the module or from other module (via
133 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800134 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700135
Adrian Roos14f75a92019-08-12 17:54:09 +0200136 // If not blank, path to the baseline txt file for approved API check violations.
137 Baseline_file *string `android:"path"`
138
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900139 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700140 Args *string
141}
142
Nan Zhang581fd212018-01-10 16:06:12 -0800143type DroiddocProperties struct {
144 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800145 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800146
Nan Zhanga40da042018-08-01 12:48:00 -0700147 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800148 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800149
150 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800151 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800152
153 // proofread file contains all of the text content of the javadocs concatenated into one file,
154 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700155 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800156
157 // a todo file lists the program elements that are missing documentation.
158 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800159 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800160
161 // directory under current module source that provide additional resources (images).
162 Resourcesdir *string
163
164 // resources output directory under out/soong/.intermediates.
165 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800166
Nan Zhange2ba5d42018-07-11 15:16:55 -0700167 // if set to true, collect the values used by the Dev tools and
168 // write them in files packaged with the SDK. Defaults to false.
169 Write_sdk_values *bool
170
171 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800172 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700173
174 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800175 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700176
Nan Zhang581fd212018-01-10 16:06:12 -0800177 // a list of files under current module source dir which contains known tags in Java sources.
178 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800179 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700180
Nan Zhang28c68b92018-03-13 16:17:01 -0700181 // the generated public API filename by Doclava.
182 Api_filename *string
183
Nan Zhang28c68b92018-03-13 16:17:01 -0700184 // the generated removed API filename by Doclava.
185 Removed_api_filename *string
186
David Brazdilaac0c3c2018-04-24 16:23:29 +0100187 // the generated removed Dex API filename by Doclava.
188 Removed_dex_api_filename *string
189
Nan Zhang853f4202018-04-12 16:55:56 -0700190 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
191 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700192
193 Check_api struct {
194 Last_released ApiToCheck
195
196 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900197
198 // do not perform API check against Last_released, in the case that both two specified API
199 // files by Last_released are modules which don't exist.
200 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700201 }
Nan Zhang79614d12018-04-19 18:03:39 -0700202
Nan Zhang1598a9e2018-09-04 17:14:32 -0700203 // if set to true, generate docs through Dokka instead of Doclava.
204 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000205
206 // Compat config XML. Generates compat change documentation if set.
207 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700208}
209
210type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700211 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700212 Api_filename *string
213
Nan Zhang199645c2018-09-19 12:40:06 -0700214 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700215 Removed_api_filename *string
216
Nan Zhang199645c2018-09-19 12:40:06 -0700217 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700218 Removed_dex_api_filename *string
219
Nan Zhang1598a9e2018-09-04 17:14:32 -0700220 Check_api struct {
221 Last_released ApiToCheck
222
223 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900224
Paul Duffin160fe412020-05-10 19:32:20 +0100225 // The java_sdk_library module generates references to modules (i.e. filegroups)
226 // from which information about the latest API version can be obtained. As those
227 // modules may not exist (e.g. because a previous version has not been released) it
228 // sets ignore_missing_latest_api=true on the droidstubs modules it creates so
229 // that droidstubs can ignore those references if the modules do not yet exist.
230 //
231 // If true then this will ignore module references for modules that do not exist
232 // in properties that supply the previous version of the API.
233 //
234 // There are two sets of those:
235 // * Api_file, Removed_api_file in check_api.last_released
236 // * New_since in check_api.api_lint.new_since
237 //
238 // The first two must be set as a pair, so either they should both exist or neither
239 // should exist - in which case when this property is true they are ignored. If one
240 // exists and the other does not then it is an error.
Inseob Kim38449af2019-02-28 14:24:05 +0900241 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200242
243 Api_lint struct {
244 Enabled *bool
245
246 // If set, performs api_lint on any new APIs not found in the given signature file
247 New_since *string `android:"path"`
248
249 // If not blank, path to the baseline txt file for approved API lint violations.
250 Baseline_file *string `android:"path"`
251 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700252 }
Nan Zhang79614d12018-04-19 18:03:39 -0700253
254 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800255 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700256
257 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700258 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700259
Pete Gillin77167902018-09-19 18:16:26 +0100260 // 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 -0700261 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700262
Pete Gillin77167902018-09-19 18:16:26 +0100263 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
264 Merge_inclusion_annotations_dirs []string
265
Pete Gillinc382a562018-11-14 18:45:46 +0000266 // a file containing a list of classes to do nullability validation for.
267 Validate_nullability_from_list *string
268
Pete Gillin581d6082018-10-22 15:55:04 +0100269 // a file containing expected warnings produced by validation of nullability annotations.
270 Check_nullability_warnings *string
271
Nan Zhang1598a9e2018-09-04 17:14:32 -0700272 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
273 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700274
Paul Duffin3ae29512020-04-08 18:18:03 +0100275 // if set to false then do not write out stubs. Defaults to true.
276 //
277 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
278 Generate_stubs *bool
279
Nan Zhang9c69a122018-08-22 10:22:08 -0700280 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
281 Api_levels_annotations_enabled *bool
282
283 // the dirs which Metalava extracts API levels annotations from.
284 Api_levels_annotations_dirs []string
285
286 // if set to true, collect the values used by the Dev tools and
287 // write them in files packaged with the SDK. Defaults to false.
288 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700289
290 // If set to true, .xml based public API file will be also generated, and
291 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
292 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800293}
294
Nan Zhanga40da042018-08-01 12:48:00 -0700295//
296// Common flags passed down to build rule
297//
298type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700299 bootClasspathArgs string
300 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700301 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700302 dokkaClasspathArgs string
303 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700304 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700305
Nan Zhanga40da042018-08-01 12:48:00 -0700306 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700307 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700308 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700309}
310
311func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
312 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
313 android.InitDefaultableModule(module)
314}
315
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200316func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
317 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
318 return false
319 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700320 return true
321 } else if String(apiToCheck.Api_file) != "" {
322 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
323 } else if String(apiToCheck.Removed_api_file) != "" {
324 panic("for " + apiVersionTag + " api_file has to be non-empty!")
325 }
326
327 return false
328}
329
Inseob Kim38449af2019-02-28 14:24:05 +0900330func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
331 api_file := String(apiToCheck.Api_file)
332 removed_api_file := String(apiToCheck.Removed_api_file)
333
334 api_module := android.SrcIsModule(api_file)
335 removed_api_module := android.SrcIsModule(removed_api_file)
336
337 if api_module == "" || removed_api_module == "" {
338 return
339 }
340
341 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
342 return
343 }
344
345 apiToCheck.Api_file = nil
346 apiToCheck.Removed_api_file = nil
347}
348
Paul Duffin3d1248c2020-04-09 00:10:17 +0100349// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700350type ApiFilePath interface {
351 ApiFilePath() android.Path
352}
353
Paul Duffin3d1248c2020-04-09 00:10:17 +0100354// Provider of information about API stubs, used by java_sdk_library.
355type ApiStubsProvider interface {
356 ApiFilePath
Paul Duffin1fd005d2020-04-09 01:08:11 +0100357 RemovedApiFilePath() android.Path
Paul Duffin3d1248c2020-04-09 00:10:17 +0100358 StubsSrcJar() android.Path
359}
360
Nan Zhanga40da042018-08-01 12:48:00 -0700361//
362// Javadoc
363//
Nan Zhang581fd212018-01-10 16:06:12 -0800364type Javadoc struct {
365 android.ModuleBase
366 android.DefaultableModuleBase
367
368 properties JavadocProperties
369
370 srcJars android.Paths
371 srcFiles android.Paths
372 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700373 argFiles android.Paths
374
375 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800376
Nan Zhangccff0f72018-03-08 17:26:16 -0800377 docZip android.WritablePath
378 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800379}
380
Colin Cross41955e82019-05-29 14:40:35 -0700381func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
382 switch tag {
383 case "":
384 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700385 case ".docs.zip":
386 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700387 default:
388 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
389 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800390}
391
Colin Crossa3002fc2019-07-08 16:48:04 -0700392// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800393func JavadocFactory() android.Module {
394 module := &Javadoc{}
395
396 module.AddProperties(&module.properties)
397
398 InitDroiddocModule(module, android.HostAndDeviceSupported)
399 return module
400}
401
Colin Crossa3002fc2019-07-08 16:48:04 -0700402// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800403func JavadocHostFactory() android.Module {
404 module := &Javadoc{}
405
406 module.AddProperties(&module.properties)
407
408 InitDroiddocModule(module, android.HostSupported)
409 return module
410}
411
Colin Cross41955e82019-05-29 14:40:35 -0700412var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800413
Jiyong Park6a927c42020-01-21 02:03:43 +0900414func (j *Javadoc) sdkVersion() sdkSpec {
415 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700416}
417
Paul Duffine25c6442019-10-11 13:50:28 +0100418func (j *Javadoc) systemModules() string {
419 return proptools.String(j.properties.System_modules)
420}
421
Jiyong Park6a927c42020-01-21 02:03:43 +0900422func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700423 return j.sdkVersion()
424}
425
Jiyong Park6a927c42020-01-21 02:03:43 +0900426func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700427 return j.sdkVersion()
428}
429
Nan Zhang581fd212018-01-10 16:06:12 -0800430func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
431 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100432 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700433 if sdkDep.useDefaultLibs {
434 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
435 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
436 if sdkDep.hasFrameworkLibs() {
437 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700438 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700439 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700440 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100441 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700442 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800443 }
444 }
445
Colin Cross42d48b72018-08-29 14:10:52 -0700446 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800447}
448
Nan Zhanga40da042018-08-01 12:48:00 -0700449func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
450 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900451
Colin Cross3047fa22019-04-18 10:56:44 -0700452 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900453
454 return flags
455}
456
457func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700458 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900459
460 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
461 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
462
463 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700464 var deps android.Paths
465
Jiyong Park1e440682018-05-23 18:42:04 +0900466 if aidlPreprocess.Valid() {
467 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700468 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900469 } else {
470 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
471 }
472
473 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
474 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
475 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
476 flags = append(flags, "-I"+src.String())
477 }
478
Colin Cross3047fa22019-04-18 10:56:44 -0700479 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900480}
481
Jiyong Parkd90d7412019-08-20 22:49:19 +0900482// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900483func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700484 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900485
486 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700487 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900488
Jiyong Park1112c4c2019-08-16 21:12:10 +0900489 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
490
Jiyong Park1e440682018-05-23 18:42:04 +0900491 for _, srcFile := range srcFiles {
492 switch srcFile.Ext() {
493 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700494 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900495 case ".logtags":
496 javaFile := genLogtags(ctx, srcFile)
497 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900498 default:
499 outSrcFiles = append(outSrcFiles, srcFile)
500 }
501 }
502
Colin Crossc0806172019-06-14 18:51:47 -0700503 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
504 if len(aidlSrcs) > 0 {
505 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
506 outSrcFiles = append(outSrcFiles, srcJarFiles...)
507 }
508
Jiyong Park1e440682018-05-23 18:42:04 +0900509 return outSrcFiles
510}
511
Nan Zhang581fd212018-01-10 16:06:12 -0800512func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
513 var deps deps
514
Colin Cross83bb3162018-06-25 15:48:06 -0700515 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800516 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700517 ctx.AddMissingDependencies(sdkDep.bootclasspath)
518 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800519 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700520 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000521 deps.aidlPreprocess = sdkDep.aidl
522 } else {
523 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800524 }
525
526 ctx.VisitDirectDeps(func(module android.Module) {
527 otherName := ctx.OtherModuleName(module)
528 tag := ctx.OtherModuleDependencyTag(module)
529
Colin Cross2d24c1b2018-05-23 10:59:18 -0700530 switch tag {
531 case bootClasspathTag:
532 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800533 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000534 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100535 // A system modules dependency has been added to the bootclasspath
536 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000537 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700538 } else {
539 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
540 }
541 case libTag:
542 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800543 case SdkLibraryDependency:
544 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700545 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900546 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900547 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700548 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800549 checkProducesJars(ctx, dep)
550 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800551 default:
552 ctx.ModuleErrorf("depends on non-java module %q", otherName)
553 }
Colin Cross6cef4812019-10-17 14:23:50 -0700554 case java9LibTag:
555 switch dep := module.(type) {
556 case Dependency:
557 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
558 default:
559 ctx.ModuleErrorf("depends on non-java module %q", otherName)
560 }
Nan Zhang357466b2018-04-17 17:38:36 -0700561 case systemModulesTag:
562 if deps.systemModules != nil {
563 panic("Found two system module dependencies")
564 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000565 sm := module.(SystemModulesProvider)
566 outputDir, outputDeps := sm.OutputDirAndDeps()
567 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800568 }
569 })
570 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
571 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800572 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900573
574 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
575 if filterPackages == nil {
576 return srcs
577 }
578 filtered := []android.Path{}
579 for _, src := range srcs {
580 if src.Ext() != ".java" {
581 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
582 // but otherwise metalava emits stub sources having references to the generated AIDL classes
583 // in filtered-out pacages (e.g. com.android.internal.*).
584 // TODO(b/141149570) We need to fix this by introducing default private constructors or
585 // fixing metalava to not emit constructors having references to unknown classes.
586 filtered = append(filtered, src)
587 continue
588 }
589 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800590 if android.HasAnyPrefix(packageName, filterPackages) {
591 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900592 }
593 }
594 return filtered
595 }
596 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
597
Nan Zhanga40da042018-08-01 12:48:00 -0700598 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900599 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800600
601 // srcs may depend on some genrule output.
602 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800603 j.srcJars = append(j.srcJars, deps.srcJars...)
604
Nan Zhang581fd212018-01-10 16:06:12 -0800605 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800606 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800607
Nan Zhang9c69a122018-08-22 10:22:08 -0700608 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800609 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
610 }
611 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800612
Colin Cross8a497952019-03-05 22:25:09 -0800613 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000614 argFilesMap := map[string]string{}
615 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700616
Paul Duffin99e4a502019-02-11 15:38:42 +0000617 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800618 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000619 if _, exists := argFilesMap[label]; !exists {
620 argFilesMap[label] = strings.Join(paths.Strings(), " ")
621 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700622 } else {
623 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000624 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700625 }
626 }
627
628 var err error
Colin Cross15638152019-07-11 11:11:35 -0700629 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700630 if strings.HasPrefix(name, "location ") {
631 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000632 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700633 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700634 } else {
Colin Cross15638152019-07-11 11:11:35 -0700635 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000636 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700637 }
638 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700639 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700640 }
Colin Cross15638152019-07-11 11:11:35 -0700641 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700642 })
643
644 if err != nil {
645 ctx.PropertyErrorf("args", "%s", err.Error())
646 }
647
Nan Zhang581fd212018-01-10 16:06:12 -0800648 return deps
649}
650
651func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
652 j.addDeps(ctx)
653}
654
655func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
656 deps := j.collectDeps(ctx)
657
Colin Crossdaa4c672019-07-15 22:53:46 -0700658 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800659
Colin Crossdaa4c672019-07-15 22:53:46 -0700660 outDir := android.PathForModuleOut(ctx, "out")
661 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
662
663 j.stubsSrcJar = nil
664
665 rule := android.NewRuleBuilder()
666
667 rule.Command().Text("rm -rf").Text(outDir.String())
668 rule.Command().Text("mkdir -p").Text(outDir.String())
669
670 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700671
Colin Cross83bb3162018-06-25 15:48:06 -0700672 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800673
Colin Crossdaa4c672019-07-15 22:53:46 -0700674 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
675 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800676
Colin Cross1e743852019-10-28 11:37:20 -0700677 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700678 Flag("-J-Xmx1024m").
679 Flag("-XDignore.symbol.file").
680 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800681
Colin Crossdaa4c672019-07-15 22:53:46 -0700682 rule.Command().
683 BuiltTool(ctx, "soong_zip").
684 Flag("-write_if_changed").
685 Flag("-d").
686 FlagWithOutput("-o ", j.docZip).
687 FlagWithArg("-C ", outDir.String()).
688 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700689
Colin Crossdaa4c672019-07-15 22:53:46 -0700690 rule.Restat()
691
692 zipSyncCleanupCmd(rule, srcJarDir)
693
694 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800695}
696
Nan Zhanga40da042018-08-01 12:48:00 -0700697//
698// Droiddoc
699//
700type Droiddoc struct {
701 Javadoc
702
703 properties DroiddocProperties
704 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700705 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700706 removedApiFile android.WritablePath
707 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700708
709 checkCurrentApiTimestamp android.WritablePath
710 updateCurrentApiTimestamp android.WritablePath
711 checkLastReleasedApiTimestamp android.WritablePath
712
Nan Zhanga40da042018-08-01 12:48:00 -0700713 apiFilePath android.Path
714}
715
Colin Crossa3002fc2019-07-08 16:48:04 -0700716// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700717func DroiddocFactory() android.Module {
718 module := &Droiddoc{}
719
720 module.AddProperties(&module.properties,
721 &module.Javadoc.properties)
722
723 InitDroiddocModule(module, android.HostAndDeviceSupported)
724 return module
725}
726
Colin Crossa3002fc2019-07-08 16:48:04 -0700727// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700728func DroiddocHostFactory() android.Module {
729 module := &Droiddoc{}
730
731 module.AddProperties(&module.properties,
732 &module.Javadoc.properties)
733
734 InitDroiddocModule(module, android.HostSupported)
735 return module
736}
737
738func (d *Droiddoc) ApiFilePath() android.Path {
739 return d.apiFilePath
740}
741
Nan Zhang581fd212018-01-10 16:06:12 -0800742func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
743 d.Javadoc.addDeps(ctx)
744
Inseob Kim38449af2019-02-28 14:24:05 +0900745 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
746 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
747 }
748
Nan Zhang79614d12018-04-19 18:03:39 -0700749 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800750 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
751 }
Nan Zhang581fd212018-01-10 16:06:12 -0800752}
753
Colin Crossab054432019-07-15 16:13:59 -0700754func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800755 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700756 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
757 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
758 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700759 cmd.FlagWithArg("-source ", "1.8").
760 Flag("-J-Xmx1600m").
761 Flag("-J-XX:-OmitStackTraceInFastThrow").
762 Flag("-XDignore.symbol.file").
763 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
764 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800765 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700766 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 -0700767
Nan Zhanga40da042018-08-01 12:48:00 -0700768 if String(d.properties.Custom_template) == "" {
769 // TODO: This is almost always droiddoc-templates-sdk
770 ctx.PropertyErrorf("custom_template", "must specify a template")
771 }
772
773 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700774 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700775 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700776 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000777 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700778 }
779 })
780
781 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700782 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
783 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
784 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700785 }
786
787 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700788 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
789 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
790 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700791 }
792
793 if len(d.properties.Html_dirs) > 2 {
794 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
795 }
796
Colin Cross8a497952019-03-05 22:25:09 -0800797 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700798 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700799
Colin Crossab054432019-07-15 16:13:59 -0700800 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700801
802 if String(d.properties.Proofread_file) != "" {
803 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700804 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700805 }
806
807 if String(d.properties.Todo_file) != "" {
808 // tricky part:
809 // we should not compute full path for todo_file through PathForModuleOut().
810 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700811 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
812 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700813 }
814
815 if String(d.properties.Resourcesdir) != "" {
816 // TODO: should we add files under resourcesDir to the implicits? It seems that
817 // resourcesDir is one sub dir of htmlDir
818 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700819 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700820 }
821
822 if String(d.properties.Resourcesoutdir) != "" {
823 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700824 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700825 }
Nan Zhanga40da042018-08-01 12:48:00 -0700826}
827
Colin Crossab054432019-07-15 16:13:59 -0700828func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200829 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
830 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700831 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700832
Nan Zhanga40da042018-08-01 12:48:00 -0700833 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700834 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700835 d.apiFilePath = d.apiFile
836 }
837
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200838 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
839 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700840 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700841 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700842 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700843 }
844
Nan Zhanga40da042018-08-01 12:48:00 -0700845 if String(d.properties.Removed_dex_api_filename) != "" {
846 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700847 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700848 }
849
Nan Zhanga40da042018-08-01 12:48:00 -0700850 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700851 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700852 }
853
854 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700855 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700856 }
Nan Zhanga40da042018-08-01 12:48:00 -0700857}
858
Colin Crossab054432019-07-15 16:13:59 -0700859func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700860 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700861 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
862 rule.Command().Text("cp").
863 Input(staticDocIndexRedirect).
864 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700865 }
866
867 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700868 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
869 rule.Command().Text("cp").
870 Input(staticDocProperties).
871 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700872 }
Nan Zhanga40da042018-08-01 12:48:00 -0700873}
874
Colin Crossab054432019-07-15 16:13:59 -0700875func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700876 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700877
878 cmd := rule.Command().
879 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
880 Flag(config.JavacVmFlags).
881 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700882 FlagWithRspFileInputList("@", srcs).
883 FlagWithInput("@", srcJarList)
884
Colin Crossab054432019-07-15 16:13:59 -0700885 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
886 // based stubs generation.
887 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
888 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
889 // the correct package name base path.
890 if len(sourcepaths) > 0 {
891 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
892 } else {
893 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
894 }
895
896 cmd.FlagWithArg("-d ", outDir.String()).
897 Flag("-quiet")
898
899 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700900}
901
Colin Crossdaa4c672019-07-15 22:53:46 -0700902func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
903 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
904 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
905
906 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
907
908 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
909 cmd.Flag(flag).Implicits(deps)
910
911 cmd.FlagWithArg("--patch-module ", "java.base=.")
912
913 if len(classpath) > 0 {
914 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
915 }
916
917 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700918}
919
Colin Crossdaa4c672019-07-15 22:53:46 -0700920func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
921 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
922 sourcepaths android.Paths) *android.RuleBuilderCommand {
923
924 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
925
926 if len(bootclasspath) == 0 && ctx.Device() {
927 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
928 // ensure java does not fall back to the default bootclasspath.
929 cmd.FlagWithArg("-bootclasspath ", `""`)
930 } else if len(bootclasspath) > 0 {
931 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
932 }
933
934 if len(classpath) > 0 {
935 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
936 }
937
938 return cmd
939}
940
Colin Crossab054432019-07-15 16:13:59 -0700941func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
942 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700943
Colin Crossab054432019-07-15 16:13:59 -0700944 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
945 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
946
947 return rule.Command().
948 BuiltTool(ctx, "dokka").
949 Flag(config.JavacVmFlags).
950 Flag(srcJarDir.String()).
951 FlagWithInputList("-classpath ", dokkaClasspath, ":").
952 FlagWithArg("-format ", "dac").
953 FlagWithArg("-dacRoot ", "/reference/kotlin").
954 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700955}
956
957func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
958 deps := d.Javadoc.collectDeps(ctx)
959
Colin Crossdaa4c672019-07-15 22:53:46 -0700960 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
961 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
962
Nan Zhang1598a9e2018-09-04 17:14:32 -0700963 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
964 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
965 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
966 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
967
Colin Crossab054432019-07-15 16:13:59 -0700968 outDir := android.PathForModuleOut(ctx, "out")
969 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
970 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -0700971
Colin Crossab054432019-07-15 16:13:59 -0700972 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -0700973
Colin Crossab054432019-07-15 16:13:59 -0700974 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
975 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700976
Colin Crossab054432019-07-15 16:13:59 -0700977 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
978
979 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -0700980 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -0700981 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700982 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -0700983 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -0700984 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700985 }
986
Colin Crossab054432019-07-15 16:13:59 -0700987 d.stubsFlags(ctx, cmd, stubsDir)
988
989 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
990
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000991 if d.properties.Compat_config != nil {
992 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
993 cmd.FlagWithInput("-compatconfig ", compatConfig)
994 }
995
Colin Crossab054432019-07-15 16:13:59 -0700996 var desc string
997 if Bool(d.properties.Dokka_enabled) {
998 desc = "dokka"
999 } else {
1000 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1001
1002 for _, o := range d.Javadoc.properties.Out {
1003 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1004 }
1005
1006 d.postDoclavaCmds(ctx, rule)
1007 desc = "doclava"
1008 }
1009
1010 rule.Command().
1011 BuiltTool(ctx, "soong_zip").
1012 Flag("-write_if_changed").
1013 Flag("-d").
1014 FlagWithOutput("-o ", d.docZip).
1015 FlagWithArg("-C ", outDir.String()).
1016 FlagWithArg("-D ", outDir.String())
1017
1018 rule.Command().
1019 BuiltTool(ctx, "soong_zip").
1020 Flag("-write_if_changed").
1021 Flag("-jar").
1022 FlagWithOutput("-o ", d.stubsSrcJar).
1023 FlagWithArg("-C ", stubsDir.String()).
1024 FlagWithArg("-D ", stubsDir.String())
1025
1026 rule.Restat()
1027
1028 zipSyncCleanupCmd(rule, srcJarDir)
1029
1030 rule.Build(pctx, ctx, "javadoc", desc)
1031
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001032 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001033 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001034
1035 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1036 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001037
1038 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001039
1040 rule := android.NewRuleBuilder()
1041
1042 rule.Command().Text("( true")
1043
1044 rule.Command().
1045 BuiltTool(ctx, "apicheck").
1046 Flag("-JXmx1024m").
1047 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1048 OptionalFlag(d.properties.Check_api.Current.Args).
1049 Input(apiFile).
1050 Input(d.apiFile).
1051 Input(removedApiFile).
1052 Input(d.removedApiFile)
1053
1054 msg := fmt.Sprintf(`\n******************************\n`+
1055 `You have tried to change the API from what has been previously approved.\n\n`+
1056 `To make these errors go away, you have two choices:\n`+
1057 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1058 ` errors above.\n\n`+
1059 ` 2. You can update current.txt by executing the following command:\n`+
1060 ` make %s-update-current-api\n\n`+
1061 ` To submit the revised current.txt to the main Android repository,\n`+
1062 ` you will need approval.\n`+
1063 `******************************\n`, ctx.ModuleName())
1064
1065 rule.Command().
1066 Text("touch").Output(d.checkCurrentApiTimestamp).
1067 Text(") || (").
1068 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1069 Text("; exit 38").
1070 Text(")")
1071
1072 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001073
1074 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001075
1076 // update API rule
1077 rule = android.NewRuleBuilder()
1078
1079 rule.Command().Text("( true")
1080
1081 rule.Command().
1082 Text("cp").Flag("-f").
1083 Input(d.apiFile).Flag(apiFile.String())
1084
1085 rule.Command().
1086 Text("cp").Flag("-f").
1087 Input(d.removedApiFile).Flag(removedApiFile.String())
1088
1089 msg = "failed to update public API"
1090
1091 rule.Command().
1092 Text("touch").Output(d.updateCurrentApiTimestamp).
1093 Text(") || (").
1094 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1095 Text("; exit 38").
1096 Text(")")
1097
1098 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001099 }
1100
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001101 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001102 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001103
1104 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1105 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001106
1107 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001108
1109 rule := android.NewRuleBuilder()
1110
1111 rule.Command().
1112 Text("(").
1113 BuiltTool(ctx, "apicheck").
1114 Flag("-JXmx1024m").
1115 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1116 OptionalFlag(d.properties.Check_api.Last_released.Args).
1117 Input(apiFile).
1118 Input(d.apiFile).
1119 Input(removedApiFile).
1120 Input(d.removedApiFile)
1121
1122 msg := `\n******************************\n` +
1123 `You have tried to change the API from what has been previously released in\n` +
1124 `an SDK. Please fix the errors listed above.\n` +
1125 `******************************\n`
1126
1127 rule.Command().
1128 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1129 Text(") || (").
1130 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1131 Text("; exit 38").
1132 Text(")")
1133
1134 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001135 }
1136}
1137
1138//
1139// Droidstubs
1140//
1141type Droidstubs struct {
1142 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001143 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001144
Pete Gillin581d6082018-10-22 15:55:04 +01001145 properties DroidstubsProperties
1146 apiFile android.WritablePath
1147 apiXmlFile android.WritablePath
1148 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001149 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001150 removedApiFile android.WritablePath
1151 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001152 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001153
1154 checkCurrentApiTimestamp android.WritablePath
1155 updateCurrentApiTimestamp android.WritablePath
1156 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001157 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001158 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001159
Pete Gillin581d6082018-10-22 15:55:04 +01001160 checkNullabilityWarningsTimestamp android.WritablePath
1161
Nan Zhang1598a9e2018-09-04 17:14:32 -07001162 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001163 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001164
1165 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001166
1167 jdiffDocZip android.WritablePath
1168 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001169
1170 metadataZip android.WritablePath
1171 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001172}
1173
Colin Crossa3002fc2019-07-08 16:48:04 -07001174// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1175// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1176// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001177func DroidstubsFactory() android.Module {
1178 module := &Droidstubs{}
1179
1180 module.AddProperties(&module.properties,
1181 &module.Javadoc.properties)
1182
1183 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001184 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001185 return module
1186}
1187
Colin Crossa3002fc2019-07-08 16:48:04 -07001188// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1189// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1190// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1191// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001192func DroidstubsHostFactory() android.Module {
1193 module := &Droidstubs{}
1194
1195 module.AddProperties(&module.properties,
1196 &module.Javadoc.properties)
1197
1198 InitDroiddocModule(module, android.HostSupported)
1199 return module
1200}
1201
1202func (d *Droidstubs) ApiFilePath() android.Path {
1203 return d.apiFilePath
1204}
1205
Paul Duffin1fd005d2020-04-09 01:08:11 +01001206func (d *Droidstubs) RemovedApiFilePath() android.Path {
1207 return d.removedApiFile
1208}
1209
Paul Duffin3d1248c2020-04-09 00:10:17 +01001210func (d *Droidstubs) StubsSrcJar() android.Path {
1211 return d.stubsSrcJar
1212}
1213
Nan Zhang1598a9e2018-09-04 17:14:32 -07001214func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1215 d.Javadoc.addDeps(ctx)
1216
Paul Duffin160fe412020-05-10 19:32:20 +01001217 // If requested clear any properties that provide information about the latest version
1218 // of an API and which reference non-existent modules.
Inseob Kim38449af2019-02-28 14:24:05 +09001219 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1220 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
Paul Duffin160fe412020-05-10 19:32:20 +01001221
1222 // If the new_since references a module, e.g. :module-latest-api and the module
1223 // does not exist then clear it.
1224 newSinceSrc := d.properties.Check_api.Api_lint.New_since
1225 newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc))
1226 if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) {
1227 d.properties.Check_api.Api_lint.New_since = nil
1228 }
Inseob Kim38449af2019-02-28 14:24:05 +09001229 }
1230
Nan Zhang1598a9e2018-09-04 17:14:32 -07001231 if len(d.properties.Merge_annotations_dirs) != 0 {
1232 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1233 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1234 }
1235 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001236
Pete Gillin77167902018-09-19 18:16:26 +01001237 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1238 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1239 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1240 }
1241 }
1242
Nan Zhang9c69a122018-08-22 10:22:08 -07001243 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1244 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1245 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1246 }
1247 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001248}
1249
Paul Duffin3ae29512020-04-08 18:18:03 +01001250func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001251 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1252 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001253 String(d.properties.Api_filename) != "" {
1254 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001255 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001256 d.apiFilePath = d.apiFile
1257 }
1258
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001259 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1260 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001261 String(d.properties.Removed_api_filename) != "" {
1262 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001263 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001264 }
1265
Nan Zhang1598a9e2018-09-04 17:14:32 -07001266 if String(d.properties.Removed_dex_api_filename) != "" {
1267 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001268 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001269 }
1270
Nan Zhang9c69a122018-08-22 10:22:08 -07001271 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001272 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1273 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001274 }
1275
Paul Duffin3ae29512020-04-08 18:18:03 +01001276 if stubsDir.Valid() {
1277 if Bool(d.properties.Create_doc_stubs) {
1278 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1279 } else {
1280 cmd.FlagWithArg("--stubs ", stubsDir.String())
1281 cmd.Flag("--exclude-documentation-from-stubs")
1282 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001283 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001284}
1285
Colin Cross33961b52019-07-11 11:01:22 -07001286func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001287 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001288 cmd.Flag("--include-annotations")
1289
Pete Gillinc382a562018-11-14 18:45:46 +00001290 validatingNullability :=
1291 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1292 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001293
Pete Gillina262c052018-09-14 14:25:48 +01001294 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001295 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001296 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001297 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001298 }
Colin Cross33961b52019-07-11 11:01:22 -07001299
Pete Gillinc382a562018-11-14 18:45:46 +00001300 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001301 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001302 }
Colin Cross33961b52019-07-11 11:01:22 -07001303
Pete Gillina262c052018-09-14 14:25:48 +01001304 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001305 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001306 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001307 }
Nan Zhanga40da042018-08-01 12:48:00 -07001308
1309 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001310 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001311
Nan Zhang1598a9e2018-09-04 17:14:32 -07001312 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001313 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001314 "has to be non-empty if annotations was enabled!")
1315 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001316
Colin Cross33961b52019-07-11 11:01:22 -07001317 d.mergeAnnoDirFlags(ctx, cmd)
1318
1319 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1320 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1321 FlagWithArg("--hide ", "SuperfluousPrefix").
1322 FlagWithArg("--hide ", "AnnotationExtraction")
1323 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001324}
1325
Colin Cross33961b52019-07-11 11:01:22 -07001326func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1327 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1328 if t, ok := m.(*ExportedDroiddocDir); ok {
1329 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1330 } else {
1331 ctx.PropertyErrorf("merge_annotations_dirs",
1332 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1333 }
1334 })
1335}
1336
1337func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001338 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1339 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001340 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001341 } else {
1342 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1343 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1344 }
1345 })
Nan Zhanga40da042018-08-01 12:48:00 -07001346}
1347
Colin Cross33961b52019-07-11 11:01:22 -07001348func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001349 if Bool(d.properties.Api_levels_annotations_enabled) {
1350 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001351
1352 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1353 ctx.PropertyErrorf("api_levels_annotations_dirs",
1354 "has to be non-empty if api levels annotations was enabled!")
1355 }
1356
Colin Cross33961b52019-07-11 11:01:22 -07001357 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1358 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1359 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1360 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001361
1362 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1363 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001364 for _, dep := range t.deps {
1365 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001366 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001367 }
1368 }
Colin Cross33961b52019-07-11 11:01:22 -07001369 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001370 } else {
1371 ctx.PropertyErrorf("api_levels_annotations_dirs",
1372 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1373 }
1374 })
1375
1376 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001377}
1378
Colin Cross33961b52019-07-11 11:01:22 -07001379func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001380 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1381 if d.apiFile.String() == "" {
1382 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1383 }
1384
1385 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001386 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001387
1388 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1389 ctx.PropertyErrorf("check_api.last_released.api_file",
1390 "has to be non-empty if jdiff was enabled!")
1391 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001392
Colin Cross33961b52019-07-11 11:01:22 -07001393 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001394 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001395 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1396 }
1397}
Nan Zhang71bbe632018-09-17 14:32:21 -07001398
Colin Cross1e743852019-10-28 11:37:20 -07001399func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001400 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001401 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1402 rule.HighMem()
Ramy Medhat427683c2020-04-30 03:08:37 -04001403 cmd := rule.Command()
1404 if ctx.Config().IsEnvTrue("RBE_METALAVA") {
1405 rule.Remoteable(android.RemoteRuleSupports{RBE: true})
1406 execStrategy := remoteexec.LocalExecStrategy
1407 if v := ctx.Config().Getenv("RBE_METALAVA_EXEC_STRATEGY"); v != "" {
1408 execStrategy = v
1409 }
1410 pool := "metalava"
1411 if v := ctx.Config().Getenv("RBE_METALAVA_POOL"); v != "" {
1412 pool = v
1413 }
1414 inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
1415 if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
1416 inputs = append(inputs, strings.Split(v, ",")...)
1417 }
1418 cmd.Text((&remoteexec.REParams{
1419 Labels: map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"},
1420 ExecStrategy: execStrategy,
1421 Inputs: inputs,
1422 ToolchainInputs: []string{config.JavaCmd(ctx).String()},
1423 Platform: map[string]string{remoteexec.PoolKey: pool},
1424 }).NoVarTemplate(ctx.Config()))
1425 }
1426
1427 cmd.BuiltTool(ctx, "metalava").
Colin Cross33961b52019-07-11 11:01:22 -07001428 Flag(config.JavacVmFlags).
1429 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001430 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001431 FlagWithRspFileInputList("@", srcs).
1432 FlagWithInput("@", srcJarList)
1433
1434 if len(bootclasspath) > 0 {
1435 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001436 }
1437
Colin Cross33961b52019-07-11 11:01:22 -07001438 if len(classpath) > 0 {
1439 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1440 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001441
Colin Cross33961b52019-07-11 11:01:22 -07001442 if len(sourcepaths) > 0 {
1443 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1444 } else {
1445 cmd.FlagWithArg("-sourcepath ", `""`)
1446 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001447
Colin Cross33961b52019-07-11 11:01:22 -07001448 cmd.Flag("--no-banner").
1449 Flag("--color").
1450 Flag("--quiet").
1451 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001452
Colin Cross33961b52019-07-11 11:01:22 -07001453 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001454}
1455
Nan Zhang1598a9e2018-09-04 17:14:32 -07001456func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001457 deps := d.Javadoc.collectDeps(ctx)
1458
1459 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001460
Colin Cross33961b52019-07-11 11:01:22 -07001461 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001462
Colin Cross33961b52019-07-11 11:01:22 -07001463 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001464
Colin Cross33961b52019-07-11 11:01:22 -07001465 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001466
Paul Duffin3ae29512020-04-08 18:18:03 +01001467 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1468 var stubsDir android.OptionalPath
1469 if generateStubs {
1470 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1471 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1472 rule.Command().Text("rm -rf").Text(stubsDir.String())
1473 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1474 }
Nan Zhanga40da042018-08-01 12:48:00 -07001475
Colin Cross33961b52019-07-11 11:01:22 -07001476 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1477
1478 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1479 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1480
1481 d.stubsFlags(ctx, cmd, stubsDir)
1482
1483 d.annotationsFlags(ctx, cmd)
1484 d.inclusionAnnotationsFlags(ctx, cmd)
1485 d.apiLevelsAnnotationsFlags(ctx, cmd)
1486 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001487
Nan Zhang1598a9e2018-09-04 17:14:32 -07001488 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1489 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1490 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1491 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1492 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001493 }
Colin Cross33961b52019-07-11 11:01:22 -07001494
1495 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1496 for _, o := range d.Javadoc.properties.Out {
1497 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1498 }
1499
Makoto Onuki88b99052020-04-27 17:22:16 -07001500 // Add options for the other optional tasks: API-lint and check-released.
1501 // We generate separate timestamp files for them.
1502
1503 doApiLint := false
1504 doCheckReleased := false
1505
1506 // Add API lint options.
1507
1508 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1509 doApiLint = true
1510
1511 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1512 if newSince.Valid() {
1513 cmd.FlagWithInput("--api-lint ", newSince.Path())
1514 } else {
1515 cmd.Flag("--api-lint")
1516 }
1517 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1518 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1519
1520 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1521 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1522 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1523
1524 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1525 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1526 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1527 // which is why we have '"$PWD"$' in it.
1528 //
1529 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1530 // message and metalava's one?
1531 msg := `$'` + // Enclose with $' ... '
1532 `************************************************************\n` +
1533 `Your API changes are triggering API Lint warnings or errors.\n` +
1534 `To make these errors go away, fix the code according to the\n` +
1535 `error and/or warning messages above.\n` +
1536 `\n` +
1537 `If it is not possible to do so, there are workarounds:\n` +
1538 `\n` +
1539 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1540
1541 if baselineFile.Valid() {
1542 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1543 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1544
1545 msg += fmt.Sprintf(``+
1546 `2. You can update the baseline by executing the following\n`+
1547 ` command:\n`+
1548 ` cp \\ \n`+
1549 ` "'"$PWD"$'/%s" \\ \n`+
1550 ` "'"$PWD"$'/%s" \n`+
1551 ` To submit the revised baseline.txt to the main Android\n`+
1552 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1553 } else {
1554 msg += fmt.Sprintf(``+
1555 `2. You can add a baseline file of existing lint failures\n`+
1556 ` to the build rule of %s.\n`, d.Name())
1557 }
1558 // Note the message ends with a ' (single quote), to close the $' ... ' .
1559 msg += `************************************************************\n'`
1560
1561 cmd.FlagWithArg("--error-message:api-lint ", msg)
1562 }
1563
1564 // Add "check released" options. (Detect incompatible API changes from the last public release)
1565
1566 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
1567 !ctx.Config().IsPdkBuild() {
1568 doCheckReleased = true
1569
1570 if len(d.Javadoc.properties.Out) > 0 {
1571 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1572 }
1573
1574 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1575 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1576 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1577 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1578
1579 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1580
1581 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1582 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1583
1584 if baselineFile.Valid() {
1585 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1586 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1587 }
1588
1589 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1590 msg := `$'\n******************************\n` +
1591 `You have tried to change the API from what has been previously released in\n` +
1592 `an SDK. Please fix the errors listed above.\n` +
1593 `******************************\n'`
1594
1595 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1596 }
1597
Paul Duffin3ae29512020-04-08 18:18:03 +01001598 if generateStubs {
1599 rule.Command().
1600 BuiltTool(ctx, "soong_zip").
1601 Flag("-write_if_changed").
1602 Flag("-jar").
1603 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1604 FlagWithArg("-C ", stubsDir.String()).
1605 FlagWithArg("-D ", stubsDir.String())
1606 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001607
1608 if Bool(d.properties.Write_sdk_values) {
1609 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1610 rule.Command().
1611 BuiltTool(ctx, "soong_zip").
1612 Flag("-write_if_changed").
1613 Flag("-d").
1614 FlagWithOutput("-o ", d.metadataZip).
1615 FlagWithArg("-C ", d.metadataDir.String()).
1616 FlagWithArg("-D ", d.metadataDir.String())
1617 }
1618
Makoto Onuki88b99052020-04-27 17:22:16 -07001619 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1620 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1621 if doApiLint {
1622 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1623 }
1624 if doCheckReleased {
1625 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1626 }
1627
Colin Cross33961b52019-07-11 11:01:22 -07001628 rule.Restat()
1629
1630 zipSyncCleanupCmd(rule, srcJarDir)
1631
Makoto Onuki88b99052020-04-27 17:22:16 -07001632 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001633
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001634 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001635 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001636
1637 if len(d.Javadoc.properties.Out) > 0 {
1638 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1639 }
1640
1641 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1642 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001643 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onuki5405a732020-04-16 17:02:40 -07001644
1645 if baselineFile.Valid() {
Makoto Onuki88b99052020-04-27 17:22:16 -07001646 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onuki5405a732020-04-16 17:02:40 -07001647 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001648
Nan Zhang2760dfc2018-08-24 17:32:54 +00001649 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001650
Colin Cross33961b52019-07-11 11:01:22 -07001651 rule := android.NewRuleBuilder()
1652
Makoto Onuki5405a732020-04-16 17:02:40 -07001653 // Diff command line.
Makoto Onuki88b99052020-04-27 17:22:16 -07001654 // -F matches the closest "opening" line, such as "package android {"
1655 // and " public class Intent {".
Makoto Onuki5405a732020-04-16 17:02:40 -07001656 diff := `diff -u -F '{ *$'`
1657
Colin Cross33961b52019-07-11 11:01:22 -07001658 rule.Command().Text("( true")
Makoto Onuki5405a732020-04-16 17:02:40 -07001659 rule.Command().
1660 Text(diff).
1661 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001662
Makoto Onuki5405a732020-04-16 17:02:40 -07001663 rule.Command().
1664 Text(diff).
1665 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001666
1667 msg := fmt.Sprintf(`\n******************************\n`+
1668 `You have tried to change the API from what has been previously approved.\n\n`+
1669 `To make these errors go away, you have two choices:\n`+
Makoto Onuki5405a732020-04-16 17:02:40 -07001670 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1671 ` to the new methods, etc. shown in the above diff.\n\n`+
1672 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001673 ` make %s-update-current-api\n\n`+
1674 ` To submit the revised current.txt to the main Android repository,\n`+
1675 ` you will need approval.\n`+
1676 `******************************\n`, ctx.ModuleName())
1677
1678 rule.Command().
1679 Text("touch").Output(d.checkCurrentApiTimestamp).
1680 Text(") || (").
1681 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1682 Text("; exit 38").
1683 Text(")")
1684
Makoto Onuki5405a732020-04-16 17:02:40 -07001685 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001686
1687 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001688
1689 // update API rule
1690 rule = android.NewRuleBuilder()
1691
1692 rule.Command().Text("( true")
1693
1694 rule.Command().
1695 Text("cp").Flag("-f").
1696 Input(d.apiFile).Flag(apiFile.String())
1697
1698 rule.Command().
1699 Text("cp").Flag("-f").
1700 Input(d.removedApiFile).Flag(removedApiFile.String())
1701
1702 msg = "failed to update public API"
1703
1704 rule.Command().
1705 Text("touch").Output(d.updateCurrentApiTimestamp).
1706 Text(") || (").
1707 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1708 Text("; exit 38").
1709 Text(")")
1710
1711 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001712 }
Nan Zhanga40da042018-08-01 12:48:00 -07001713
Pete Gillin581d6082018-10-22 15:55:04 +01001714 if String(d.properties.Check_nullability_warnings) != "" {
1715 if d.nullabilityWarningsFile == nil {
1716 ctx.PropertyErrorf("check_nullability_warnings",
1717 "Cannot specify check_nullability_warnings unless validating nullability")
1718 }
Colin Cross33961b52019-07-11 11:01:22 -07001719
1720 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1721
Pete Gillin581d6082018-10-22 15:55:04 +01001722 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001723
Pete Gillin581d6082018-10-22 15:55:04 +01001724 msg := fmt.Sprintf(`\n******************************\n`+
1725 `The warnings encountered during nullability annotation validation did\n`+
1726 `not match the checked in file of expected warnings. The diffs are shown\n`+
1727 `above. You have two options:\n`+
1728 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1729 ` 2. Update the file of expected warnings by running:\n`+
1730 ` cp %s %s\n`+
1731 ` and submitting the updated file as part of your change.`,
1732 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001733
1734 rule := android.NewRuleBuilder()
1735
1736 rule.Command().
1737 Text("(").
1738 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1739 Text("&&").
1740 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1741 Text(") || (").
1742 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1743 Text("; exit 38").
1744 Text(")")
1745
1746 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001747 }
1748
Nan Zhang71bbe632018-09-17 14:32:21 -07001749 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001750 if len(d.Javadoc.properties.Out) > 0 {
1751 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1752 }
1753
1754 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1755 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1756 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1757
1758 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001759
Nan Zhang86b06202018-09-21 17:09:21 -07001760 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1761 // since there's cron job downstream that fetch this .zip file periodically.
1762 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001763 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1764 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1765
Nan Zhang71bbe632018-09-17 14:32:21 -07001766 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001767
Colin Cross33961b52019-07-11 11:01:22 -07001768 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1769 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001770
Colin Cross33961b52019-07-11 11:01:22 -07001771 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1772
Colin Crossdaa4c672019-07-15 22:53:46 -07001773 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001774 deps.bootClasspath, deps.classpath, d.sourcepaths)
1775
1776 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001777 Flag("-XDignore.symbol.file").
1778 FlagWithArg("-doclet ", "jdiff.JDiff").
1779 FlagWithInput("-docletpath ", jdiff).
1780 Flag("-quiet").
1781 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1782 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1783 Implicit(d.apiXmlFile).
1784 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1785 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1786 Implicit(d.lastReleasedApiXmlFile)
1787
Colin Cross33961b52019-07-11 11:01:22 -07001788 rule.Command().
1789 BuiltTool(ctx, "soong_zip").
1790 Flag("-write_if_changed").
1791 Flag("-d").
1792 FlagWithOutput("-o ", d.jdiffDocZip).
1793 FlagWithArg("-C ", outDir.String()).
1794 FlagWithArg("-D ", outDir.String())
1795
1796 rule.Command().
1797 BuiltTool(ctx, "soong_zip").
1798 Flag("-write_if_changed").
1799 Flag("-jar").
1800 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1801 FlagWithArg("-C ", stubsDir.String()).
1802 FlagWithArg("-D ", stubsDir.String())
1803
1804 rule.Restat()
1805
1806 zipSyncCleanupCmd(rule, srcJarDir)
1807
1808 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001809 }
Nan Zhang581fd212018-01-10 16:06:12 -08001810}
Dan Willemsencc090972018-02-26 14:33:31 -08001811
Nan Zhanga40da042018-08-01 12:48:00 -07001812//
Nan Zhangf4936b02018-08-01 15:00:28 -07001813// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001814//
Dan Willemsencc090972018-02-26 14:33:31 -08001815var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001816var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001817var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001818var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001819
Nan Zhangf4936b02018-08-01 15:00:28 -07001820type ExportedDroiddocDirProperties struct {
1821 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001822 Path *string
1823}
1824
Nan Zhangf4936b02018-08-01 15:00:28 -07001825type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001826 android.ModuleBase
1827
Nan Zhangf4936b02018-08-01 15:00:28 -07001828 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001829
1830 deps android.Paths
1831 dir android.Path
1832}
1833
Colin Crossa3002fc2019-07-08 16:48:04 -07001834// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001835func ExportedDroiddocDirFactory() android.Module {
1836 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001837 module.AddProperties(&module.properties)
1838 android.InitAndroidModule(module)
1839 return module
1840}
1841
Nan Zhangf4936b02018-08-01 15:00:28 -07001842func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001843
Nan Zhangf4936b02018-08-01 15:00:28 -07001844func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001845 path := String(d.properties.Path)
1846 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001847 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001848}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001849
1850//
1851// Defaults
1852//
1853type DocDefaults struct {
1854 android.ModuleBase
1855 android.DefaultsModuleBase
1856}
1857
Nan Zhangb2b33de2018-02-23 11:18:47 -08001858func DocDefaultsFactory() android.Module {
1859 module := &DocDefaults{}
1860
1861 module.AddProperties(
1862 &JavadocProperties{},
1863 &DroiddocProperties{},
1864 )
1865
1866 android.InitDefaultsModule(module)
1867
1868 return module
1869}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001870
1871func StubsDefaultsFactory() android.Module {
1872 module := &DocDefaults{}
1873
1874 module.AddProperties(
1875 &JavadocProperties{},
1876 &DroidstubsProperties{},
1877 )
1878
1879 android.InitDefaultsModule(module)
1880
1881 return module
1882}
Colin Cross33961b52019-07-11 11:01:22 -07001883
1884func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1885 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1886
1887 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1888 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1889 srcJarList := srcJarDir.Join(ctx, "list")
1890
1891 rule.Temporary(srcJarList)
1892
1893 rule.Command().BuiltTool(ctx, "zipsync").
1894 FlagWithArg("-d ", srcJarDir.String()).
1895 FlagWithOutput("-l ", srcJarList).
1896 FlagWithArg("-f ", `"*.java"`).
1897 Inputs(srcJars)
1898
1899 return srcJarList
1900}
1901
1902func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1903 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1904}
Paul Duffin91547182019-11-12 19:39:36 +00001905
1906var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1907
1908type PrebuiltStubsSourcesProperties struct {
1909 Srcs []string `android:"path"`
1910}
1911
1912type PrebuiltStubsSources struct {
1913 android.ModuleBase
1914 android.DefaultableModuleBase
1915 prebuilt android.Prebuilt
1916 android.SdkBase
1917
1918 properties PrebuiltStubsSourcesProperties
1919
Paul Duffin9b478b02019-12-10 13:41:51 +00001920 // The source directories containing stubs source files.
1921 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001922 stubsSrcJar android.ModuleOutPath
1923}
1924
Paul Duffin9b478b02019-12-10 13:41:51 +00001925func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1926 switch tag {
1927 case "":
1928 return android.Paths{p.stubsSrcJar}, nil
1929 default:
1930 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1931 }
1932}
1933
Paul Duffin91547182019-11-12 19:39:36 +00001934func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001935 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1936
1937 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1938
1939 rule := android.NewRuleBuilder()
1940 command := rule.Command().
1941 BuiltTool(ctx, "soong_zip").
1942 Flag("-write_if_changed").
1943 Flag("-jar").
1944 FlagWithOutput("-o ", p.stubsSrcJar)
1945
1946 for _, d := range p.srcDirs {
1947 dir := d.String()
1948 command.
1949 FlagWithArg("-C ", dir).
1950 FlagWithInput("-D ", d)
1951 }
1952
1953 rule.Restat()
1954
1955 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001956}
1957
1958func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
1959 return &p.prebuilt
1960}
1961
1962func (p *PrebuiltStubsSources) Name() string {
1963 return p.prebuilt.Name(p.ModuleBase.Name())
1964}
1965
Paul Duffin91547182019-11-12 19:39:36 +00001966// prebuilt_stubs_sources imports a set of java source files as if they were
1967// generated by droidstubs.
1968//
1969// By default, a prebuilt_stubs_sources has a single variant that expects a
1970// set of `.java` files generated by droidstubs.
1971//
1972// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
1973// for host modules.
1974//
1975// Intended only for use by sdk snapshots.
1976func PrebuiltStubsSourcesFactory() android.Module {
1977 module := &PrebuiltStubsSources{}
1978
1979 module.AddProperties(&module.properties)
1980
1981 android.InitPrebuiltModule(module, &module.properties.Srcs)
1982 android.InitSdkAwareModule(module)
1983 InitDroiddocModule(module, android.HostAndDeviceSupported)
1984 return module
1985}
1986
Paul Duffin13879572019-11-28 14:31:38 +00001987type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00001988 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00001989}
1990
1991func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
1992 mctx.AddVariationDependencies(nil, dependencyTag, names...)
1993}
1994
1995func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
1996 _, ok := module.(*Droidstubs)
1997 return ok
1998}
1999
Paul Duffin495ffb92020-03-20 13:35:40 +00002000func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2001 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
2002}
2003
2004func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2005 return &droidStubsInfoProperties{}
2006}
2007
2008type droidStubsInfoProperties struct {
2009 android.SdkMemberPropertiesBase
2010
2011 StubsSrcJar android.Path
2012}
2013
2014func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2015 droidstubs := variant.(*Droidstubs)
2016 p.StubsSrcJar = droidstubs.stubsSrcJar
2017}
2018
2019func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
2020 if p.StubsSrcJar != nil {
2021 builder := ctx.SnapshotBuilder()
2022
2023 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2024
2025 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2026
2027 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002028 }
Paul Duffin91547182019-11-12 19:39:36 +00002029}