blob: 70d997a43324422b2d19ee3d98f62560363c8317 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Nan Zhang581fd212018-01-10 16:06:12 -080027)
28
29func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000030 RegisterDocsBuildComponents(android.InitRegistrationContext)
31 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000032
33 // Register sdk member type.
34 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
35 SdkMemberTypeBase: android.SdkMemberTypeBase{
36 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000037 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
38 // the APEX.
39 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000040 },
41 })
Nan Zhang581fd212018-01-10 16:06:12 -080042}
43
Paul Duffin884363e2019-12-19 10:21:09 +000044func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
45 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
46
47 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
48 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
49 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
50 ctx.RegisterModuleType("javadoc", JavadocFactory)
51 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
52}
53
54func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
55 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
56
57 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
58 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
59
60 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
61}
62
Colin Crossa1ce2a02018-06-20 15:19:39 -070063var (
64 srcsLibTag = dependencyTag{name: "sources from javalib"}
65)
66
Nan Zhang581fd212018-01-10 16:06:12 -080067type JavadocProperties struct {
68 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
69 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080070 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080071
72 // list of directories rooted at the Android.bp file that will
73 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080074 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080075
76 // list of source files that should not be used to build the Java module.
77 // This is most useful in the arch/multilib variants to remove non-common files
78 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080079 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080080
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090081 // list of package names that should actually be used. If this property is left unspecified,
82 // all the sources from the srcs property is used.
83 Filter_packages []string
84
Nan Zhangb2b33de2018-02-23 11:18:47 -080085 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080086 Libs []string `android:"arch_variant"`
87
88 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080089 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080090
Paul Duffine25c6442019-10-11 13:50:28 +010091 // if not blank, set to the version of the sdk to compile against.
92 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080093 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090094
Paul Duffine25c6442019-10-11 13:50:28 +010095 // When targeting 1.9 and above, override the modules to use with --system,
96 // otherwise provides defaults libraries to add to the bootclasspath.
97 // Defaults to "none"
98 System_modules *string
99
Jiyong Park1e440682018-05-23 18:42:04 +0900100 Aidl struct {
101 // Top level directories to pass to aidl tool
102 Include_dirs []string
103
104 // Directories rooted at the Android.bp file to pass to aidl tool
105 Local_include_dirs []string
106 }
Nan Zhang357466b2018-04-17 17:38:36 -0700107
108 // If not blank, set the java version passed to javadoc as -source
109 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700110
111 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800112 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700113
114 // user customized droiddoc args.
115 // Available variables for substitution:
116 //
117 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700118 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700119 Args *string
120
121 // names of the output files used in args that will be generated
122 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800123}
124
Nan Zhang61819ce2018-05-04 18:49:16 -0700125type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900126 // path to the API txt file that the new API extracted from source code is checked
127 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800128 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700129
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900130 // path to the API txt file that the new @removed API extractd from source code is
131 // checked against. The path can be local to the module or from other module (via
132 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800133 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700134
Adrian Roos14f75a92019-08-12 17:54:09 +0200135 // If not blank, path to the baseline txt file for approved API check violations.
136 Baseline_file *string `android:"path"`
137
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700139 Args *string
140}
141
Nan Zhang581fd212018-01-10 16:06:12 -0800142type DroiddocProperties struct {
143 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800144 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800145
Nan Zhanga40da042018-08-01 12:48:00 -0700146 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800147 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800148
149 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800150 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800151
152 // proofread file contains all of the text content of the javadocs concatenated into one file,
153 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700154 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800155
156 // a todo file lists the program elements that are missing documentation.
157 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800158 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800159
160 // directory under current module source that provide additional resources (images).
161 Resourcesdir *string
162
163 // resources output directory under out/soong/.intermediates.
164 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800165
Nan Zhange2ba5d42018-07-11 15:16:55 -0700166 // if set to true, collect the values used by the Dev tools and
167 // write them in files packaged with the SDK. Defaults to false.
168 Write_sdk_values *bool
169
170 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800171 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700172
173 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800174 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700175
Nan Zhang581fd212018-01-10 16:06:12 -0800176 // a list of files under current module source dir which contains known tags in Java sources.
177 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800178 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700179
180 // the tag name used to distinguish if the API files belong to public/system/test.
181 Api_tag_name *string
182
183 // the generated public API filename by Doclava.
184 Api_filename *string
185
David Brazdilfbe4cc32018-05-31 13:56:46 +0100186 // the generated public Dex API filename by Doclava.
187 Dex_api_filename *string
188
Nan Zhang28c68b92018-03-13 16:17:01 -0700189 // the generated private API filename by Doclava.
190 Private_api_filename *string
191
192 // the generated private Dex API filename by Doclava.
193 Private_dex_api_filename *string
194
195 // the generated removed API filename by Doclava.
196 Removed_api_filename *string
197
David Brazdilaac0c3c2018-04-24 16:23:29 +0100198 // the generated removed Dex API filename by Doclava.
199 Removed_dex_api_filename *string
200
Mathew Inwood76c3de12018-06-22 15:28:11 +0100201 // mapping of dex signatures to source file and line number. This is a temporary property and
202 // will be deleted; you probably shouldn't be using it.
203 Dex_mapping_filename *string
204
Nan Zhang28c68b92018-03-13 16:17:01 -0700205 // the generated exact API filename by Doclava.
206 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700207
Nan Zhang66dc2362018-08-14 20:41:04 -0700208 // the generated proguard filename by Doclava.
209 Proguard_filename *string
210
Nan Zhang853f4202018-04-12 16:55:56 -0700211 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
212 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700213
214 Check_api struct {
215 Last_released ApiToCheck
216
217 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900218
219 // do not perform API check against Last_released, in the case that both two specified API
220 // files by Last_released are modules which don't exist.
221 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700222 }
Nan Zhang79614d12018-04-19 18:03:39 -0700223
Nan Zhang1598a9e2018-09-04 17:14:32 -0700224 // if set to true, generate docs through Dokka instead of Doclava.
225 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000226
227 // Compat config XML. Generates compat change documentation if set.
228 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700229}
230
231type DroidstubsProperties struct {
232 // the tag name used to distinguish if the API files belong to public/system/test.
233 Api_tag_name *string
234
Nan Zhang199645c2018-09-19 12:40:06 -0700235 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700236 Api_filename *string
237
Nan Zhang199645c2018-09-19 12:40:06 -0700238 // the generated public Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700239 Dex_api_filename *string
240
Nan Zhang199645c2018-09-19 12:40:06 -0700241 // the generated private API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700242 Private_api_filename *string
243
Nan Zhang199645c2018-09-19 12:40:06 -0700244 // the generated private Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700245 Private_dex_api_filename *string
246
Nan Zhang199645c2018-09-19 12:40:06 -0700247 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700248 Removed_api_filename *string
249
Nan Zhang199645c2018-09-19 12:40:06 -0700250 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700251 Removed_dex_api_filename *string
252
Nan Zhang9c69a122018-08-22 10:22:08 -0700253 // mapping of dex signatures to source file and line number. This is a temporary property and
254 // will be deleted; you probably shouldn't be using it.
255 Dex_mapping_filename *string
256
Nan Zhang199645c2018-09-19 12:40:06 -0700257 // the generated exact API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700258 Exact_api_filename *string
259
Nan Zhang199645c2018-09-19 12:40:06 -0700260 // the generated proguard filename by Metalava.
261 Proguard_filename *string
262
Nan Zhang1598a9e2018-09-04 17:14:32 -0700263 Check_api struct {
264 Last_released ApiToCheck
265
266 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900267
268 // do not perform API check against Last_released, in the case that both two specified API
269 // files by Last_released are modules which don't exist.
270 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200271
272 Api_lint struct {
273 Enabled *bool
274
275 // If set, performs api_lint on any new APIs not found in the given signature file
276 New_since *string `android:"path"`
277
278 // If not blank, path to the baseline txt file for approved API lint violations.
279 Baseline_file *string `android:"path"`
280 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700281 }
Nan Zhang79614d12018-04-19 18:03:39 -0700282
283 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800284 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700285
286 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700287 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700288
Pete Gillin77167902018-09-19 18:16:26 +0100289 // 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 -0700290 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700291
Pete Gillin77167902018-09-19 18:16:26 +0100292 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
293 Merge_inclusion_annotations_dirs []string
294
Pete Gillinc382a562018-11-14 18:45:46 +0000295 // a file containing a list of classes to do nullability validation for.
296 Validate_nullability_from_list *string
297
Pete Gillin581d6082018-10-22 15:55:04 +0100298 // a file containing expected warnings produced by validation of nullability annotations.
299 Check_nullability_warnings *string
300
Nan Zhang1598a9e2018-09-04 17:14:32 -0700301 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
302 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700303
304 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
305 Api_levels_annotations_enabled *bool
306
307 // the dirs which Metalava extracts API levels annotations from.
308 Api_levels_annotations_dirs []string
309
310 // if set to true, collect the values used by the Dev tools and
311 // write them in files packaged with the SDK. Defaults to false.
312 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700313
314 // If set to true, .xml based public API file will be also generated, and
315 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
316 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800317}
318
Nan Zhanga40da042018-08-01 12:48:00 -0700319//
320// Common flags passed down to build rule
321//
322type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700323 bootClasspathArgs string
324 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700325 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700326 dokkaClasspathArgs string
327 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700328 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700329
Nan Zhanga40da042018-08-01 12:48:00 -0700330 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700331 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700332 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700333}
334
335func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
336 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
337 android.InitDefaultableModule(module)
338}
339
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200340func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
341 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
342 return false
343 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700344 return true
345 } else if String(apiToCheck.Api_file) != "" {
346 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
347 } else if String(apiToCheck.Removed_api_file) != "" {
348 panic("for " + apiVersionTag + " api_file has to be non-empty!")
349 }
350
351 return false
352}
353
Inseob Kim38449af2019-02-28 14:24:05 +0900354func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
355 api_file := String(apiToCheck.Api_file)
356 removed_api_file := String(apiToCheck.Removed_api_file)
357
358 api_module := android.SrcIsModule(api_file)
359 removed_api_module := android.SrcIsModule(removed_api_file)
360
361 if api_module == "" || removed_api_module == "" {
362 return
363 }
364
365 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
366 return
367 }
368
369 apiToCheck.Api_file = nil
370 apiToCheck.Removed_api_file = nil
371}
372
Nan Zhang1598a9e2018-09-04 17:14:32 -0700373type ApiFilePath interface {
374 ApiFilePath() android.Path
375}
376
Nan Zhanga40da042018-08-01 12:48:00 -0700377//
378// Javadoc
379//
Nan Zhang581fd212018-01-10 16:06:12 -0800380type Javadoc struct {
381 android.ModuleBase
382 android.DefaultableModuleBase
383
384 properties JavadocProperties
385
386 srcJars android.Paths
387 srcFiles android.Paths
388 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700389 argFiles android.Paths
390
391 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800392
Nan Zhangccff0f72018-03-08 17:26:16 -0800393 docZip android.WritablePath
394 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800395}
396
Colin Cross41955e82019-05-29 14:40:35 -0700397func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
398 switch tag {
399 case "":
400 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700401 case ".docs.zip":
402 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700403 default:
404 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
405 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800406}
407
Colin Crossa3002fc2019-07-08 16:48:04 -0700408// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800409func JavadocFactory() android.Module {
410 module := &Javadoc{}
411
412 module.AddProperties(&module.properties)
413
414 InitDroiddocModule(module, android.HostAndDeviceSupported)
415 return module
416}
417
Colin Crossa3002fc2019-07-08 16:48:04 -0700418// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800419func JavadocHostFactory() android.Module {
420 module := &Javadoc{}
421
422 module.AddProperties(&module.properties)
423
424 InitDroiddocModule(module, android.HostSupported)
425 return module
426}
427
Colin Cross41955e82019-05-29 14:40:35 -0700428var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800429
Jiyong Park6a927c42020-01-21 02:03:43 +0900430func (j *Javadoc) sdkVersion() sdkSpec {
431 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700432}
433
Paul Duffine25c6442019-10-11 13:50:28 +0100434func (j *Javadoc) systemModules() string {
435 return proptools.String(j.properties.System_modules)
436}
437
Jiyong Park6a927c42020-01-21 02:03:43 +0900438func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700439 return j.sdkVersion()
440}
441
Jiyong Park6a927c42020-01-21 02:03:43 +0900442func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700443 return j.sdkVersion()
444}
445
Nan Zhang581fd212018-01-10 16:06:12 -0800446func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
447 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100448 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700449 if sdkDep.useDefaultLibs {
450 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
451 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
452 if sdkDep.hasFrameworkLibs() {
453 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700454 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700455 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700456 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100457 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700458 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800459 }
460 }
461
Colin Cross42d48b72018-08-29 14:10:52 -0700462 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800463}
464
Nan Zhanga40da042018-08-01 12:48:00 -0700465func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
466 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900467
Colin Cross3047fa22019-04-18 10:56:44 -0700468 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900469
470 return flags
471}
472
473func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700474 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900475
476 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
477 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
478
479 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700480 var deps android.Paths
481
Jiyong Park1e440682018-05-23 18:42:04 +0900482 if aidlPreprocess.Valid() {
483 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700484 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900485 } else {
486 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
487 }
488
489 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
490 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
491 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
492 flags = append(flags, "-I"+src.String())
493 }
494
Colin Cross3047fa22019-04-18 10:56:44 -0700495 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900496}
497
Jiyong Parkd90d7412019-08-20 22:49:19 +0900498// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900499func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700500 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900501
502 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700503 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900504
Jiyong Park1112c4c2019-08-16 21:12:10 +0900505 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
506
Jiyong Park1e440682018-05-23 18:42:04 +0900507 for _, srcFile := range srcFiles {
508 switch srcFile.Ext() {
509 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700510 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900511 case ".logtags":
512 javaFile := genLogtags(ctx, srcFile)
513 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900514 default:
515 outSrcFiles = append(outSrcFiles, srcFile)
516 }
517 }
518
Colin Crossc0806172019-06-14 18:51:47 -0700519 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
520 if len(aidlSrcs) > 0 {
521 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
522 outSrcFiles = append(outSrcFiles, srcJarFiles...)
523 }
524
Jiyong Park1e440682018-05-23 18:42:04 +0900525 return outSrcFiles
526}
527
Nan Zhang581fd212018-01-10 16:06:12 -0800528func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
529 var deps deps
530
Colin Cross83bb3162018-06-25 15:48:06 -0700531 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800532 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700533 ctx.AddMissingDependencies(sdkDep.bootclasspath)
534 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800535 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700536 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000537 deps.aidlPreprocess = sdkDep.aidl
538 } else {
539 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800540 }
541
542 ctx.VisitDirectDeps(func(module android.Module) {
543 otherName := ctx.OtherModuleName(module)
544 tag := ctx.OtherModuleDependencyTag(module)
545
Colin Cross2d24c1b2018-05-23 10:59:18 -0700546 switch tag {
547 case bootClasspathTag:
548 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800549 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000550 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100551 // A system modules dependency has been added to the bootclasspath
552 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000553 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700554 } else {
555 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
556 }
557 case libTag:
558 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800559 case SdkLibraryDependency:
560 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700561 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900562 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900563 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700564 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800565 checkProducesJars(ctx, dep)
566 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800567 default:
568 ctx.ModuleErrorf("depends on non-java module %q", otherName)
569 }
Colin Cross6cef4812019-10-17 14:23:50 -0700570 case java9LibTag:
571 switch dep := module.(type) {
572 case Dependency:
573 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
574 default:
575 ctx.ModuleErrorf("depends on non-java module %q", otherName)
576 }
Nan Zhang357466b2018-04-17 17:38:36 -0700577 case systemModulesTag:
578 if deps.systemModules != nil {
579 panic("Found two system module dependencies")
580 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000581 sm := module.(SystemModulesProvider)
582 outputDir, outputDeps := sm.OutputDirAndDeps()
583 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800584 }
585 })
586 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
587 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800588 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900589
590 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
591 if filterPackages == nil {
592 return srcs
593 }
594 filtered := []android.Path{}
595 for _, src := range srcs {
596 if src.Ext() != ".java" {
597 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
598 // but otherwise metalava emits stub sources having references to the generated AIDL classes
599 // in filtered-out pacages (e.g. com.android.internal.*).
600 // TODO(b/141149570) We need to fix this by introducing default private constructors or
601 // fixing metalava to not emit constructors having references to unknown classes.
602 filtered = append(filtered, src)
603 continue
604 }
605 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800606 if android.HasAnyPrefix(packageName, filterPackages) {
607 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900608 }
609 }
610 return filtered
611 }
612 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
613
Nan Zhanga40da042018-08-01 12:48:00 -0700614 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900615 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800616
617 // srcs may depend on some genrule output.
618 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800619 j.srcJars = append(j.srcJars, deps.srcJars...)
620
Nan Zhang581fd212018-01-10 16:06:12 -0800621 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800622 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800623
Nan Zhang9c69a122018-08-22 10:22:08 -0700624 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800625 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
626 }
627 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800628
Colin Cross8a497952019-03-05 22:25:09 -0800629 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000630 argFilesMap := map[string]string{}
631 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700632
Paul Duffin99e4a502019-02-11 15:38:42 +0000633 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800634 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000635 if _, exists := argFilesMap[label]; !exists {
636 argFilesMap[label] = strings.Join(paths.Strings(), " ")
637 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700638 } else {
639 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000640 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700641 }
642 }
643
644 var err error
Colin Cross15638152019-07-11 11:11:35 -0700645 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700646 if strings.HasPrefix(name, "location ") {
647 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000648 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700649 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700650 } else {
Colin Cross15638152019-07-11 11:11:35 -0700651 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000652 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700653 }
654 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700655 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700656 }
Colin Cross15638152019-07-11 11:11:35 -0700657 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700658 })
659
660 if err != nil {
661 ctx.PropertyErrorf("args", "%s", err.Error())
662 }
663
Nan Zhang581fd212018-01-10 16:06:12 -0800664 return deps
665}
666
667func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
668 j.addDeps(ctx)
669}
670
671func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
672 deps := j.collectDeps(ctx)
673
Colin Crossdaa4c672019-07-15 22:53:46 -0700674 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800675
Colin Crossdaa4c672019-07-15 22:53:46 -0700676 outDir := android.PathForModuleOut(ctx, "out")
677 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
678
679 j.stubsSrcJar = nil
680
681 rule := android.NewRuleBuilder()
682
683 rule.Command().Text("rm -rf").Text(outDir.String())
684 rule.Command().Text("mkdir -p").Text(outDir.String())
685
686 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700687
Colin Cross83bb3162018-06-25 15:48:06 -0700688 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800689
Colin Crossdaa4c672019-07-15 22:53:46 -0700690 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
691 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800692
Colin Cross1e743852019-10-28 11:37:20 -0700693 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700694 Flag("-J-Xmx1024m").
695 Flag("-XDignore.symbol.file").
696 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800697
Colin Crossdaa4c672019-07-15 22:53:46 -0700698 rule.Command().
699 BuiltTool(ctx, "soong_zip").
700 Flag("-write_if_changed").
701 Flag("-d").
702 FlagWithOutput("-o ", j.docZip).
703 FlagWithArg("-C ", outDir.String()).
704 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700705
Colin Crossdaa4c672019-07-15 22:53:46 -0700706 rule.Restat()
707
708 zipSyncCleanupCmd(rule, srcJarDir)
709
710 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800711}
712
Nan Zhanga40da042018-08-01 12:48:00 -0700713//
714// Droiddoc
715//
716type Droiddoc struct {
717 Javadoc
718
719 properties DroiddocProperties
720 apiFile android.WritablePath
721 dexApiFile android.WritablePath
722 privateApiFile android.WritablePath
723 privateDexApiFile android.WritablePath
724 removedApiFile android.WritablePath
725 removedDexApiFile android.WritablePath
726 exactApiFile android.WritablePath
727 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700728 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700729
730 checkCurrentApiTimestamp android.WritablePath
731 updateCurrentApiTimestamp android.WritablePath
732 checkLastReleasedApiTimestamp android.WritablePath
733
Nan Zhanga40da042018-08-01 12:48:00 -0700734 apiFilePath android.Path
735}
736
Colin Crossa3002fc2019-07-08 16:48:04 -0700737// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700738func DroiddocFactory() android.Module {
739 module := &Droiddoc{}
740
741 module.AddProperties(&module.properties,
742 &module.Javadoc.properties)
743
744 InitDroiddocModule(module, android.HostAndDeviceSupported)
745 return module
746}
747
Colin Crossa3002fc2019-07-08 16:48:04 -0700748// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700749func DroiddocHostFactory() android.Module {
750 module := &Droiddoc{}
751
752 module.AddProperties(&module.properties,
753 &module.Javadoc.properties)
754
755 InitDroiddocModule(module, android.HostSupported)
756 return module
757}
758
759func (d *Droiddoc) ApiFilePath() android.Path {
760 return d.apiFilePath
761}
762
Nan Zhang581fd212018-01-10 16:06:12 -0800763func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
764 d.Javadoc.addDeps(ctx)
765
Inseob Kim38449af2019-02-28 14:24:05 +0900766 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
767 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
768 }
769
Nan Zhang79614d12018-04-19 18:03:39 -0700770 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800771 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
772 }
Nan Zhang581fd212018-01-10 16:06:12 -0800773}
774
Colin Crossab054432019-07-15 16:13:59 -0700775func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Nan Zhang443fa522018-08-20 20:58:28 -0700776 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
777 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
778 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700779 cmd.FlagWithArg("-source ", "1.8").
780 Flag("-J-Xmx1600m").
781 Flag("-J-XX:-OmitStackTraceInFastThrow").
782 Flag("-XDignore.symbol.file").
783 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
784 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
785 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-"+ctx.Config().BuildNumberFromFile()).
Elliott Hughes26bce342019-09-12 15:05:13 -0700786 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 -0700787
Nan Zhanga40da042018-08-01 12:48:00 -0700788 if String(d.properties.Custom_template) == "" {
789 // TODO: This is almost always droiddoc-templates-sdk
790 ctx.PropertyErrorf("custom_template", "must specify a template")
791 }
792
793 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700794 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700795 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700796 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000797 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700798 }
799 })
800
801 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700802 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
803 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
804 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700805 }
806
807 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700808 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
809 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
810 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700811 }
812
813 if len(d.properties.Html_dirs) > 2 {
814 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
815 }
816
Colin Cross8a497952019-03-05 22:25:09 -0800817 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700818 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700819
Colin Crossab054432019-07-15 16:13:59 -0700820 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700821
822 if String(d.properties.Proofread_file) != "" {
823 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700824 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700825 }
826
827 if String(d.properties.Todo_file) != "" {
828 // tricky part:
829 // we should not compute full path for todo_file through PathForModuleOut().
830 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700831 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
832 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700833 }
834
835 if String(d.properties.Resourcesdir) != "" {
836 // TODO: should we add files under resourcesDir to the implicits? It seems that
837 // resourcesDir is one sub dir of htmlDir
838 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700839 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700840 }
841
842 if String(d.properties.Resourcesoutdir) != "" {
843 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700844 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700845 }
Nan Zhanga40da042018-08-01 12:48:00 -0700846}
847
Colin Crossab054432019-07-15 16:13:59 -0700848func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200849 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
850 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700851 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700852
Nan Zhanga40da042018-08-01 12:48:00 -0700853 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700854 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700855 d.apiFilePath = d.apiFile
856 }
857
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200858 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
859 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700860 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700861 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700862 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700863 }
864
865 if String(d.properties.Private_api_filename) != "" {
866 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700867 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700868 }
869
870 if String(d.properties.Dex_api_filename) != "" {
871 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700872 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700873 }
874
875 if String(d.properties.Private_dex_api_filename) != "" {
876 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700877 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700878 }
879
880 if String(d.properties.Removed_dex_api_filename) != "" {
881 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700882 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700883 }
884
885 if String(d.properties.Exact_api_filename) != "" {
886 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700887 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700888 }
889
890 if String(d.properties.Dex_mapping_filename) != "" {
891 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700892 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700893 }
894
Nan Zhang66dc2362018-08-14 20:41:04 -0700895 if String(d.properties.Proguard_filename) != "" {
896 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700897 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700898 }
899
Nan Zhanga40da042018-08-01 12:48:00 -0700900 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700901 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700902 }
903
904 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700905 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700906 }
Nan Zhanga40da042018-08-01 12:48:00 -0700907}
908
Colin Crossab054432019-07-15 16:13:59 -0700909func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700910 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700911 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
912 rule.Command().Text("cp").
913 Input(staticDocIndexRedirect).
914 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700915 }
916
917 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700918 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
919 rule.Command().Text("cp").
920 Input(staticDocProperties).
921 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700922 }
Nan Zhanga40da042018-08-01 12:48:00 -0700923}
924
Colin Crossab054432019-07-15 16:13:59 -0700925func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700926 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700927
928 cmd := rule.Command().
929 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
930 Flag(config.JavacVmFlags).
931 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700932 FlagWithRspFileInputList("@", srcs).
933 FlagWithInput("@", srcJarList)
934
Colin Crossab054432019-07-15 16:13:59 -0700935 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
936 // based stubs generation.
937 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
938 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
939 // the correct package name base path.
940 if len(sourcepaths) > 0 {
941 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
942 } else {
943 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
944 }
945
946 cmd.FlagWithArg("-d ", outDir.String()).
947 Flag("-quiet")
948
949 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700950}
951
Colin Crossdaa4c672019-07-15 22:53:46 -0700952func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
953 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
954 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
955
956 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
957
958 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
959 cmd.Flag(flag).Implicits(deps)
960
961 cmd.FlagWithArg("--patch-module ", "java.base=.")
962
963 if len(classpath) > 0 {
964 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
965 }
966
967 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700968}
969
Colin Crossdaa4c672019-07-15 22:53:46 -0700970func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
971 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
972 sourcepaths android.Paths) *android.RuleBuilderCommand {
973
974 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
975
976 if len(bootclasspath) == 0 && ctx.Device() {
977 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
978 // ensure java does not fall back to the default bootclasspath.
979 cmd.FlagWithArg("-bootclasspath ", `""`)
980 } else if len(bootclasspath) > 0 {
981 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
982 }
983
984 if len(classpath) > 0 {
985 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
986 }
987
988 return cmd
989}
990
Colin Crossab054432019-07-15 16:13:59 -0700991func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
992 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700993
Colin Crossab054432019-07-15 16:13:59 -0700994 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
995 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
996
997 return rule.Command().
998 BuiltTool(ctx, "dokka").
999 Flag(config.JavacVmFlags).
1000 Flag(srcJarDir.String()).
1001 FlagWithInputList("-classpath ", dokkaClasspath, ":").
1002 FlagWithArg("-format ", "dac").
1003 FlagWithArg("-dacRoot ", "/reference/kotlin").
1004 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001005}
1006
1007func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1008 deps := d.Javadoc.collectDeps(ctx)
1009
Colin Crossdaa4c672019-07-15 22:53:46 -07001010 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
1011 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1012
Nan Zhang1598a9e2018-09-04 17:14:32 -07001013 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1014 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1015 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1016 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1017
Colin Crossab054432019-07-15 16:13:59 -07001018 outDir := android.PathForModuleOut(ctx, "out")
1019 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1020 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001021
Colin Crossab054432019-07-15 16:13:59 -07001022 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001023
Colin Crossab054432019-07-15 16:13:59 -07001024 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1025 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001026
Colin Crossab054432019-07-15 16:13:59 -07001027 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1028
1029 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001030 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001031 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001032 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001033 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001034 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001035 }
1036
Colin Crossab054432019-07-15 16:13:59 -07001037 d.stubsFlags(ctx, cmd, stubsDir)
1038
1039 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1040
Mathew Inwoodabd49ab2019-12-19 14:27:08 +00001041 if d.properties.Compat_config != nil {
1042 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
1043 cmd.FlagWithInput("-compatconfig ", compatConfig)
1044 }
1045
Colin Crossab054432019-07-15 16:13:59 -07001046 var desc string
1047 if Bool(d.properties.Dokka_enabled) {
1048 desc = "dokka"
1049 } else {
1050 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1051
1052 for _, o := range d.Javadoc.properties.Out {
1053 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1054 }
1055
1056 d.postDoclavaCmds(ctx, rule)
1057 desc = "doclava"
1058 }
1059
1060 rule.Command().
1061 BuiltTool(ctx, "soong_zip").
1062 Flag("-write_if_changed").
1063 Flag("-d").
1064 FlagWithOutput("-o ", d.docZip).
1065 FlagWithArg("-C ", outDir.String()).
1066 FlagWithArg("-D ", outDir.String())
1067
1068 rule.Command().
1069 BuiltTool(ctx, "soong_zip").
1070 Flag("-write_if_changed").
1071 Flag("-jar").
1072 FlagWithOutput("-o ", d.stubsSrcJar).
1073 FlagWithArg("-C ", stubsDir.String()).
1074 FlagWithArg("-D ", stubsDir.String())
1075
1076 rule.Restat()
1077
1078 zipSyncCleanupCmd(rule, srcJarDir)
1079
1080 rule.Build(pctx, ctx, "javadoc", desc)
1081
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001082 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001083 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001084
1085 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1086 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001087
1088 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001089
1090 rule := android.NewRuleBuilder()
1091
1092 rule.Command().Text("( true")
1093
1094 rule.Command().
1095 BuiltTool(ctx, "apicheck").
1096 Flag("-JXmx1024m").
1097 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1098 OptionalFlag(d.properties.Check_api.Current.Args).
1099 Input(apiFile).
1100 Input(d.apiFile).
1101 Input(removedApiFile).
1102 Input(d.removedApiFile)
1103
1104 msg := fmt.Sprintf(`\n******************************\n`+
1105 `You have tried to change the API from what has been previously approved.\n\n`+
1106 `To make these errors go away, you have two choices:\n`+
1107 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1108 ` errors above.\n\n`+
1109 ` 2. You can update current.txt by executing the following command:\n`+
1110 ` make %s-update-current-api\n\n`+
1111 ` To submit the revised current.txt to the main Android repository,\n`+
1112 ` you will need approval.\n`+
1113 `******************************\n`, ctx.ModuleName())
1114
1115 rule.Command().
1116 Text("touch").Output(d.checkCurrentApiTimestamp).
1117 Text(") || (").
1118 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1119 Text("; exit 38").
1120 Text(")")
1121
1122 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001123
1124 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001125
1126 // update API rule
1127 rule = android.NewRuleBuilder()
1128
1129 rule.Command().Text("( true")
1130
1131 rule.Command().
1132 Text("cp").Flag("-f").
1133 Input(d.apiFile).Flag(apiFile.String())
1134
1135 rule.Command().
1136 Text("cp").Flag("-f").
1137 Input(d.removedApiFile).Flag(removedApiFile.String())
1138
1139 msg = "failed to update public API"
1140
1141 rule.Command().
1142 Text("touch").Output(d.updateCurrentApiTimestamp).
1143 Text(") || (").
1144 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1145 Text("; exit 38").
1146 Text(")")
1147
1148 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001149 }
1150
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001151 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001152 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001153
1154 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1155 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001156
1157 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001158
1159 rule := android.NewRuleBuilder()
1160
1161 rule.Command().
1162 Text("(").
1163 BuiltTool(ctx, "apicheck").
1164 Flag("-JXmx1024m").
1165 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1166 OptionalFlag(d.properties.Check_api.Last_released.Args).
1167 Input(apiFile).
1168 Input(d.apiFile).
1169 Input(removedApiFile).
1170 Input(d.removedApiFile)
1171
1172 msg := `\n******************************\n` +
1173 `You have tried to change the API from what has been previously released in\n` +
1174 `an SDK. Please fix the errors listed above.\n` +
1175 `******************************\n`
1176
1177 rule.Command().
1178 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1179 Text(") || (").
1180 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1181 Text("; exit 38").
1182 Text(")")
1183
1184 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001185 }
1186}
1187
1188//
1189// Droidstubs
1190//
1191type Droidstubs struct {
1192 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001193 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001194
Pete Gillin581d6082018-10-22 15:55:04 +01001195 properties DroidstubsProperties
1196 apiFile android.WritablePath
1197 apiXmlFile android.WritablePath
1198 lastReleasedApiXmlFile android.WritablePath
1199 dexApiFile android.WritablePath
1200 privateApiFile android.WritablePath
1201 privateDexApiFile android.WritablePath
1202 removedApiFile android.WritablePath
1203 removedDexApiFile android.WritablePath
1204 apiMappingFile android.WritablePath
1205 exactApiFile android.WritablePath
1206 proguardFile android.WritablePath
1207 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001208
1209 checkCurrentApiTimestamp android.WritablePath
1210 updateCurrentApiTimestamp android.WritablePath
1211 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001212 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001213 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001214
Pete Gillin581d6082018-10-22 15:55:04 +01001215 checkNullabilityWarningsTimestamp android.WritablePath
1216
Nan Zhang1598a9e2018-09-04 17:14:32 -07001217 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001218 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001219
1220 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001221
1222 jdiffDocZip android.WritablePath
1223 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001224
1225 metadataZip android.WritablePath
1226 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001227}
1228
Colin Crossa3002fc2019-07-08 16:48:04 -07001229// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1230// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1231// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001232func DroidstubsFactory() android.Module {
1233 module := &Droidstubs{}
1234
1235 module.AddProperties(&module.properties,
1236 &module.Javadoc.properties)
1237
1238 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001239 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001240 return module
1241}
1242
Colin Crossa3002fc2019-07-08 16:48:04 -07001243// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1244// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1245// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1246// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001247func DroidstubsHostFactory() android.Module {
1248 module := &Droidstubs{}
1249
1250 module.AddProperties(&module.properties,
1251 &module.Javadoc.properties)
1252
1253 InitDroiddocModule(module, android.HostSupported)
1254 return module
1255}
1256
1257func (d *Droidstubs) ApiFilePath() android.Path {
1258 return d.apiFilePath
1259}
1260
1261func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1262 d.Javadoc.addDeps(ctx)
1263
Inseob Kim38449af2019-02-28 14:24:05 +09001264 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1265 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1266 }
1267
Nan Zhang1598a9e2018-09-04 17:14:32 -07001268 if len(d.properties.Merge_annotations_dirs) != 0 {
1269 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1270 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1271 }
1272 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001273
Pete Gillin77167902018-09-19 18:16:26 +01001274 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1275 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1276 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1277 }
1278 }
1279
Nan Zhang9c69a122018-08-22 10:22:08 -07001280 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1281 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1282 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1283 }
1284 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001285}
1286
Colin Cross33961b52019-07-11 11:01:22 -07001287func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001288 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1289 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001290 String(d.properties.Api_filename) != "" {
1291 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001292 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001293 d.apiFilePath = d.apiFile
1294 }
1295
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001296 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1297 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001298 String(d.properties.Removed_api_filename) != "" {
1299 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001300 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001301 }
1302
1303 if String(d.properties.Private_api_filename) != "" {
1304 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001305 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001306 }
1307
1308 if String(d.properties.Dex_api_filename) != "" {
1309 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001310 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001311 }
1312
1313 if String(d.properties.Private_dex_api_filename) != "" {
1314 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001315 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001316 }
1317
1318 if String(d.properties.Removed_dex_api_filename) != "" {
1319 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001320 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001321 }
1322
1323 if String(d.properties.Exact_api_filename) != "" {
1324 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001325 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 }
1327
Nan Zhang9c69a122018-08-22 10:22:08 -07001328 if String(d.properties.Dex_mapping_filename) != "" {
1329 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001330 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001331 }
1332
Nan Zhang199645c2018-09-19 12:40:06 -07001333 if String(d.properties.Proguard_filename) != "" {
1334 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001335 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001336 }
1337
Nan Zhang9c69a122018-08-22 10:22:08 -07001338 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001339 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1340 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001341 }
1342
Nan Zhang1598a9e2018-09-04 17:14:32 -07001343 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001344 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001345 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001346 cmd.FlagWithArg("--stubs ", stubsDir.String())
Aurimas Liutikas2d732e02020-03-11 16:28:05 -07001347 cmd.Flag("--exclude-documentation-from-stubs")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001348 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001349}
1350
Colin Cross33961b52019-07-11 11:01:22 -07001351func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001352 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001353 cmd.Flag("--include-annotations")
1354
Pete Gillinc382a562018-11-14 18:45:46 +00001355 validatingNullability :=
1356 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1357 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001358
Pete Gillina262c052018-09-14 14:25:48 +01001359 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001360 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001361 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001362 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001363 }
Colin Cross33961b52019-07-11 11:01:22 -07001364
Pete Gillinc382a562018-11-14 18:45:46 +00001365 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001366 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001367 }
Colin Cross33961b52019-07-11 11:01:22 -07001368
Pete Gillina262c052018-09-14 14:25:48 +01001369 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001370 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001371 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001372 }
Nan Zhanga40da042018-08-01 12:48:00 -07001373
1374 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001375 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001376
Nan Zhang1598a9e2018-09-04 17:14:32 -07001377 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001378 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001379 "has to be non-empty if annotations was enabled!")
1380 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001381
Colin Cross33961b52019-07-11 11:01:22 -07001382 d.mergeAnnoDirFlags(ctx, cmd)
1383
1384 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1385 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1386 FlagWithArg("--hide ", "SuperfluousPrefix").
1387 FlagWithArg("--hide ", "AnnotationExtraction")
1388 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001389}
1390
Colin Cross33961b52019-07-11 11:01:22 -07001391func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1392 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1393 if t, ok := m.(*ExportedDroiddocDir); ok {
1394 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1395 } else {
1396 ctx.PropertyErrorf("merge_annotations_dirs",
1397 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1398 }
1399 })
1400}
1401
1402func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001403 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1404 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001405 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001406 } else {
1407 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1408 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1409 }
1410 })
Nan Zhanga40da042018-08-01 12:48:00 -07001411}
1412
Colin Cross33961b52019-07-11 11:01:22 -07001413func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001414 if Bool(d.properties.Api_levels_annotations_enabled) {
1415 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001416
1417 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1418 ctx.PropertyErrorf("api_levels_annotations_dirs",
1419 "has to be non-empty if api levels annotations was enabled!")
1420 }
1421
Colin Cross33961b52019-07-11 11:01:22 -07001422 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1423 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1424 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1425 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001426
1427 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1428 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001429 for _, dep := range t.deps {
1430 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001431 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001432 }
1433 }
Colin Cross33961b52019-07-11 11:01:22 -07001434 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001435 } else {
1436 ctx.PropertyErrorf("api_levels_annotations_dirs",
1437 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1438 }
1439 })
1440
1441 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001442}
1443
Colin Cross33961b52019-07-11 11:01:22 -07001444func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001445 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1446 if d.apiFile.String() == "" {
1447 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1448 }
1449
1450 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001451 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001452
1453 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1454 ctx.PropertyErrorf("check_api.last_released.api_file",
1455 "has to be non-empty if jdiff was enabled!")
1456 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001457
Colin Cross33961b52019-07-11 11:01:22 -07001458 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001459 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001460 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1461 }
1462}
Nan Zhang71bbe632018-09-17 14:32:21 -07001463
Colin Cross1e743852019-10-28 11:37:20 -07001464func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001465 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001466 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1467 rule.HighMem()
Colin Cross33961b52019-07-11 11:01:22 -07001468 cmd := rule.Command().BuiltTool(ctx, "metalava").
1469 Flag(config.JavacVmFlags).
1470 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001471 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001472 FlagWithRspFileInputList("@", srcs).
1473 FlagWithInput("@", srcJarList)
1474
1475 if len(bootclasspath) > 0 {
1476 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001477 }
1478
Colin Cross33961b52019-07-11 11:01:22 -07001479 if len(classpath) > 0 {
1480 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1481 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001482
Colin Cross33961b52019-07-11 11:01:22 -07001483 if len(sourcepaths) > 0 {
1484 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1485 } else {
1486 cmd.FlagWithArg("-sourcepath ", `""`)
1487 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001488
Colin Cross33961b52019-07-11 11:01:22 -07001489 cmd.Flag("--no-banner").
1490 Flag("--color").
1491 Flag("--quiet").
1492 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001493
Colin Cross33961b52019-07-11 11:01:22 -07001494 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001495}
1496
Nan Zhang1598a9e2018-09-04 17:14:32 -07001497func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001498 deps := d.Javadoc.collectDeps(ctx)
1499
1500 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001501
Colin Cross33961b52019-07-11 11:01:22 -07001502 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001503
Colin Crossdaa4c672019-07-15 22:53:46 -07001504 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001505
Colin Cross33961b52019-07-11 11:01:22 -07001506 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1507 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001508
Colin Cross33961b52019-07-11 11:01:22 -07001509 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001510
Colin Cross33961b52019-07-11 11:01:22 -07001511 rule.Command().Text("rm -rf").Text(stubsDir.String())
1512 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001513
Colin Cross33961b52019-07-11 11:01:22 -07001514 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1515
1516 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1517 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1518
1519 d.stubsFlags(ctx, cmd, stubsDir)
1520
1521 d.annotationsFlags(ctx, cmd)
1522 d.inclusionAnnotationsFlags(ctx, cmd)
1523 d.apiLevelsAnnotationsFlags(ctx, cmd)
1524 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001525
Nan Zhang1598a9e2018-09-04 17:14:32 -07001526 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1527 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1528 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1529 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1530 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001531 }
Colin Cross33961b52019-07-11 11:01:22 -07001532
1533 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1534 for _, o := range d.Javadoc.properties.Out {
1535 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1536 }
1537
1538 rule.Command().
1539 BuiltTool(ctx, "soong_zip").
1540 Flag("-write_if_changed").
1541 Flag("-jar").
1542 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1543 FlagWithArg("-C ", stubsDir.String()).
1544 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001545
1546 if Bool(d.properties.Write_sdk_values) {
1547 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1548 rule.Command().
1549 BuiltTool(ctx, "soong_zip").
1550 Flag("-write_if_changed").
1551 Flag("-d").
1552 FlagWithOutput("-o ", d.metadataZip).
1553 FlagWithArg("-C ", d.metadataDir.String()).
1554 FlagWithArg("-D ", d.metadataDir.String())
1555 }
1556
Colin Cross33961b52019-07-11 11:01:22 -07001557 rule.Restat()
1558
1559 zipSyncCleanupCmd(rule, srcJarDir)
1560
1561 rule.Build(pctx, ctx, "metalava", "metalava")
1562
1563 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001564
Adrian Roos075eedc2019-10-10 12:07:03 +02001565 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1566 rule := android.NewRuleBuilder()
1567 rule.Command().Text("( true")
1568
1569 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1570 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1571
1572 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1573 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1574
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001575 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1576
Adrian Roos075eedc2019-10-10 12:07:03 +02001577 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1578 if newSince.Valid() {
1579 cmd.FlagWithInput("--api-lint ", newSince.Path())
1580 } else {
1581 cmd.Flag("--api-lint")
1582 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001583 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1584 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001585
1586 d.inclusionAnnotationsFlags(ctx, cmd)
1587 d.mergeAnnoDirFlags(ctx, cmd)
1588
1589 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1590 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1591 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1592
1593 if baselineFile.Valid() {
1594 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1595 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1596 }
1597
1598 zipSyncCleanupCmd(rule, srcJarDir)
1599
1600 msg := fmt.Sprintf(`\n******************************\n`+
1601 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1602 `To make these errors go away, you have two choices:\n`+
1603 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1604 ` 2. You can update the baseline by executing the following command:\n`+
1605 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1606 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1607 rule.Command().
1608 Text("touch").Output(d.apiLintTimestamp).
1609 Text(") || (").
1610 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1611 Text("; exit 38").
1612 Text(")")
1613
1614 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1615
1616 }
1617
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001618 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001619 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001620
1621 if len(d.Javadoc.properties.Out) > 0 {
1622 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1623 }
1624
1625 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1626 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001627 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1628 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001629
Nan Zhang2760dfc2018-08-24 17:32:54 +00001630 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001631
Colin Cross33961b52019-07-11 11:01:22 -07001632 rule := android.NewRuleBuilder()
1633
1634 rule.Command().Text("( true")
1635
1636 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1637 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1638
1639 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1640 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1641
1642 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1643 FlagWithInput("--check-compatibility:api:current ", apiFile).
1644 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1645
1646 d.inclusionAnnotationsFlags(ctx, cmd)
1647 d.mergeAnnoDirFlags(ctx, cmd)
1648
Adrian Roos14f75a92019-08-12 17:54:09 +02001649 if baselineFile.Valid() {
1650 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1651 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1652 }
1653
Colin Cross33961b52019-07-11 11:01:22 -07001654 zipSyncCleanupCmd(rule, srcJarDir)
1655
1656 msg := fmt.Sprintf(`\n******************************\n`+
1657 `You have tried to change the API from what has been previously approved.\n\n`+
1658 `To make these errors go away, you have two choices:\n`+
1659 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1660 ` errors above.\n\n`+
1661 ` 2. You can update current.txt by executing the following command:\n`+
1662 ` make %s-update-current-api\n\n`+
1663 ` To submit the revised current.txt to the main Android repository,\n`+
1664 ` you will need approval.\n`+
1665 `******************************\n`, ctx.ModuleName())
1666
1667 rule.Command().
1668 Text("touch").Output(d.checkCurrentApiTimestamp).
1669 Text(") || (").
1670 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1671 Text("; exit 38").
1672 Text(")")
1673
1674 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001675
1676 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001677
1678 // update API rule
1679 rule = android.NewRuleBuilder()
1680
1681 rule.Command().Text("( true")
1682
1683 rule.Command().
1684 Text("cp").Flag("-f").
1685 Input(d.apiFile).Flag(apiFile.String())
1686
1687 rule.Command().
1688 Text("cp").Flag("-f").
1689 Input(d.removedApiFile).Flag(removedApiFile.String())
1690
1691 msg = "failed to update public API"
1692
1693 rule.Command().
1694 Text("touch").Output(d.updateCurrentApiTimestamp).
1695 Text(") || (").
1696 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1697 Text("; exit 38").
1698 Text(")")
1699
1700 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001701 }
Nan Zhanga40da042018-08-01 12:48:00 -07001702
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001703 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001704 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001705
1706 if len(d.Javadoc.properties.Out) > 0 {
1707 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1708 }
1709
1710 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1711 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001712 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1713 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001714
Nan Zhang2760dfc2018-08-24 17:32:54 +00001715 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001716
Colin Cross33961b52019-07-11 11:01:22 -07001717 rule := android.NewRuleBuilder()
1718
1719 rule.Command().Text("( true")
1720
1721 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1722 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1723
1724 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1725 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1726
1727 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1728 FlagWithInput("--check-compatibility:api:released ", apiFile)
1729
1730 d.inclusionAnnotationsFlags(ctx, cmd)
1731
1732 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1733
1734 d.mergeAnnoDirFlags(ctx, cmd)
1735
Adrian Roos14f75a92019-08-12 17:54:09 +02001736 if baselineFile.Valid() {
1737 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1738 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1739 }
1740
Colin Cross33961b52019-07-11 11:01:22 -07001741 zipSyncCleanupCmd(rule, srcJarDir)
1742
1743 msg := `\n******************************\n` +
1744 `You have tried to change the API from what has been previously released in\n` +
1745 `an SDK. Please fix the errors listed above.\n` +
1746 `******************************\n`
1747 rule.Command().
1748 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1749 Text(") || (").
1750 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1751 Text("; exit 38").
1752 Text(")")
1753
1754 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001755 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001756
Pete Gillin581d6082018-10-22 15:55:04 +01001757 if String(d.properties.Check_nullability_warnings) != "" {
1758 if d.nullabilityWarningsFile == nil {
1759 ctx.PropertyErrorf("check_nullability_warnings",
1760 "Cannot specify check_nullability_warnings unless validating nullability")
1761 }
Colin Cross33961b52019-07-11 11:01:22 -07001762
1763 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1764
Pete Gillin581d6082018-10-22 15:55:04 +01001765 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001766
Pete Gillin581d6082018-10-22 15:55:04 +01001767 msg := fmt.Sprintf(`\n******************************\n`+
1768 `The warnings encountered during nullability annotation validation did\n`+
1769 `not match the checked in file of expected warnings. The diffs are shown\n`+
1770 `above. You have two options:\n`+
1771 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1772 ` 2. Update the file of expected warnings by running:\n`+
1773 ` cp %s %s\n`+
1774 ` and submitting the updated file as part of your change.`,
1775 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001776
1777 rule := android.NewRuleBuilder()
1778
1779 rule.Command().
1780 Text("(").
1781 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1782 Text("&&").
1783 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1784 Text(") || (").
1785 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1786 Text("; exit 38").
1787 Text(")")
1788
1789 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001790 }
1791
Nan Zhang71bbe632018-09-17 14:32:21 -07001792 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001793 if len(d.Javadoc.properties.Out) > 0 {
1794 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1795 }
1796
1797 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1798 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1799 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1800
1801 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001802
Nan Zhang86b06202018-09-21 17:09:21 -07001803 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1804 // since there's cron job downstream that fetch this .zip file periodically.
1805 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001806 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1807 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1808
Nan Zhang71bbe632018-09-17 14:32:21 -07001809 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001810
Colin Cross33961b52019-07-11 11:01:22 -07001811 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1812 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001813
Colin Cross33961b52019-07-11 11:01:22 -07001814 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1815
Colin Crossdaa4c672019-07-15 22:53:46 -07001816 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001817 deps.bootClasspath, deps.classpath, d.sourcepaths)
1818
1819 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001820 Flag("-XDignore.symbol.file").
1821 FlagWithArg("-doclet ", "jdiff.JDiff").
1822 FlagWithInput("-docletpath ", jdiff).
1823 Flag("-quiet").
1824 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1825 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1826 Implicit(d.apiXmlFile).
1827 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1828 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1829 Implicit(d.lastReleasedApiXmlFile)
1830
Colin Cross33961b52019-07-11 11:01:22 -07001831 rule.Command().
1832 BuiltTool(ctx, "soong_zip").
1833 Flag("-write_if_changed").
1834 Flag("-d").
1835 FlagWithOutput("-o ", d.jdiffDocZip).
1836 FlagWithArg("-C ", outDir.String()).
1837 FlagWithArg("-D ", outDir.String())
1838
1839 rule.Command().
1840 BuiltTool(ctx, "soong_zip").
1841 Flag("-write_if_changed").
1842 Flag("-jar").
1843 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1844 FlagWithArg("-C ", stubsDir.String()).
1845 FlagWithArg("-D ", stubsDir.String())
1846
1847 rule.Restat()
1848
1849 zipSyncCleanupCmd(rule, srcJarDir)
1850
1851 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001852 }
Nan Zhang581fd212018-01-10 16:06:12 -08001853}
Dan Willemsencc090972018-02-26 14:33:31 -08001854
Nan Zhanga40da042018-08-01 12:48:00 -07001855//
Nan Zhangf4936b02018-08-01 15:00:28 -07001856// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001857//
Dan Willemsencc090972018-02-26 14:33:31 -08001858var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001859var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001860var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001861var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001862
Nan Zhangf4936b02018-08-01 15:00:28 -07001863type ExportedDroiddocDirProperties struct {
1864 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001865 Path *string
1866}
1867
Nan Zhangf4936b02018-08-01 15:00:28 -07001868type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001869 android.ModuleBase
1870
Nan Zhangf4936b02018-08-01 15:00:28 -07001871 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001872
1873 deps android.Paths
1874 dir android.Path
1875}
1876
Colin Crossa3002fc2019-07-08 16:48:04 -07001877// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001878func ExportedDroiddocDirFactory() android.Module {
1879 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001880 module.AddProperties(&module.properties)
1881 android.InitAndroidModule(module)
1882 return module
1883}
1884
Nan Zhangf4936b02018-08-01 15:00:28 -07001885func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001886
Nan Zhangf4936b02018-08-01 15:00:28 -07001887func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001888 path := String(d.properties.Path)
1889 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001890 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001891}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001892
1893//
1894// Defaults
1895//
1896type DocDefaults struct {
1897 android.ModuleBase
1898 android.DefaultsModuleBase
1899}
1900
Nan Zhangb2b33de2018-02-23 11:18:47 -08001901func DocDefaultsFactory() android.Module {
1902 module := &DocDefaults{}
1903
1904 module.AddProperties(
1905 &JavadocProperties{},
1906 &DroiddocProperties{},
1907 )
1908
1909 android.InitDefaultsModule(module)
1910
1911 return module
1912}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001913
1914func StubsDefaultsFactory() android.Module {
1915 module := &DocDefaults{}
1916
1917 module.AddProperties(
1918 &JavadocProperties{},
1919 &DroidstubsProperties{},
1920 )
1921
1922 android.InitDefaultsModule(module)
1923
1924 return module
1925}
Colin Cross33961b52019-07-11 11:01:22 -07001926
1927func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1928 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1929
1930 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1931 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1932 srcJarList := srcJarDir.Join(ctx, "list")
1933
1934 rule.Temporary(srcJarList)
1935
1936 rule.Command().BuiltTool(ctx, "zipsync").
1937 FlagWithArg("-d ", srcJarDir.String()).
1938 FlagWithOutput("-l ", srcJarList).
1939 FlagWithArg("-f ", `"*.java"`).
1940 Inputs(srcJars)
1941
1942 return srcJarList
1943}
1944
1945func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1946 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1947}
Paul Duffin91547182019-11-12 19:39:36 +00001948
1949var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1950
1951type PrebuiltStubsSourcesProperties struct {
1952 Srcs []string `android:"path"`
1953}
1954
1955type PrebuiltStubsSources struct {
1956 android.ModuleBase
1957 android.DefaultableModuleBase
1958 prebuilt android.Prebuilt
1959 android.SdkBase
1960
1961 properties PrebuiltStubsSourcesProperties
1962
Paul Duffin9b478b02019-12-10 13:41:51 +00001963 // The source directories containing stubs source files.
1964 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001965 stubsSrcJar android.ModuleOutPath
1966}
1967
Paul Duffin9b478b02019-12-10 13:41:51 +00001968func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1969 switch tag {
1970 case "":
1971 return android.Paths{p.stubsSrcJar}, nil
1972 default:
1973 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1974 }
1975}
1976
Paul Duffin91547182019-11-12 19:39:36 +00001977func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001978 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1979
1980 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1981
1982 rule := android.NewRuleBuilder()
1983 command := rule.Command().
1984 BuiltTool(ctx, "soong_zip").
1985 Flag("-write_if_changed").
1986 Flag("-jar").
1987 FlagWithOutput("-o ", p.stubsSrcJar)
1988
1989 for _, d := range p.srcDirs {
1990 dir := d.String()
1991 command.
1992 FlagWithArg("-C ", dir).
1993 FlagWithInput("-D ", d)
1994 }
1995
1996 rule.Restat()
1997
1998 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00001999}
2000
2001func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
2002 return &p.prebuilt
2003}
2004
2005func (p *PrebuiltStubsSources) Name() string {
2006 return p.prebuilt.Name(p.ModuleBase.Name())
2007}
2008
Paul Duffin91547182019-11-12 19:39:36 +00002009// prebuilt_stubs_sources imports a set of java source files as if they were
2010// generated by droidstubs.
2011//
2012// By default, a prebuilt_stubs_sources has a single variant that expects a
2013// set of `.java` files generated by droidstubs.
2014//
2015// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2016// for host modules.
2017//
2018// Intended only for use by sdk snapshots.
2019func PrebuiltStubsSourcesFactory() android.Module {
2020 module := &PrebuiltStubsSources{}
2021
2022 module.AddProperties(&module.properties)
2023
2024 android.InitPrebuiltModule(module, &module.properties.Srcs)
2025 android.InitSdkAwareModule(module)
2026 InitDroiddocModule(module, android.HostAndDeviceSupported)
2027 return module
2028}
2029
Paul Duffin13879572019-11-28 14:31:38 +00002030type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00002031 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00002032}
2033
2034func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2035 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2036}
2037
2038func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
2039 _, ok := module.(*Droidstubs)
2040 return ok
2041}
2042
2043func (mt *droidStubsSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
2044 variants := member.Variants()
2045 if len(variants) != 1 {
2046 sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
2047 }
2048 variant := variants[0]
2049 d, _ := variant.(*Droidstubs)
Paul Duffin91547182019-11-12 19:39:36 +00002050 stubsSrcJar := d.stubsSrcJar
2051
2052 snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
2053 builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
2054
Paul Duffin9d8d6092019-12-05 18:19:29 +00002055 pbm := builder.AddPrebuiltModule(member, "prebuilt_stubs_sources")
Paul Duffinb645ec82019-11-27 17:43:54 +00002056 pbm.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin91547182019-11-12 19:39:36 +00002057}