blob: 6c3c7ec842d80a43ce045499103324dc186e53bb [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
Paul Duffin3d1248c2020-04-09 00:10:17 +0100373// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700374type ApiFilePath interface {
375 ApiFilePath() android.Path
376}
377
Paul Duffin3d1248c2020-04-09 00:10:17 +0100378// Provider of information about API stubs, used by java_sdk_library.
379type ApiStubsProvider interface {
380 ApiFilePath
381 StubsSrcJar() android.Path
382}
383
Nan Zhanga40da042018-08-01 12:48:00 -0700384//
385// Javadoc
386//
Nan Zhang581fd212018-01-10 16:06:12 -0800387type Javadoc struct {
388 android.ModuleBase
389 android.DefaultableModuleBase
390
391 properties JavadocProperties
392
393 srcJars android.Paths
394 srcFiles android.Paths
395 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700396 argFiles android.Paths
397
398 args string
Nan Zhang581fd212018-01-10 16:06:12 -0800399
Nan Zhangccff0f72018-03-08 17:26:16 -0800400 docZip android.WritablePath
401 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800402}
403
Colin Cross41955e82019-05-29 14:40:35 -0700404func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
405 switch tag {
406 case "":
407 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700408 case ".docs.zip":
409 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700410 default:
411 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
412 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800413}
414
Colin Crossa3002fc2019-07-08 16:48:04 -0700415// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800416func JavadocFactory() android.Module {
417 module := &Javadoc{}
418
419 module.AddProperties(&module.properties)
420
421 InitDroiddocModule(module, android.HostAndDeviceSupported)
422 return module
423}
424
Colin Crossa3002fc2019-07-08 16:48:04 -0700425// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800426func JavadocHostFactory() android.Module {
427 module := &Javadoc{}
428
429 module.AddProperties(&module.properties)
430
431 InitDroiddocModule(module, android.HostSupported)
432 return module
433}
434
Colin Cross41955e82019-05-29 14:40:35 -0700435var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800436
Jiyong Park6a927c42020-01-21 02:03:43 +0900437func (j *Javadoc) sdkVersion() sdkSpec {
438 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700439}
440
Paul Duffine25c6442019-10-11 13:50:28 +0100441func (j *Javadoc) systemModules() string {
442 return proptools.String(j.properties.System_modules)
443}
444
Jiyong Park6a927c42020-01-21 02:03:43 +0900445func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700446 return j.sdkVersion()
447}
448
Jiyong Park6a927c42020-01-21 02:03:43 +0900449func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700450 return j.sdkVersion()
451}
452
Nan Zhang581fd212018-01-10 16:06:12 -0800453func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
454 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100455 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Colin Cross6d8d8c62019-10-28 15:10:03 -0700456 if sdkDep.useDefaultLibs {
457 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
458 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
459 if sdkDep.hasFrameworkLibs() {
460 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700461 }
Colin Cross6d8d8c62019-10-28 15:10:03 -0700462 } else if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700463 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100464 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700465 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800466 }
467 }
468
Colin Cross42d48b72018-08-29 14:10:52 -0700469 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800470}
471
Nan Zhanga40da042018-08-01 12:48:00 -0700472func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
473 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900474
Colin Cross3047fa22019-04-18 10:56:44 -0700475 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900476
477 return flags
478}
479
480func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700481 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900482
483 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
484 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
485
486 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700487 var deps android.Paths
488
Jiyong Park1e440682018-05-23 18:42:04 +0900489 if aidlPreprocess.Valid() {
490 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700491 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900492 } else {
493 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
494 }
495
496 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
497 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
498 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
499 flags = append(flags, "-I"+src.String())
500 }
501
Colin Cross3047fa22019-04-18 10:56:44 -0700502 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900503}
504
Jiyong Parkd90d7412019-08-20 22:49:19 +0900505// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900506func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700507 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900508
509 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700510 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900511
Jiyong Park1112c4c2019-08-16 21:12:10 +0900512 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
513
Jiyong Park1e440682018-05-23 18:42:04 +0900514 for _, srcFile := range srcFiles {
515 switch srcFile.Ext() {
516 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700517 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900518 case ".logtags":
519 javaFile := genLogtags(ctx, srcFile)
520 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900521 default:
522 outSrcFiles = append(outSrcFiles, srcFile)
523 }
524 }
525
Colin Crossc0806172019-06-14 18:51:47 -0700526 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
527 if len(aidlSrcs) > 0 {
528 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
529 outSrcFiles = append(outSrcFiles, srcJarFiles...)
530 }
531
Jiyong Park1e440682018-05-23 18:42:04 +0900532 return outSrcFiles
533}
534
Nan Zhang581fd212018-01-10 16:06:12 -0800535func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
536 var deps deps
537
Colin Cross83bb3162018-06-25 15:48:06 -0700538 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800539 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700540 ctx.AddMissingDependencies(sdkDep.bootclasspath)
541 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800542 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700543 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000544 deps.aidlPreprocess = sdkDep.aidl
545 } else {
546 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800547 }
548
549 ctx.VisitDirectDeps(func(module android.Module) {
550 otherName := ctx.OtherModuleName(module)
551 tag := ctx.OtherModuleDependencyTag(module)
552
Colin Cross2d24c1b2018-05-23 10:59:18 -0700553 switch tag {
554 case bootClasspathTag:
555 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800556 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000557 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100558 // A system modules dependency has been added to the bootclasspath
559 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000560 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700561 } else {
562 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
563 }
564 case libTag:
565 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800566 case SdkLibraryDependency:
567 deps.classpath = append(deps.classpath, dep.SdkImplementationJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700568 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900569 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900570 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700571 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800572 checkProducesJars(ctx, dep)
573 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800574 default:
575 ctx.ModuleErrorf("depends on non-java module %q", otherName)
576 }
Colin Cross6cef4812019-10-17 14:23:50 -0700577 case java9LibTag:
578 switch dep := module.(type) {
579 case Dependency:
580 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
581 default:
582 ctx.ModuleErrorf("depends on non-java module %q", otherName)
583 }
Nan Zhang357466b2018-04-17 17:38:36 -0700584 case systemModulesTag:
585 if deps.systemModules != nil {
586 panic("Found two system module dependencies")
587 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000588 sm := module.(SystemModulesProvider)
589 outputDir, outputDeps := sm.OutputDirAndDeps()
590 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800591 }
592 })
593 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
594 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800595 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900596
597 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
598 if filterPackages == nil {
599 return srcs
600 }
601 filtered := []android.Path{}
602 for _, src := range srcs {
603 if src.Ext() != ".java" {
604 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
605 // but otherwise metalava emits stub sources having references to the generated AIDL classes
606 // in filtered-out pacages (e.g. com.android.internal.*).
607 // TODO(b/141149570) We need to fix this by introducing default private constructors or
608 // fixing metalava to not emit constructors having references to unknown classes.
609 filtered = append(filtered, src)
610 continue
611 }
612 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800613 if android.HasAnyPrefix(packageName, filterPackages) {
614 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900615 }
616 }
617 return filtered
618 }
619 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
620
Nan Zhanga40da042018-08-01 12:48:00 -0700621 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900622 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800623
624 // srcs may depend on some genrule output.
625 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800626 j.srcJars = append(j.srcJars, deps.srcJars...)
627
Nan Zhang581fd212018-01-10 16:06:12 -0800628 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800629 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800630
Nan Zhang9c69a122018-08-22 10:22:08 -0700631 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800632 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
633 }
634 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800635
Colin Cross8a497952019-03-05 22:25:09 -0800636 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000637 argFilesMap := map[string]string{}
638 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700639
Paul Duffin99e4a502019-02-11 15:38:42 +0000640 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800641 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000642 if _, exists := argFilesMap[label]; !exists {
643 argFilesMap[label] = strings.Join(paths.Strings(), " ")
644 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700645 } else {
646 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000647 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700648 }
649 }
650
651 var err error
Colin Cross15638152019-07-11 11:11:35 -0700652 j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700653 if strings.HasPrefix(name, "location ") {
654 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
Paul Duffin99e4a502019-02-11 15:38:42 +0000655 if paths, ok := argFilesMap[label]; ok {
Colin Cross15638152019-07-11 11:11:35 -0700656 return paths, nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700657 } else {
Colin Cross15638152019-07-11 11:11:35 -0700658 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000659 label, strings.Join(argFileLabels, ", "))
Nan Zhang1598a9e2018-09-04 17:14:32 -0700660 }
661 } else if name == "genDir" {
Colin Cross15638152019-07-11 11:11:35 -0700662 return android.PathForModuleGen(ctx).String(), nil
Nan Zhang1598a9e2018-09-04 17:14:32 -0700663 }
Colin Cross15638152019-07-11 11:11:35 -0700664 return "", fmt.Errorf("unknown variable '$(%s)'", name)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700665 })
666
667 if err != nil {
668 ctx.PropertyErrorf("args", "%s", err.Error())
669 }
670
Nan Zhang581fd212018-01-10 16:06:12 -0800671 return deps
672}
673
674func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
675 j.addDeps(ctx)
676}
677
678func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
679 deps := j.collectDeps(ctx)
680
Colin Crossdaa4c672019-07-15 22:53:46 -0700681 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800682
Colin Crossdaa4c672019-07-15 22:53:46 -0700683 outDir := android.PathForModuleOut(ctx, "out")
684 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
685
686 j.stubsSrcJar = nil
687
688 rule := android.NewRuleBuilder()
689
690 rule.Command().Text("rm -rf").Text(outDir.String())
691 rule.Command().Text("mkdir -p").Text(outDir.String())
692
693 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700694
Colin Cross83bb3162018-06-25 15:48:06 -0700695 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800696
Colin Crossdaa4c672019-07-15 22:53:46 -0700697 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
698 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800699
Colin Cross1e743852019-10-28 11:37:20 -0700700 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700701 Flag("-J-Xmx1024m").
702 Flag("-XDignore.symbol.file").
703 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800704
Colin Crossdaa4c672019-07-15 22:53:46 -0700705 rule.Command().
706 BuiltTool(ctx, "soong_zip").
707 Flag("-write_if_changed").
708 Flag("-d").
709 FlagWithOutput("-o ", j.docZip).
710 FlagWithArg("-C ", outDir.String()).
711 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700712
Colin Crossdaa4c672019-07-15 22:53:46 -0700713 rule.Restat()
714
715 zipSyncCleanupCmd(rule, srcJarDir)
716
717 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800718}
719
Nan Zhanga40da042018-08-01 12:48:00 -0700720//
721// Droiddoc
722//
723type Droiddoc struct {
724 Javadoc
725
726 properties DroiddocProperties
727 apiFile android.WritablePath
728 dexApiFile android.WritablePath
729 privateApiFile android.WritablePath
730 privateDexApiFile android.WritablePath
731 removedApiFile android.WritablePath
732 removedDexApiFile android.WritablePath
733 exactApiFile android.WritablePath
734 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700735 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700736
737 checkCurrentApiTimestamp android.WritablePath
738 updateCurrentApiTimestamp android.WritablePath
739 checkLastReleasedApiTimestamp android.WritablePath
740
Nan Zhanga40da042018-08-01 12:48:00 -0700741 apiFilePath android.Path
742}
743
Colin Crossa3002fc2019-07-08 16:48:04 -0700744// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700745func DroiddocFactory() android.Module {
746 module := &Droiddoc{}
747
748 module.AddProperties(&module.properties,
749 &module.Javadoc.properties)
750
751 InitDroiddocModule(module, android.HostAndDeviceSupported)
752 return module
753}
754
Colin Crossa3002fc2019-07-08 16:48:04 -0700755// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700756func DroiddocHostFactory() android.Module {
757 module := &Droiddoc{}
758
759 module.AddProperties(&module.properties,
760 &module.Javadoc.properties)
761
762 InitDroiddocModule(module, android.HostSupported)
763 return module
764}
765
766func (d *Droiddoc) ApiFilePath() android.Path {
767 return d.apiFilePath
768}
769
Nan Zhang581fd212018-01-10 16:06:12 -0800770func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
771 d.Javadoc.addDeps(ctx)
772
Inseob Kim38449af2019-02-28 14:24:05 +0900773 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
774 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
775 }
776
Nan Zhang79614d12018-04-19 18:03:39 -0700777 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800778 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
779 }
Nan Zhang581fd212018-01-10 16:06:12 -0800780}
781
Colin Crossab054432019-07-15 16:13:59 -0700782func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800783 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700784 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
785 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
786 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700787 cmd.FlagWithArg("-source ", "1.8").
788 Flag("-J-Xmx1600m").
789 Flag("-J-XX:-OmitStackTraceInFastThrow").
790 Flag("-XDignore.symbol.file").
791 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
792 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800793 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700794 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 -0700795
Nan Zhanga40da042018-08-01 12:48:00 -0700796 if String(d.properties.Custom_template) == "" {
797 // TODO: This is almost always droiddoc-templates-sdk
798 ctx.PropertyErrorf("custom_template", "must specify a template")
799 }
800
801 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700802 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700803 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700804 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000805 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700806 }
807 })
808
809 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700810 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
811 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
812 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700813 }
814
815 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700816 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
817 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
818 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700819 }
820
821 if len(d.properties.Html_dirs) > 2 {
822 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
823 }
824
Colin Cross8a497952019-03-05 22:25:09 -0800825 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700826 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700827
Colin Crossab054432019-07-15 16:13:59 -0700828 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700829
830 if String(d.properties.Proofread_file) != "" {
831 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700832 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700833 }
834
835 if String(d.properties.Todo_file) != "" {
836 // tricky part:
837 // we should not compute full path for todo_file through PathForModuleOut().
838 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700839 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
840 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700841 }
842
843 if String(d.properties.Resourcesdir) != "" {
844 // TODO: should we add files under resourcesDir to the implicits? It seems that
845 // resourcesDir is one sub dir of htmlDir
846 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700847 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700848 }
849
850 if String(d.properties.Resourcesoutdir) != "" {
851 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700852 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700853 }
Nan Zhanga40da042018-08-01 12:48:00 -0700854}
855
Colin Crossab054432019-07-15 16:13:59 -0700856func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200857 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
858 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700859 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700860
Nan Zhanga40da042018-08-01 12:48:00 -0700861 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700862 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700863 d.apiFilePath = d.apiFile
864 }
865
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200866 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
867 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700868 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700869 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700870 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700871 }
872
873 if String(d.properties.Private_api_filename) != "" {
874 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700875 cmd.FlagWithOutput("-privateApi ", d.privateApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700876 }
877
878 if String(d.properties.Dex_api_filename) != "" {
879 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700880 cmd.FlagWithOutput("-dexApi ", d.dexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700881 }
882
883 if String(d.properties.Private_dex_api_filename) != "" {
884 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700885 cmd.FlagWithOutput("-privateDexApi ", d.privateDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700886 }
887
888 if String(d.properties.Removed_dex_api_filename) != "" {
889 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700890 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700891 }
892
893 if String(d.properties.Exact_api_filename) != "" {
894 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700895 cmd.FlagWithOutput("-exactApi ", d.exactApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700896 }
897
898 if String(d.properties.Dex_mapping_filename) != "" {
899 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Crossab054432019-07-15 16:13:59 -0700900 cmd.FlagWithOutput("-apiMapping ", d.apiMappingFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700901 }
902
Nan Zhang66dc2362018-08-14 20:41:04 -0700903 if String(d.properties.Proguard_filename) != "" {
904 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Crossab054432019-07-15 16:13:59 -0700905 cmd.FlagWithOutput("-proguard ", d.proguardFile)
Nan Zhang66dc2362018-08-14 20:41:04 -0700906 }
907
Nan Zhanga40da042018-08-01 12:48:00 -0700908 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700909 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700910 }
911
912 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700913 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700914 }
Nan Zhanga40da042018-08-01 12:48:00 -0700915}
916
Colin Crossab054432019-07-15 16:13:59 -0700917func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700918 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700919 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
920 rule.Command().Text("cp").
921 Input(staticDocIndexRedirect).
922 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700923 }
924
925 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700926 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
927 rule.Command().Text("cp").
928 Input(staticDocProperties).
929 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700930 }
Nan Zhanga40da042018-08-01 12:48:00 -0700931}
932
Colin Crossab054432019-07-15 16:13:59 -0700933func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700934 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700935
936 cmd := rule.Command().
937 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
938 Flag(config.JavacVmFlags).
939 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700940 FlagWithRspFileInputList("@", srcs).
941 FlagWithInput("@", srcJarList)
942
Colin Crossab054432019-07-15 16:13:59 -0700943 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
944 // based stubs generation.
945 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
946 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
947 // the correct package name base path.
948 if len(sourcepaths) > 0 {
949 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
950 } else {
951 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
952 }
953
954 cmd.FlagWithArg("-d ", outDir.String()).
955 Flag("-quiet")
956
957 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700958}
959
Colin Crossdaa4c672019-07-15 22:53:46 -0700960func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
961 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
962 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
963
964 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
965
966 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
967 cmd.Flag(flag).Implicits(deps)
968
969 cmd.FlagWithArg("--patch-module ", "java.base=.")
970
971 if len(classpath) > 0 {
972 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
973 }
974
975 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700976}
977
Colin Crossdaa4c672019-07-15 22:53:46 -0700978func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
979 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
980 sourcepaths android.Paths) *android.RuleBuilderCommand {
981
982 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
983
984 if len(bootclasspath) == 0 && ctx.Device() {
985 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
986 // ensure java does not fall back to the default bootclasspath.
987 cmd.FlagWithArg("-bootclasspath ", `""`)
988 } else if len(bootclasspath) > 0 {
989 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
990 }
991
992 if len(classpath) > 0 {
993 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
994 }
995
996 return cmd
997}
998
Colin Crossab054432019-07-15 16:13:59 -0700999func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1000 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001001
Colin Crossab054432019-07-15 16:13:59 -07001002 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
1003 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
1004
1005 return rule.Command().
1006 BuiltTool(ctx, "dokka").
1007 Flag(config.JavacVmFlags).
1008 Flag(srcJarDir.String()).
1009 FlagWithInputList("-classpath ", dokkaClasspath, ":").
1010 FlagWithArg("-format ", "dac").
1011 FlagWithArg("-dacRoot ", "/reference/kotlin").
1012 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001013}
1014
1015func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1016 deps := d.Javadoc.collectDeps(ctx)
1017
Colin Crossdaa4c672019-07-15 22:53:46 -07001018 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
1019 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1020
Nan Zhang1598a9e2018-09-04 17:14:32 -07001021 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1022 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1023 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1024 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1025
Colin Crossab054432019-07-15 16:13:59 -07001026 outDir := android.PathForModuleOut(ctx, "out")
1027 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1028 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001029
Colin Crossab054432019-07-15 16:13:59 -07001030 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001031
Colin Crossab054432019-07-15 16:13:59 -07001032 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1033 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001034
Colin Crossab054432019-07-15 16:13:59 -07001035 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1036
1037 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001038 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001039 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001040 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001041 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001042 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001043 }
1044
Colin Crossab054432019-07-15 16:13:59 -07001045 d.stubsFlags(ctx, cmd, stubsDir)
1046
1047 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1048
Mathew Inwoodabd49ab2019-12-19 14:27:08 +00001049 if d.properties.Compat_config != nil {
1050 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
1051 cmd.FlagWithInput("-compatconfig ", compatConfig)
1052 }
1053
Colin Crossab054432019-07-15 16:13:59 -07001054 var desc string
1055 if Bool(d.properties.Dokka_enabled) {
1056 desc = "dokka"
1057 } else {
1058 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1059
1060 for _, o := range d.Javadoc.properties.Out {
1061 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1062 }
1063
1064 d.postDoclavaCmds(ctx, rule)
1065 desc = "doclava"
1066 }
1067
1068 rule.Command().
1069 BuiltTool(ctx, "soong_zip").
1070 Flag("-write_if_changed").
1071 Flag("-d").
1072 FlagWithOutput("-o ", d.docZip).
1073 FlagWithArg("-C ", outDir.String()).
1074 FlagWithArg("-D ", outDir.String())
1075
1076 rule.Command().
1077 BuiltTool(ctx, "soong_zip").
1078 Flag("-write_if_changed").
1079 Flag("-jar").
1080 FlagWithOutput("-o ", d.stubsSrcJar).
1081 FlagWithArg("-C ", stubsDir.String()).
1082 FlagWithArg("-D ", stubsDir.String())
1083
1084 rule.Restat()
1085
1086 zipSyncCleanupCmd(rule, srcJarDir)
1087
1088 rule.Build(pctx, ctx, "javadoc", desc)
1089
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001090 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001091 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001092
1093 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1094 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001095
1096 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001097
1098 rule := android.NewRuleBuilder()
1099
1100 rule.Command().Text("( true")
1101
1102 rule.Command().
1103 BuiltTool(ctx, "apicheck").
1104 Flag("-JXmx1024m").
1105 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1106 OptionalFlag(d.properties.Check_api.Current.Args).
1107 Input(apiFile).
1108 Input(d.apiFile).
1109 Input(removedApiFile).
1110 Input(d.removedApiFile)
1111
1112 msg := fmt.Sprintf(`\n******************************\n`+
1113 `You have tried to change the API from what has been previously approved.\n\n`+
1114 `To make these errors go away, you have two choices:\n`+
1115 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1116 ` errors above.\n\n`+
1117 ` 2. You can update current.txt by executing the following command:\n`+
1118 ` make %s-update-current-api\n\n`+
1119 ` To submit the revised current.txt to the main Android repository,\n`+
1120 ` you will need approval.\n`+
1121 `******************************\n`, ctx.ModuleName())
1122
1123 rule.Command().
1124 Text("touch").Output(d.checkCurrentApiTimestamp).
1125 Text(") || (").
1126 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1127 Text("; exit 38").
1128 Text(")")
1129
1130 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001131
1132 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001133
1134 // update API rule
1135 rule = android.NewRuleBuilder()
1136
1137 rule.Command().Text("( true")
1138
1139 rule.Command().
1140 Text("cp").Flag("-f").
1141 Input(d.apiFile).Flag(apiFile.String())
1142
1143 rule.Command().
1144 Text("cp").Flag("-f").
1145 Input(d.removedApiFile).Flag(removedApiFile.String())
1146
1147 msg = "failed to update public API"
1148
1149 rule.Command().
1150 Text("touch").Output(d.updateCurrentApiTimestamp).
1151 Text(") || (").
1152 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1153 Text("; exit 38").
1154 Text(")")
1155
1156 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001157 }
1158
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001159 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001160 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001161
1162 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1163 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001164
1165 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001166
1167 rule := android.NewRuleBuilder()
1168
1169 rule.Command().
1170 Text("(").
1171 BuiltTool(ctx, "apicheck").
1172 Flag("-JXmx1024m").
1173 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1174 OptionalFlag(d.properties.Check_api.Last_released.Args).
1175 Input(apiFile).
1176 Input(d.apiFile).
1177 Input(removedApiFile).
1178 Input(d.removedApiFile)
1179
1180 msg := `\n******************************\n` +
1181 `You have tried to change the API from what has been previously released in\n` +
1182 `an SDK. Please fix the errors listed above.\n` +
1183 `******************************\n`
1184
1185 rule.Command().
1186 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1187 Text(") || (").
1188 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1189 Text("; exit 38").
1190 Text(")")
1191
1192 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001193 }
1194}
1195
1196//
1197// Droidstubs
1198//
1199type Droidstubs struct {
1200 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001201 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001202
Pete Gillin581d6082018-10-22 15:55:04 +01001203 properties DroidstubsProperties
1204 apiFile android.WritablePath
1205 apiXmlFile android.WritablePath
1206 lastReleasedApiXmlFile android.WritablePath
1207 dexApiFile android.WritablePath
1208 privateApiFile android.WritablePath
1209 privateDexApiFile android.WritablePath
1210 removedApiFile android.WritablePath
1211 removedDexApiFile android.WritablePath
1212 apiMappingFile android.WritablePath
1213 exactApiFile android.WritablePath
1214 proguardFile android.WritablePath
1215 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001216
1217 checkCurrentApiTimestamp android.WritablePath
1218 updateCurrentApiTimestamp android.WritablePath
1219 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001220 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001221 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001222
Pete Gillin581d6082018-10-22 15:55:04 +01001223 checkNullabilityWarningsTimestamp android.WritablePath
1224
Nan Zhang1598a9e2018-09-04 17:14:32 -07001225 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001226 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001227
1228 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001229
1230 jdiffDocZip android.WritablePath
1231 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001232
1233 metadataZip android.WritablePath
1234 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001235}
1236
Colin Crossa3002fc2019-07-08 16:48:04 -07001237// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1238// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1239// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001240func DroidstubsFactory() android.Module {
1241 module := &Droidstubs{}
1242
1243 module.AddProperties(&module.properties,
1244 &module.Javadoc.properties)
1245
1246 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001247 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001248 return module
1249}
1250
Colin Crossa3002fc2019-07-08 16:48:04 -07001251// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1252// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1253// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1254// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001255func DroidstubsHostFactory() android.Module {
1256 module := &Droidstubs{}
1257
1258 module.AddProperties(&module.properties,
1259 &module.Javadoc.properties)
1260
1261 InitDroiddocModule(module, android.HostSupported)
1262 return module
1263}
1264
1265func (d *Droidstubs) ApiFilePath() android.Path {
1266 return d.apiFilePath
1267}
1268
Paul Duffin3d1248c2020-04-09 00:10:17 +01001269func (d *Droidstubs) StubsSrcJar() android.Path {
1270 return d.stubsSrcJar
1271}
1272
Nan Zhang1598a9e2018-09-04 17:14:32 -07001273func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1274 d.Javadoc.addDeps(ctx)
1275
Inseob Kim38449af2019-02-28 14:24:05 +09001276 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1277 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
1278 }
1279
Nan Zhang1598a9e2018-09-04 17:14:32 -07001280 if len(d.properties.Merge_annotations_dirs) != 0 {
1281 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1282 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1283 }
1284 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001285
Pete Gillin77167902018-09-19 18:16:26 +01001286 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1287 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1288 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1289 }
1290 }
1291
Nan Zhang9c69a122018-08-22 10:22:08 -07001292 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1293 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1294 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1295 }
1296 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001297}
1298
Colin Cross33961b52019-07-11 11:01:22 -07001299func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001300 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1301 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001302 String(d.properties.Api_filename) != "" {
1303 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001304 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001305 d.apiFilePath = d.apiFile
1306 }
1307
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001308 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1309 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001310 String(d.properties.Removed_api_filename) != "" {
1311 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001312 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001313 }
1314
1315 if String(d.properties.Private_api_filename) != "" {
1316 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001317 cmd.FlagWithOutput("--private-api ", d.privateApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001318 }
1319
1320 if String(d.properties.Dex_api_filename) != "" {
1321 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001322 cmd.FlagWithOutput("--dex-api ", d.dexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001323 }
1324
1325 if String(d.properties.Private_dex_api_filename) != "" {
1326 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001327 cmd.FlagWithOutput("--private-dex-api ", d.privateDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001328 }
1329
1330 if String(d.properties.Removed_dex_api_filename) != "" {
1331 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001332 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001333 }
1334
1335 if String(d.properties.Exact_api_filename) != "" {
1336 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001337 cmd.FlagWithOutput("--exact-api ", d.exactApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001338 }
1339
Nan Zhang9c69a122018-08-22 10:22:08 -07001340 if String(d.properties.Dex_mapping_filename) != "" {
1341 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001342 cmd.FlagWithOutput("--dex-api-mapping ", d.apiMappingFile)
Nan Zhang9c69a122018-08-22 10:22:08 -07001343 }
1344
Nan Zhang199645c2018-09-19 12:40:06 -07001345 if String(d.properties.Proguard_filename) != "" {
1346 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001347 cmd.FlagWithOutput("--proguard ", d.proguardFile)
Nan Zhang199645c2018-09-19 12:40:06 -07001348 }
1349
Nan Zhang9c69a122018-08-22 10:22:08 -07001350 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001351 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1352 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001353 }
1354
Nan Zhang1598a9e2018-09-04 17:14:32 -07001355 if Bool(d.properties.Create_doc_stubs) {
Colin Cross33961b52019-07-11 11:01:22 -07001356 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001357 } else {
Colin Cross33961b52019-07-11 11:01:22 -07001358 cmd.FlagWithArg("--stubs ", stubsDir.String())
Aurimas Liutikas39de3252020-03-11 16:28:05 -07001359 cmd.Flag("--exclude-documentation-from-stubs")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001360 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001361}
1362
Colin Cross33961b52019-07-11 11:01:22 -07001363func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001364 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001365 cmd.Flag("--include-annotations")
1366
Pete Gillinc382a562018-11-14 18:45:46 +00001367 validatingNullability :=
1368 strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") ||
1369 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001370
Pete Gillina262c052018-09-14 14:25:48 +01001371 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001372 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001373 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001374 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001375 }
Colin Cross33961b52019-07-11 11:01:22 -07001376
Pete Gillinc382a562018-11-14 18:45:46 +00001377 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001378 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001379 }
Colin Cross33961b52019-07-11 11:01:22 -07001380
Pete Gillina262c052018-09-14 14:25:48 +01001381 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001382 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001383 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001384 }
Nan Zhanga40da042018-08-01 12:48:00 -07001385
1386 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001387 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001388
Nan Zhang1598a9e2018-09-04 17:14:32 -07001389 if len(d.properties.Merge_annotations_dirs) == 0 {
Nan Zhang9c69a122018-08-22 10:22:08 -07001390 ctx.PropertyErrorf("merge_annotations_dirs",
Nan Zhanga40da042018-08-01 12:48:00 -07001391 "has to be non-empty if annotations was enabled!")
1392 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001393
Colin Cross33961b52019-07-11 11:01:22 -07001394 d.mergeAnnoDirFlags(ctx, cmd)
1395
1396 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1397 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1398 FlagWithArg("--hide ", "SuperfluousPrefix").
1399 FlagWithArg("--hide ", "AnnotationExtraction")
1400 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001401}
1402
Colin Cross33961b52019-07-11 11:01:22 -07001403func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1404 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1405 if t, ok := m.(*ExportedDroiddocDir); ok {
1406 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1407 } else {
1408 ctx.PropertyErrorf("merge_annotations_dirs",
1409 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1410 }
1411 })
1412}
1413
1414func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001415 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1416 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001417 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001418 } else {
1419 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1420 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1421 }
1422 })
Nan Zhanga40da042018-08-01 12:48:00 -07001423}
1424
Colin Cross33961b52019-07-11 11:01:22 -07001425func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001426 if Bool(d.properties.Api_levels_annotations_enabled) {
1427 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001428
1429 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1430 ctx.PropertyErrorf("api_levels_annotations_dirs",
1431 "has to be non-empty if api levels annotations was enabled!")
1432 }
1433
Colin Cross33961b52019-07-11 11:01:22 -07001434 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1435 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1436 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1437 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001438
1439 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1440 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001441 for _, dep := range t.deps {
1442 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001443 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001444 }
1445 }
Colin Cross33961b52019-07-11 11:01:22 -07001446 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001447 } else {
1448 ctx.PropertyErrorf("api_levels_annotations_dirs",
1449 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1450 }
1451 })
1452
1453 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001454}
1455
Colin Cross33961b52019-07-11 11:01:22 -07001456func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang71bbe632018-09-17 14:32:21 -07001457 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
1458 if d.apiFile.String() == "" {
1459 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1460 }
1461
1462 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001463 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001464
1465 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1466 ctx.PropertyErrorf("check_api.last_released.api_file",
1467 "has to be non-empty if jdiff was enabled!")
1468 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001469
Colin Cross33961b52019-07-11 11:01:22 -07001470 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001471 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001472 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1473 }
1474}
Nan Zhang71bbe632018-09-17 14:32:21 -07001475
Colin Cross1e743852019-10-28 11:37:20 -07001476func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Colin Cross33961b52019-07-11 11:01:22 -07001477 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001478 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1479 rule.HighMem()
Colin Cross33961b52019-07-11 11:01:22 -07001480 cmd := rule.Command().BuiltTool(ctx, "metalava").
1481 Flag(config.JavacVmFlags).
1482 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001483 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001484 FlagWithRspFileInputList("@", srcs).
1485 FlagWithInput("@", srcJarList)
1486
1487 if len(bootclasspath) > 0 {
1488 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001489 }
1490
Colin Cross33961b52019-07-11 11:01:22 -07001491 if len(classpath) > 0 {
1492 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1493 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001494
Colin Cross33961b52019-07-11 11:01:22 -07001495 if len(sourcepaths) > 0 {
1496 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1497 } else {
1498 cmd.FlagWithArg("-sourcepath ", `""`)
1499 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001500
Colin Cross33961b52019-07-11 11:01:22 -07001501 cmd.Flag("--no-banner").
1502 Flag("--color").
1503 Flag("--quiet").
1504 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001505
Colin Cross33961b52019-07-11 11:01:22 -07001506 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001507}
1508
Nan Zhang1598a9e2018-09-04 17:14:32 -07001509func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001510 deps := d.Javadoc.collectDeps(ctx)
1511
1512 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001513
Colin Cross33961b52019-07-11 11:01:22 -07001514 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001515
Colin Crossdaa4c672019-07-15 22:53:46 -07001516 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhanga40da042018-08-01 12:48:00 -07001517
Colin Cross33961b52019-07-11 11:01:22 -07001518 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1519 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang71bbe632018-09-17 14:32:21 -07001520
Colin Cross33961b52019-07-11 11:01:22 -07001521 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001522
Colin Cross33961b52019-07-11 11:01:22 -07001523 rule.Command().Text("rm -rf").Text(stubsDir.String())
1524 rule.Command().Text("mkdir -p").Text(stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -07001525
Colin Cross33961b52019-07-11 11:01:22 -07001526 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1527
1528 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1529 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1530
1531 d.stubsFlags(ctx, cmd, stubsDir)
1532
1533 d.annotationsFlags(ctx, cmd)
1534 d.inclusionAnnotationsFlags(ctx, cmd)
1535 d.apiLevelsAnnotationsFlags(ctx, cmd)
1536 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001537
Nan Zhang1598a9e2018-09-04 17:14:32 -07001538 if strings.Contains(d.Javadoc.args, "--generate-documentation") {
1539 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1540 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1541 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
1542 d.Javadoc.args = d.Javadoc.args + " -nodocs "
Nan Zhang79614d12018-04-19 18:03:39 -07001543 }
Colin Cross33961b52019-07-11 11:01:22 -07001544
1545 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1546 for _, o := range d.Javadoc.properties.Out {
1547 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1548 }
1549
1550 rule.Command().
1551 BuiltTool(ctx, "soong_zip").
1552 Flag("-write_if_changed").
1553 Flag("-jar").
1554 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1555 FlagWithArg("-C ", stubsDir.String()).
1556 FlagWithArg("-D ", stubsDir.String())
Jerome Gaillard0f599032019-10-10 19:29:11 +01001557
1558 if Bool(d.properties.Write_sdk_values) {
1559 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1560 rule.Command().
1561 BuiltTool(ctx, "soong_zip").
1562 Flag("-write_if_changed").
1563 Flag("-d").
1564 FlagWithOutput("-o ", d.metadataZip).
1565 FlagWithArg("-C ", d.metadataDir.String()).
1566 FlagWithArg("-D ", d.metadataDir.String())
1567 }
1568
Colin Cross33961b52019-07-11 11:01:22 -07001569 rule.Restat()
1570
1571 zipSyncCleanupCmd(rule, srcJarDir)
1572
1573 rule.Build(pctx, ctx, "metalava", "metalava")
1574
1575 // Create rule for apicheck
Nan Zhang61819ce2018-05-04 18:49:16 -07001576
Adrian Roos075eedc2019-10-10 12:07:03 +02001577 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1578 rule := android.NewRuleBuilder()
1579 rule.Command().Text("( true")
1580
1581 srcJarDir := android.PathForModuleOut(ctx, "api_lint", "srcjars")
1582 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1583
1584 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1585 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1586
Adrian Rooscab4a2c2019-10-14 16:32:41 +02001587 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles)
1588
Adrian Roos075eedc2019-10-10 12:07:03 +02001589 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1590 if newSince.Valid() {
1591 cmd.FlagWithInput("--api-lint ", newSince.Path())
1592 } else {
1593 cmd.Flag("--api-lint")
1594 }
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001595 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1596 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport)
Adrian Roos075eedc2019-10-10 12:07:03 +02001597
1598 d.inclusionAnnotationsFlags(ctx, cmd)
1599 d.mergeAnnoDirFlags(ctx, cmd)
1600
1601 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1602 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1603 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1604
1605 if baselineFile.Valid() {
1606 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1607 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1608 }
1609
1610 zipSyncCleanupCmd(rule, srcJarDir)
1611
1612 msg := fmt.Sprintf(`\n******************************\n`+
1613 `Your API changes are triggering API Lint warnings or errors.\n\n`+
1614 `To make these errors go away, you have two choices:\n`+
1615 ` 1. You can suppress the errors with @SuppressLint(\"<id>\").\n\n`+
1616 ` 2. You can update the baseline by executing the following command:\n`+
1617 ` cp \"$PWD/%s\" \"$PWD/%s\"\n\n`+
1618 `******************************\n`, updatedBaselineOutput, baselineFile.Path())
1619 rule.Command().
1620 Text("touch").Output(d.apiLintTimestamp).
1621 Text(") || (").
1622 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1623 Text("; exit 38").
1624 Text(")")
1625
1626 rule.Build(pctx, ctx, "metalavaApiLint", "metalava API lint")
1627
1628 }
1629
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001630 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001631 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001632
1633 if len(d.Javadoc.properties.Out) > 0 {
1634 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1635 }
1636
1637 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1638 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001639 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
1640 updatedBaselineOutput := android.PathForModuleOut(ctx, "current_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001641
Nan Zhang2760dfc2018-08-24 17:32:54 +00001642 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001643
Colin Cross33961b52019-07-11 11:01:22 -07001644 rule := android.NewRuleBuilder()
1645
1646 rule.Command().Text("( true")
1647
1648 srcJarDir := android.PathForModuleOut(ctx, "current-apicheck", "srcjars")
1649 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1650
1651 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1652 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1653
1654 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1655 FlagWithInput("--check-compatibility:api:current ", apiFile).
1656 FlagWithInput("--check-compatibility:removed:current ", removedApiFile)
1657
1658 d.inclusionAnnotationsFlags(ctx, cmd)
1659 d.mergeAnnoDirFlags(ctx, cmd)
1660
Adrian Roos14f75a92019-08-12 17:54:09 +02001661 if baselineFile.Valid() {
1662 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1663 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1664 }
1665
Colin Cross33961b52019-07-11 11:01:22 -07001666 zipSyncCleanupCmd(rule, srcJarDir)
1667
1668 msg := fmt.Sprintf(`\n******************************\n`+
1669 `You have tried to change the API from what has been previously approved.\n\n`+
1670 `To make these errors go away, you have two choices:\n`+
1671 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1672 ` errors above.\n\n`+
1673 ` 2. You can update current.txt by executing the following command:\n`+
1674 ` make %s-update-current-api\n\n`+
1675 ` To submit the revised current.txt to the main Android repository,\n`+
1676 ` you will need approval.\n`+
1677 `******************************\n`, ctx.ModuleName())
1678
1679 rule.Command().
1680 Text("touch").Output(d.checkCurrentApiTimestamp).
1681 Text(") || (").
1682 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1683 Text("; exit 38").
1684 Text(")")
1685
1686 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "metalava check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001687
1688 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001689
1690 // update API rule
1691 rule = android.NewRuleBuilder()
1692
1693 rule.Command().Text("( true")
1694
1695 rule.Command().
1696 Text("cp").Flag("-f").
1697 Input(d.apiFile).Flag(apiFile.String())
1698
1699 rule.Command().
1700 Text("cp").Flag("-f").
1701 Input(d.removedApiFile).Flag(removedApiFile.String())
1702
1703 msg = "failed to update public API"
1704
1705 rule.Command().
1706 Text("touch").Output(d.updateCurrentApiTimestamp).
1707 Text(") || (").
1708 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1709 Text("; exit 38").
1710 Text(")")
1711
1712 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001713 }
Nan Zhanga40da042018-08-01 12:48:00 -07001714
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001715 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001716 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001717
1718 if len(d.Javadoc.properties.Out) > 0 {
1719 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1720 }
1721
1722 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1723 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001724 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1725 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
Nan Zhang61819ce2018-05-04 18:49:16 -07001726
Nan Zhang2760dfc2018-08-24 17:32:54 +00001727 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001728
Colin Cross33961b52019-07-11 11:01:22 -07001729 rule := android.NewRuleBuilder()
1730
1731 rule.Command().Text("( true")
1732
1733 srcJarDir := android.PathForModuleOut(ctx, "last-apicheck", "srcjars")
1734 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1735
1736 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
1737 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
1738
1739 cmd.Flag(d.Javadoc.args).Implicits(d.Javadoc.argFiles).
1740 FlagWithInput("--check-compatibility:api:released ", apiFile)
1741
1742 d.inclusionAnnotationsFlags(ctx, cmd)
1743
1744 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1745
1746 d.mergeAnnoDirFlags(ctx, cmd)
1747
Adrian Roos14f75a92019-08-12 17:54:09 +02001748 if baselineFile.Valid() {
1749 cmd.FlagWithInput("--baseline ", baselineFile.Path())
1750 cmd.FlagWithOutput("--update-baseline ", updatedBaselineOutput)
1751 }
1752
Colin Cross33961b52019-07-11 11:01:22 -07001753 zipSyncCleanupCmd(rule, srcJarDir)
1754
1755 msg := `\n******************************\n` +
1756 `You have tried to change the API from what has been previously released in\n` +
1757 `an SDK. Please fix the errors listed above.\n` +
1758 `******************************\n`
1759 rule.Command().
1760 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1761 Text(") || (").
1762 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1763 Text("; exit 38").
1764 Text(")")
1765
1766 rule.Build(pctx, ctx, "metalavaLastApiCheck", "metalava check last API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001767 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001768
Pete Gillin581d6082018-10-22 15:55:04 +01001769 if String(d.properties.Check_nullability_warnings) != "" {
1770 if d.nullabilityWarningsFile == nil {
1771 ctx.PropertyErrorf("check_nullability_warnings",
1772 "Cannot specify check_nullability_warnings unless validating nullability")
1773 }
Colin Cross33961b52019-07-11 11:01:22 -07001774
1775 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1776
Pete Gillin581d6082018-10-22 15:55:04 +01001777 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001778
Pete Gillin581d6082018-10-22 15:55:04 +01001779 msg := fmt.Sprintf(`\n******************************\n`+
1780 `The warnings encountered during nullability annotation validation did\n`+
1781 `not match the checked in file of expected warnings. The diffs are shown\n`+
1782 `above. You have two options:\n`+
1783 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1784 ` 2. Update the file of expected warnings by running:\n`+
1785 ` cp %s %s\n`+
1786 ` and submitting the updated file as part of your change.`,
1787 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001788
1789 rule := android.NewRuleBuilder()
1790
1791 rule.Command().
1792 Text("(").
1793 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1794 Text("&&").
1795 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1796 Text(") || (").
1797 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1798 Text("; exit 38").
1799 Text(")")
1800
1801 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001802 }
1803
Nan Zhang71bbe632018-09-17 14:32:21 -07001804 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001805 if len(d.Javadoc.properties.Out) > 0 {
1806 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1807 }
1808
1809 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1810 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1811 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1812
1813 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001814
Nan Zhang86b06202018-09-21 17:09:21 -07001815 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1816 // since there's cron job downstream that fetch this .zip file periodically.
1817 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001818 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1819 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1820
Nan Zhang71bbe632018-09-17 14:32:21 -07001821 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001822
Colin Cross33961b52019-07-11 11:01:22 -07001823 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1824 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001825
Colin Cross33961b52019-07-11 11:01:22 -07001826 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1827
Colin Crossdaa4c672019-07-15 22:53:46 -07001828 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001829 deps.bootClasspath, deps.classpath, d.sourcepaths)
1830
1831 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001832 Flag("-XDignore.symbol.file").
1833 FlagWithArg("-doclet ", "jdiff.JDiff").
1834 FlagWithInput("-docletpath ", jdiff).
1835 Flag("-quiet").
1836 FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1837 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1838 Implicit(d.apiXmlFile).
1839 FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1840 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1841 Implicit(d.lastReleasedApiXmlFile)
1842
Colin Cross33961b52019-07-11 11:01:22 -07001843 rule.Command().
1844 BuiltTool(ctx, "soong_zip").
1845 Flag("-write_if_changed").
1846 Flag("-d").
1847 FlagWithOutput("-o ", d.jdiffDocZip).
1848 FlagWithArg("-C ", outDir.String()).
1849 FlagWithArg("-D ", outDir.String())
1850
1851 rule.Command().
1852 BuiltTool(ctx, "soong_zip").
1853 Flag("-write_if_changed").
1854 Flag("-jar").
1855 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1856 FlagWithArg("-C ", stubsDir.String()).
1857 FlagWithArg("-D ", stubsDir.String())
1858
1859 rule.Restat()
1860
1861 zipSyncCleanupCmd(rule, srcJarDir)
1862
1863 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001864 }
Nan Zhang581fd212018-01-10 16:06:12 -08001865}
Dan Willemsencc090972018-02-26 14:33:31 -08001866
Nan Zhanga40da042018-08-01 12:48:00 -07001867//
Nan Zhangf4936b02018-08-01 15:00:28 -07001868// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001869//
Dan Willemsencc090972018-02-26 14:33:31 -08001870var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001871var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001872var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001873var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001874
Nan Zhangf4936b02018-08-01 15:00:28 -07001875type ExportedDroiddocDirProperties struct {
1876 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001877 Path *string
1878}
1879
Nan Zhangf4936b02018-08-01 15:00:28 -07001880type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001881 android.ModuleBase
1882
Nan Zhangf4936b02018-08-01 15:00:28 -07001883 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001884
1885 deps android.Paths
1886 dir android.Path
1887}
1888
Colin Crossa3002fc2019-07-08 16:48:04 -07001889// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001890func ExportedDroiddocDirFactory() android.Module {
1891 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001892 module.AddProperties(&module.properties)
1893 android.InitAndroidModule(module)
1894 return module
1895}
1896
Nan Zhangf4936b02018-08-01 15:00:28 -07001897func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001898
Nan Zhangf4936b02018-08-01 15:00:28 -07001899func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001900 path := String(d.properties.Path)
1901 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001902 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001903}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001904
1905//
1906// Defaults
1907//
1908type DocDefaults struct {
1909 android.ModuleBase
1910 android.DefaultsModuleBase
1911}
1912
Nan Zhangb2b33de2018-02-23 11:18:47 -08001913func DocDefaultsFactory() android.Module {
1914 module := &DocDefaults{}
1915
1916 module.AddProperties(
1917 &JavadocProperties{},
1918 &DroiddocProperties{},
1919 )
1920
1921 android.InitDefaultsModule(module)
1922
1923 return module
1924}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001925
1926func StubsDefaultsFactory() android.Module {
1927 module := &DocDefaults{}
1928
1929 module.AddProperties(
1930 &JavadocProperties{},
1931 &DroidstubsProperties{},
1932 )
1933
1934 android.InitDefaultsModule(module)
1935
1936 return module
1937}
Colin Cross33961b52019-07-11 11:01:22 -07001938
1939func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1940 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1941
1942 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1943 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1944 srcJarList := srcJarDir.Join(ctx, "list")
1945
1946 rule.Temporary(srcJarList)
1947
1948 rule.Command().BuiltTool(ctx, "zipsync").
1949 FlagWithArg("-d ", srcJarDir.String()).
1950 FlagWithOutput("-l ", srcJarList).
1951 FlagWithArg("-f ", `"*.java"`).
1952 Inputs(srcJars)
1953
1954 return srcJarList
1955}
1956
1957func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1958 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1959}
Paul Duffin91547182019-11-12 19:39:36 +00001960
1961var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1962
1963type PrebuiltStubsSourcesProperties struct {
1964 Srcs []string `android:"path"`
1965}
1966
1967type PrebuiltStubsSources struct {
1968 android.ModuleBase
1969 android.DefaultableModuleBase
1970 prebuilt android.Prebuilt
1971 android.SdkBase
1972
1973 properties PrebuiltStubsSourcesProperties
1974
Paul Duffin9b478b02019-12-10 13:41:51 +00001975 // The source directories containing stubs source files.
1976 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00001977 stubsSrcJar android.ModuleOutPath
1978}
1979
Paul Duffin9b478b02019-12-10 13:41:51 +00001980func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
1981 switch tag {
1982 case "":
1983 return android.Paths{p.stubsSrcJar}, nil
1984 default:
1985 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1986 }
1987}
1988
Paul Duffin91547182019-11-12 19:39:36 +00001989func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00001990 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1991
1992 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
1993
1994 rule := android.NewRuleBuilder()
1995 command := rule.Command().
1996 BuiltTool(ctx, "soong_zip").
1997 Flag("-write_if_changed").
1998 Flag("-jar").
1999 FlagWithOutput("-o ", p.stubsSrcJar)
2000
2001 for _, d := range p.srcDirs {
2002 dir := d.String()
2003 command.
2004 FlagWithArg("-C ", dir).
2005 FlagWithInput("-D ", d)
2006 }
2007
2008 rule.Restat()
2009
2010 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00002011}
2012
2013func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
2014 return &p.prebuilt
2015}
2016
2017func (p *PrebuiltStubsSources) Name() string {
2018 return p.prebuilt.Name(p.ModuleBase.Name())
2019}
2020
Paul Duffin91547182019-11-12 19:39:36 +00002021// prebuilt_stubs_sources imports a set of java source files as if they were
2022// generated by droidstubs.
2023//
2024// By default, a prebuilt_stubs_sources has a single variant that expects a
2025// set of `.java` files generated by droidstubs.
2026//
2027// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2028// for host modules.
2029//
2030// Intended only for use by sdk snapshots.
2031func PrebuiltStubsSourcesFactory() android.Module {
2032 module := &PrebuiltStubsSources{}
2033
2034 module.AddProperties(&module.properties)
2035
2036 android.InitPrebuiltModule(module, &module.properties.Srcs)
2037 android.InitSdkAwareModule(module)
2038 InitDroiddocModule(module, android.HostAndDeviceSupported)
2039 return module
2040}
2041
Paul Duffin13879572019-11-28 14:31:38 +00002042type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00002043 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00002044}
2045
2046func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2047 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2048}
2049
2050func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
2051 _, ok := module.(*Droidstubs)
2052 return ok
2053}
2054
Paul Duffin495ffb92020-03-20 13:35:40 +00002055func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2056 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
2057}
2058
2059func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2060 return &droidStubsInfoProperties{}
2061}
2062
2063type droidStubsInfoProperties struct {
2064 android.SdkMemberPropertiesBase
2065
2066 StubsSrcJar android.Path
2067}
2068
2069func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2070 droidstubs := variant.(*Droidstubs)
2071 p.StubsSrcJar = droidstubs.stubsSrcJar
2072}
2073
2074func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
2075 if p.StubsSrcJar != nil {
2076 builder := ctx.SnapshotBuilder()
2077
2078 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2079
2080 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2081
2082 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002083 }
Paul Duffin91547182019-11-12 19:39:36 +00002084}