blob: 08865b66616197af9955ab695433fbe0288d7df9 [file] [log] [blame]
Nan Zhang581fd212018-01-10 16:06:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
Nan Zhang581fd212018-01-10 16:06:12 -080018 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080019 "path/filepath"
Nan Zhang581fd212018-01-10 16:06:12 -080020 "strings"
21
Paul Duffin13879572019-11-28 14:31:38 +000022 "github.com/google/blueprint"
Jeongik Cha6bd33c12019-06-25 16:26:18 +090023 "github.com/google/blueprint/proptools"
Nan Zhang581fd212018-01-10 16:06:12 -080024
Colin Crossab054432019-07-15 16:13:59 -070025 "android/soong/android"
26 "android/soong/java/config"
Ramy Medhat427683c2020-04-30 03:08:37 -040027 "android/soong/remoteexec"
Nan Zhang581fd212018-01-10 16:06:12 -080028)
29
30func init() {
Paul Duffin884363e2019-12-19 10:21:09 +000031 RegisterDocsBuildComponents(android.InitRegistrationContext)
32 RegisterStubsBuildComponents(android.InitRegistrationContext)
Paul Duffin255f18e2019-12-13 11:22:16 +000033
34 // Register sdk member type.
35 android.RegisterSdkMemberType(&droidStubsSdkMemberType{
36 SdkMemberTypeBase: android.SdkMemberTypeBase{
37 PropertyName: "stubs_sources",
Paul Duffine6029182019-12-16 17:43:48 +000038 // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
39 // the APEX.
40 SupportsSdk: true,
Paul Duffin255f18e2019-12-13 11:22:16 +000041 },
42 })
Nan Zhang581fd212018-01-10 16:06:12 -080043}
44
Paul Duffin884363e2019-12-19 10:21:09 +000045func RegisterDocsBuildComponents(ctx android.RegistrationContext) {
46 ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory)
47
48 ctx.RegisterModuleType("droiddoc", DroiddocFactory)
49 ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
50 ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
51 ctx.RegisterModuleType("javadoc", JavadocFactory)
52 ctx.RegisterModuleType("javadoc_host", JavadocHostFactory)
53}
54
55func RegisterStubsBuildComponents(ctx android.RegistrationContext) {
56 ctx.RegisterModuleType("stubs_defaults", StubsDefaultsFactory)
57
58 ctx.RegisterModuleType("droidstubs", DroidstubsFactory)
59 ctx.RegisterModuleType("droidstubs_host", DroidstubsHostFactory)
60
61 ctx.RegisterModuleType("prebuilt_stubs_sources", PrebuiltStubsSourcesFactory)
62}
63
Colin Crossa1ce2a02018-06-20 15:19:39 -070064var (
65 srcsLibTag = dependencyTag{name: "sources from javalib"}
66)
67
Nan Zhang581fd212018-01-10 16:06:12 -080068type JavadocProperties struct {
69 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
70 // or .aidl files.
Colin Cross27b922f2019-03-04 22:35:41 -080071 Srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080072
73 // list of directories rooted at the Android.bp file that will
74 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -080075 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -080076
77 // list of source files that should not be used to build the Java module.
78 // This is most useful in the arch/multilib variants to remove non-common files
79 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -080080 Exclude_srcs []string `android:"path,arch_variant"`
Nan Zhang581fd212018-01-10 16:06:12 -080081
Jiyong Parkc6ddccf2019-09-13 20:56:14 +090082 // list of package names that should actually be used. If this property is left unspecified,
83 // all the sources from the srcs property is used.
84 Filter_packages []string
85
Nan Zhangb2b33de2018-02-23 11:18:47 -080086 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -080087 Libs []string `android:"arch_variant"`
88
89 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -080090 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -080091
Paul Duffine25c6442019-10-11 13:50:28 +010092 // if not blank, set to the version of the sdk to compile against.
93 // Defaults to compiling against the current platform.
Nan Zhang581fd212018-01-10 16:06:12 -080094 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +090095
Paul Duffine25c6442019-10-11 13:50:28 +010096 // When targeting 1.9 and above, override the modules to use with --system,
97 // otherwise provides defaults libraries to add to the bootclasspath.
98 // Defaults to "none"
99 System_modules *string
100
Jiyong Park1e440682018-05-23 18:42:04 +0900101 Aidl struct {
102 // Top level directories to pass to aidl tool
103 Include_dirs []string
104
105 // Directories rooted at the Android.bp file to pass to aidl tool
106 Local_include_dirs []string
107 }
Nan Zhang357466b2018-04-17 17:38:36 -0700108
109 // If not blank, set the java version passed to javadoc as -source
110 Java_version *string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700111
112 // local files that are used within user customized droiddoc options.
Colin Cross27b922f2019-03-04 22:35:41 -0800113 Arg_files []string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700114
Liz Kammer585cac22020-07-06 09:12:57 -0700115 // user customized droiddoc args. Deprecated, use flags instead.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700116 // Available variables for substitution:
117 //
118 // $(location <label>): the path to the arg_files with name <label>
Colin Crosse4a05842019-05-28 10:17:14 -0700119 // $$: a literal $
Nan Zhang1598a9e2018-09-04 17:14:32 -0700120 Args *string
121
Liz Kammer585cac22020-07-06 09:12:57 -0700122 // user customized droiddoc args. Not compatible with property args.
123 // Available variables for substitution:
124 //
125 // $(location <label>): the path to the arg_files with name <label>
126 // $$: a literal $
127 Flags []string
128
Nan Zhang1598a9e2018-09-04 17:14:32 -0700129 // names of the output files used in args that will be generated
130 Out []string
Ramy Medhat2f99eec2020-06-13 17:38:27 -0400131
132 // If set, metalava is sandboxed to only read files explicitly specified on the command
133 // line. Defaults to false.
134 Sandbox *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800135}
136
Nan Zhang61819ce2018-05-04 18:49:16 -0700137type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900138 // path to the API txt file that the new API extracted from source code is checked
139 // against. The path can be local to the module or from other module (via :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800140 Api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700141
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900142 // path to the API txt file that the new @removed API extractd from source code is
143 // checked against. The path can be local to the module or from other module (via
144 // :module syntax).
Colin Cross27b922f2019-03-04 22:35:41 -0800145 Removed_api_file *string `android:"path"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700146
Adrian Roos14f75a92019-08-12 17:54:09 +0200147 // If not blank, path to the baseline txt file for approved API check violations.
148 Baseline_file *string `android:"path"`
149
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900150 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700151 Args *string
152}
153
Nan Zhang581fd212018-01-10 16:06:12 -0800154type DroiddocProperties struct {
155 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800156 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800157
Nan Zhanga40da042018-08-01 12:48:00 -0700158 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800159 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800160
161 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800162 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800163
164 // proofread file contains all of the text content of the javadocs concatenated into one file,
165 // suitable for spell-checking and other goodness.
Colin Crossab054432019-07-15 16:13:59 -0700166 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800167
168 // a todo file lists the program elements that are missing documentation.
169 // At some point, this might be improved to show more warnings.
Colin Cross27b922f2019-03-04 22:35:41 -0800170 Todo_file *string `android:"path"`
Nan Zhangb2b33de2018-02-23 11:18:47 -0800171
172 // directory under current module source that provide additional resources (images).
173 Resourcesdir *string
174
175 // resources output directory under out/soong/.intermediates.
176 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800177
Nan Zhange2ba5d42018-07-11 15:16:55 -0700178 // if set to true, collect the values used by the Dev tools and
179 // write them in files packaged with the SDK. Defaults to false.
180 Write_sdk_values *bool
181
182 // index.html under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800183 Static_doc_index_redirect *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700184
185 // source.properties under current module will be copied to docs out dir, if not null.
Colin Cross27b922f2019-03-04 22:35:41 -0800186 Static_doc_properties *string `android:"path"`
Nan Zhange2ba5d42018-07-11 15:16:55 -0700187
Nan Zhang581fd212018-01-10 16:06:12 -0800188 // a list of files under current module source dir which contains known tags in Java sources.
189 // filegroup or genrule can be included within this property.
Colin Cross27b922f2019-03-04 22:35:41 -0800190 Knowntags []string `android:"path"`
Nan Zhang28c68b92018-03-13 16:17:01 -0700191
Nan Zhang28c68b92018-03-13 16:17:01 -0700192 // the generated public API filename by Doclava.
193 Api_filename *string
194
Nan Zhang28c68b92018-03-13 16:17:01 -0700195 // 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
Nan Zhang853f4202018-04-12 16:55:56 -0700201 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
202 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700203
204 Check_api struct {
205 Last_released ApiToCheck
206
207 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900208
209 // do not perform API check against Last_released, in the case that both two specified API
210 // files by Last_released are modules which don't exist.
211 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Nan Zhang61819ce2018-05-04 18:49:16 -0700212 }
Nan Zhang79614d12018-04-19 18:03:39 -0700213
Nan Zhang1598a9e2018-09-04 17:14:32 -0700214 // if set to true, generate docs through Dokka instead of Doclava.
215 Dokka_enabled *bool
Mathew Inwoodabd49ab2019-12-19 14:27:08 +0000216
217 // Compat config XML. Generates compat change documentation if set.
218 Compat_config *string `android:"path"`
Nan Zhang1598a9e2018-09-04 17:14:32 -0700219}
220
221type DroidstubsProperties struct {
Nan Zhang199645c2018-09-19 12:40:06 -0700222 // the generated public API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700223 Api_filename *string
224
Nan Zhang199645c2018-09-19 12:40:06 -0700225 // the generated removed API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700226 Removed_api_filename *string
227
Nan Zhang199645c2018-09-19 12:40:06 -0700228 // the generated removed Dex API filename by Metalava.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700229 Removed_dex_api_filename *string
230
Nan Zhang1598a9e2018-09-04 17:14:32 -0700231 Check_api struct {
232 Last_released ApiToCheck
233
234 Current ApiToCheck
Inseob Kim38449af2019-02-28 14:24:05 +0900235
Paul Duffin160fe412020-05-10 19:32:20 +0100236 // The java_sdk_library module generates references to modules (i.e. filegroups)
237 // from which information about the latest API version can be obtained. As those
238 // modules may not exist (e.g. because a previous version has not been released) it
239 // sets ignore_missing_latest_api=true on the droidstubs modules it creates so
240 // that droidstubs can ignore those references if the modules do not yet exist.
241 //
242 // If true then this will ignore module references for modules that do not exist
243 // in properties that supply the previous version of the API.
244 //
245 // There are two sets of those:
246 // * Api_file, Removed_api_file in check_api.last_released
247 // * New_since in check_api.api_lint.new_since
248 //
249 // The first two must be set as a pair, so either they should both exist or neither
250 // should exist - in which case when this property is true they are ignored. If one
251 // exists and the other does not then it is an error.
Inseob Kim38449af2019-02-28 14:24:05 +0900252 Ignore_missing_latest_api *bool `blueprint:"mutated"`
Adrian Roos075eedc2019-10-10 12:07:03 +0200253
254 Api_lint struct {
255 Enabled *bool
256
257 // If set, performs api_lint on any new APIs not found in the given signature file
258 New_since *string `android:"path"`
259
260 // If not blank, path to the baseline txt file for approved API lint violations.
261 Baseline_file *string `android:"path"`
262 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700263 }
Nan Zhang79614d12018-04-19 18:03:39 -0700264
265 // user can specify the version of previous released API file in order to do compatibility check.
Colin Cross27b922f2019-03-04 22:35:41 -0800266 Previous_api *string `android:"path"`
Nan Zhang79614d12018-04-19 18:03:39 -0700267
268 // is set to true, Metalava will allow framework SDK to contain annotations.
Nan Zhang1598a9e2018-09-04 17:14:32 -0700269 Annotations_enabled *bool
Nan Zhang79614d12018-04-19 18:03:39 -0700270
Pete Gillin77167902018-09-19 18:16:26 +0100271 // 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 -0700272 Merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700273
Pete Gillin77167902018-09-19 18:16:26 +0100274 // a list of top-level directories containing Java stub files to merge show/hide annotations from.
275 Merge_inclusion_annotations_dirs []string
276
Pete Gillinc382a562018-11-14 18:45:46 +0000277 // a file containing a list of classes to do nullability validation for.
278 Validate_nullability_from_list *string
279
Pete Gillin581d6082018-10-22 15:55:04 +0100280 // a file containing expected warnings produced by validation of nullability annotations.
281 Check_nullability_warnings *string
282
Nan Zhang1598a9e2018-09-04 17:14:32 -0700283 // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false.
284 Create_doc_stubs *bool
Nan Zhang9c69a122018-08-22 10:22:08 -0700285
Paul Duffin3ae29512020-04-08 18:18:03 +0100286 // if set to false then do not write out stubs. Defaults to true.
287 //
288 // TODO(b/146727827): Remove capability when we do not need to generate stubs and API separately.
289 Generate_stubs *bool
290
Nan Zhang9c69a122018-08-22 10:22:08 -0700291 // is set to true, Metalava will allow framework SDK to contain API levels annotations.
292 Api_levels_annotations_enabled *bool
293
294 // the dirs which Metalava extracts API levels annotations from.
295 Api_levels_annotations_dirs []string
296
297 // if set to true, collect the values used by the Dev tools and
298 // write them in files packaged with the SDK. Defaults to false.
299 Write_sdk_values *bool
Nan Zhang71bbe632018-09-17 14:32:21 -0700300
301 // If set to true, .xml based public API file will be also generated, and
302 // JDiff tool will be invoked to genreate javadoc files. Defaults to false.
303 Jdiff_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800304}
305
Nan Zhanga40da042018-08-01 12:48:00 -0700306//
307// Common flags passed down to build rule
308//
309type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700310 bootClasspathArgs string
311 classpathArgs string
Nan Zhang1598a9e2018-09-04 17:14:32 -0700312 sourcepathArgs string
Nan Zhang86d2d552018-08-09 15:33:27 -0700313 dokkaClasspathArgs string
314 aidlFlags string
Colin Cross3047fa22019-04-18 10:56:44 -0700315 aidlDeps android.Paths
Nan Zhanga40da042018-08-01 12:48:00 -0700316
Nan Zhanga40da042018-08-01 12:48:00 -0700317 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700318 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700319 postDoclavaCmds string
Nan Zhanga40da042018-08-01 12:48:00 -0700320}
321
322func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
323 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
324 android.InitDefaultableModule(module)
325}
326
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200327func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
328 if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
329 return false
330 } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700331 return true
332 } else if String(apiToCheck.Api_file) != "" {
333 panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
334 } else if String(apiToCheck.Removed_api_file) != "" {
335 panic("for " + apiVersionTag + " api_file has to be non-empty!")
336 }
337
338 return false
339}
340
Inseob Kim38449af2019-02-28 14:24:05 +0900341func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
342 api_file := String(apiToCheck.Api_file)
343 removed_api_file := String(apiToCheck.Removed_api_file)
344
345 api_module := android.SrcIsModule(api_file)
346 removed_api_module := android.SrcIsModule(removed_api_file)
347
348 if api_module == "" || removed_api_module == "" {
349 return
350 }
351
352 if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
353 return
354 }
355
356 apiToCheck.Api_file = nil
357 apiToCheck.Removed_api_file = nil
358}
359
Paul Duffin3d1248c2020-04-09 00:10:17 +0100360// Used by xsd_config
Nan Zhang1598a9e2018-09-04 17:14:32 -0700361type ApiFilePath interface {
362 ApiFilePath() android.Path
363}
364
Paul Duffin0f8faff2020-05-20 16:18:00 +0100365type ApiStubsSrcProvider interface {
366 StubsSrcJar() android.Path
367}
368
Paul Duffin3d1248c2020-04-09 00:10:17 +0100369// Provider of information about API stubs, used by java_sdk_library.
370type ApiStubsProvider interface {
371 ApiFilePath
Paul Duffin1fd005d2020-04-09 01:08:11 +0100372 RemovedApiFilePath() android.Path
Paul Duffin0f8faff2020-05-20 16:18:00 +0100373
374 ApiStubsSrcProvider
Paul Duffin3d1248c2020-04-09 00:10:17 +0100375}
376
Nan Zhanga40da042018-08-01 12:48:00 -0700377//
378// Javadoc
379//
Nan Zhang581fd212018-01-10 16:06:12 -0800380type Javadoc struct {
381 android.ModuleBase
382 android.DefaultableModuleBase
383
384 properties JavadocProperties
385
386 srcJars android.Paths
387 srcFiles android.Paths
388 sourcepaths android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700389 argFiles android.Paths
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400390 implicits android.Paths
Nan Zhang1598a9e2018-09-04 17:14:32 -0700391
Liz Kammer585cac22020-07-06 09:12:57 -0700392 args []string
Nan Zhang581fd212018-01-10 16:06:12 -0800393
Nan Zhangccff0f72018-03-08 17:26:16 -0800394 docZip android.WritablePath
395 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800396}
397
Colin Cross41955e82019-05-29 14:40:35 -0700398func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) {
399 switch tag {
400 case "":
401 return android.Paths{j.stubsSrcJar}, nil
Colin Crosse68e5542019-08-12 13:11:40 -0700402 case ".docs.zip":
403 return android.Paths{j.docZip}, nil
Colin Cross41955e82019-05-29 14:40:35 -0700404 default:
405 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
406 }
Nan Zhangb2b33de2018-02-23 11:18:47 -0800407}
408
Colin Crossa3002fc2019-07-08 16:48:04 -0700409// javadoc converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800410func JavadocFactory() android.Module {
411 module := &Javadoc{}
412
413 module.AddProperties(&module.properties)
414
415 InitDroiddocModule(module, android.HostAndDeviceSupported)
416 return module
417}
418
Colin Crossa3002fc2019-07-08 16:48:04 -0700419// javadoc_host converts .java source files to documentation using javadoc.
Nan Zhang581fd212018-01-10 16:06:12 -0800420func JavadocHostFactory() android.Module {
421 module := &Javadoc{}
422
423 module.AddProperties(&module.properties)
424
425 InitDroiddocModule(module, android.HostSupported)
426 return module
427}
428
Colin Cross41955e82019-05-29 14:40:35 -0700429var _ android.OutputFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800430
Jiyong Park6a927c42020-01-21 02:03:43 +0900431func (j *Javadoc) sdkVersion() sdkSpec {
432 return sdkSpecFrom(String(j.properties.Sdk_version))
Colin Cross83bb3162018-06-25 15:48:06 -0700433}
434
Paul Duffine25c6442019-10-11 13:50:28 +0100435func (j *Javadoc) systemModules() string {
436 return proptools.String(j.properties.System_modules)
437}
438
Jiyong Park6a927c42020-01-21 02:03:43 +0900439func (j *Javadoc) minSdkVersion() sdkSpec {
Colin Cross83bb3162018-06-25 15:48:06 -0700440 return j.sdkVersion()
441}
442
Jiyong Park6a927c42020-01-21 02:03:43 +0900443func (j *Javadoc) targetSdkVersion() sdkSpec {
Dan Willemsen419290a2018-10-31 15:28:47 -0700444 return j.sdkVersion()
445}
446
Nan Zhang581fd212018-01-10 16:06:12 -0800447func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
448 if ctx.Device() {
Paul Duffin250e6192019-06-07 10:44:37 +0100449 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Pete Gilline3d44b22020-06-29 11:28:51 +0100450 if sdkDep.useModule {
Colin Cross6cef4812019-10-17 14:23:50 -0700451 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
Paul Duffine25c6442019-10-11 13:50:28 +0100452 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Colin Cross6cef4812019-10-17 14:23:50 -0700453 ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
Pete Gilline3d44b22020-06-29 11:28:51 +0100454 ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800455 }
456 }
457
Colin Cross42d48b72018-08-29 14:10:52 -0700458 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800459}
460
Nan Zhanga40da042018-08-01 12:48:00 -0700461func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
462 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900463
Colin Cross3047fa22019-04-18 10:56:44 -0700464 flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
Jiyong Park1e440682018-05-23 18:42:04 +0900465
466 return flags
467}
468
469func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
Colin Cross3047fa22019-04-18 10:56:44 -0700470 aidlIncludeDirs android.Paths) (string, android.Paths) {
Jiyong Park1e440682018-05-23 18:42:04 +0900471
472 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
473 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
474
475 var flags []string
Colin Cross3047fa22019-04-18 10:56:44 -0700476 var deps android.Paths
477
Jiyong Park1e440682018-05-23 18:42:04 +0900478 if aidlPreprocess.Valid() {
479 flags = append(flags, "-p"+aidlPreprocess.String())
Colin Cross3047fa22019-04-18 10:56:44 -0700480 deps = append(deps, aidlPreprocess.Path())
Jiyong Park1e440682018-05-23 18:42:04 +0900481 } else {
482 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
483 }
484
485 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
486 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
487 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
488 flags = append(flags, "-I"+src.String())
489 }
490
Colin Cross3047fa22019-04-18 10:56:44 -0700491 return strings.Join(flags, " "), deps
Jiyong Park1e440682018-05-23 18:42:04 +0900492}
493
Jiyong Parkd90d7412019-08-20 22:49:19 +0900494// TODO: remove the duplication between this and the one in gen.go
Jiyong Park1e440682018-05-23 18:42:04 +0900495func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700496 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900497
498 outSrcFiles := make(android.Paths, 0, len(srcFiles))
Colin Crossc0806172019-06-14 18:51:47 -0700499 var aidlSrcs android.Paths
Jiyong Park1e440682018-05-23 18:42:04 +0900500
Jiyong Park1112c4c2019-08-16 21:12:10 +0900501 aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
502
Jiyong Park1e440682018-05-23 18:42:04 +0900503 for _, srcFile := range srcFiles {
504 switch srcFile.Ext() {
505 case ".aidl":
Colin Crossc0806172019-06-14 18:51:47 -0700506 aidlSrcs = append(aidlSrcs, srcFile)
Jiyong Parkd90d7412019-08-20 22:49:19 +0900507 case ".logtags":
508 javaFile := genLogtags(ctx, srcFile)
509 outSrcFiles = append(outSrcFiles, javaFile)
Jiyong Park1e440682018-05-23 18:42:04 +0900510 default:
511 outSrcFiles = append(outSrcFiles, srcFile)
512 }
513 }
514
Colin Crossc0806172019-06-14 18:51:47 -0700515 // Process all aidl files together to support sharding them into one or more rules that produce srcjars.
516 if len(aidlSrcs) > 0 {
517 srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
518 outSrcFiles = append(outSrcFiles, srcJarFiles...)
519 }
520
Jiyong Park1e440682018-05-23 18:42:04 +0900521 return outSrcFiles
522}
523
Nan Zhang581fd212018-01-10 16:06:12 -0800524func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
525 var deps deps
526
Colin Cross83bb3162018-06-25 15:48:06 -0700527 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800528 if sdkDep.invalidVersion {
Colin Cross6cef4812019-10-17 14:23:50 -0700529 ctx.AddMissingDependencies(sdkDep.bootclasspath)
530 ctx.AddMissingDependencies(sdkDep.java9Classpath)
Nan Zhang581fd212018-01-10 16:06:12 -0800531 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700532 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Anton Hansson26bf49b2020-02-08 20:26:29 +0000533 deps.aidlPreprocess = sdkDep.aidl
534 } else {
535 deps.aidlPreprocess = sdkDep.aidl
Nan Zhang581fd212018-01-10 16:06:12 -0800536 }
537
538 ctx.VisitDirectDeps(func(module android.Module) {
539 otherName := ctx.OtherModuleName(module)
540 tag := ctx.OtherModuleDependencyTag(module)
541
Colin Cross2d24c1b2018-05-23 10:59:18 -0700542 switch tag {
543 case bootClasspathTag:
544 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800545 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Paul Duffin83a2d962019-11-19 19:44:10 +0000546 } else if sm, ok := module.(SystemModulesProvider); ok {
Paul Duffine25c6442019-10-11 13:50:28 +0100547 // A system modules dependency has been added to the bootclasspath
548 // so add its libs to the bootclasspath.
Paul Duffin83a2d962019-11-19 19:44:10 +0000549 deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700550 } else {
551 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
552 }
553 case libTag:
554 switch dep := module.(type) {
Colin Cross897d2ed2019-02-11 14:03:51 -0800555 case SdkLibraryDependency:
Paul Duffin649dadf2020-05-26 11:42:13 +0100556 deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700557 case Dependency:
Sundong Ahnba493602018-11-20 17:36:35 +0900558 deps.classpath = append(deps.classpath, dep.HeaderJars()...)
Jiyong Park19a7f252019-07-10 16:59:31 +0900559 deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700560 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800561 checkProducesJars(ctx, dep)
562 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800563 default:
564 ctx.ModuleErrorf("depends on non-java module %q", otherName)
565 }
Colin Cross6cef4812019-10-17 14:23:50 -0700566 case java9LibTag:
567 switch dep := module.(type) {
568 case Dependency:
569 deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
570 default:
571 ctx.ModuleErrorf("depends on non-java module %q", otherName)
572 }
Nan Zhang357466b2018-04-17 17:38:36 -0700573 case systemModulesTag:
574 if deps.systemModules != nil {
575 panic("Found two system module dependencies")
576 }
Paul Duffin83a2d962019-11-19 19:44:10 +0000577 sm := module.(SystemModulesProvider)
578 outputDir, outputDeps := sm.OutputDirAndDeps()
579 deps.systemModules = &systemModules{outputDir, outputDeps}
Nan Zhang581fd212018-01-10 16:06:12 -0800580 }
581 })
582 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
583 // may contain filegroup or genrule.
Colin Cross8a497952019-03-05 22:25:09 -0800584 srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400585 j.implicits = append(j.implicits, srcFiles...)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900586
587 filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path {
588 if filterPackages == nil {
589 return srcs
590 }
591 filtered := []android.Path{}
592 for _, src := range srcs {
593 if src.Ext() != ".java" {
594 // Don't filter-out non-Java (=generated sources) by package names. This is not ideal,
595 // but otherwise metalava emits stub sources having references to the generated AIDL classes
596 // in filtered-out pacages (e.g. com.android.internal.*).
597 // TODO(b/141149570) We need to fix this by introducing default private constructors or
598 // fixing metalava to not emit constructors having references to unknown classes.
599 filtered = append(filtered, src)
600 continue
601 }
602 packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".")
Jaewoong Jung3aff5782020-02-11 07:54:35 -0800603 if android.HasAnyPrefix(packageName, filterPackages) {
604 filtered = append(filtered, src)
Jiyong Parkc6ddccf2019-09-13 20:56:14 +0900605 }
606 }
607 return filtered
608 }
609 srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages)
610
Ramy Medhatc7965cd2020-04-30 03:08:37 -0400611 // While metalava needs package html files, it does not need them to be explicit on the command
612 // line. More importantly, the metalava rsp file is also used by the subsequent jdiff action if
613 // jdiff_enabled=true. javadoc complains if it receives html files on the command line. The filter
614 // below excludes html files from the rsp file for both metalava and jdiff. Note that the html
615 // files are still included as implicit inputs for successful remote execution and correct
616 // incremental builds.
617 filterHtml := func(srcs []android.Path) []android.Path {
618 filtered := []android.Path{}
619 for _, src := range srcs {
620 if src.Ext() == ".html" {
621 continue
622 }
623 filtered = append(filtered, src)
624 }
625 return filtered
626 }
627 srcFiles = filterHtml(srcFiles)
628
Liz Kammer585cac22020-07-06 09:12:57 -0700629 aidlFlags := j.collectAidlFlags(ctx, deps)
630 srcFiles = j.genSources(ctx, srcFiles, aidlFlags)
Nan Zhang581fd212018-01-10 16:06:12 -0800631
632 // srcs may depend on some genrule output.
633 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800634 j.srcJars = append(j.srcJars, deps.srcJars...)
635
Nan Zhang581fd212018-01-10 16:06:12 -0800636 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800637 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800638
Nan Zhang9c69a122018-08-22 10:22:08 -0700639 if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 {
Nan Zhang581fd212018-01-10 16:06:12 -0800640 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
641 }
642 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800643
Colin Cross8a497952019-03-05 22:25:09 -0800644 j.argFiles = android.PathsForModuleSrc(ctx, j.properties.Arg_files)
Paul Duffin99e4a502019-02-11 15:38:42 +0000645 argFilesMap := map[string]string{}
646 argFileLabels := []string{}
Nan Zhang1598a9e2018-09-04 17:14:32 -0700647
Paul Duffin99e4a502019-02-11 15:38:42 +0000648 for _, label := range j.properties.Arg_files {
Colin Cross8a497952019-03-05 22:25:09 -0800649 var paths = android.PathsForModuleSrc(ctx, []string{label})
Paul Duffin99e4a502019-02-11 15:38:42 +0000650 if _, exists := argFilesMap[label]; !exists {
651 argFilesMap[label] = strings.Join(paths.Strings(), " ")
652 argFileLabels = append(argFileLabels, label)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700653 } else {
654 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
Paul Duffin99e4a502019-02-11 15:38:42 +0000655 label, argFilesMap[label], paths)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700656 }
657 }
658
Liz Kammer585cac22020-07-06 09:12:57 -0700659 var argsPropertyName string
660 flags := make([]string, 0)
661 if j.properties.Args != nil && j.properties.Flags != nil {
662 ctx.PropertyErrorf("args", "flags is set. Cannot set args")
663 } else if args := proptools.String(j.properties.Args); args != "" {
664 flags = append(flags, args)
665 argsPropertyName = "args"
666 } else {
667 flags = append(flags, j.properties.Flags...)
668 argsPropertyName = "flags"
669 }
Nan Zhang1598a9e2018-09-04 17:14:32 -0700670
Liz Kammer585cac22020-07-06 09:12:57 -0700671 for _, flag := range flags {
672 args, err := android.Expand(flag, func(name string) (string, error) {
673 if strings.HasPrefix(name, "location ") {
674 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
675 if paths, ok := argFilesMap[label]; ok {
676 return paths, nil
677 } else {
678 return "", fmt.Errorf("unknown location label %q, expecting one of %q",
679 label, strings.Join(argFileLabels, ", "))
680 }
681 } else if name == "genDir" {
682 return android.PathForModuleGen(ctx).String(), nil
683 }
684 return "", fmt.Errorf("unknown variable '$(%s)'", name)
685 })
686
687 if err != nil {
688 ctx.PropertyErrorf(argsPropertyName, "%s", err.Error())
689 }
690 j.args = append(j.args, args)
Nan Zhang1598a9e2018-09-04 17:14:32 -0700691 }
692
Nan Zhang581fd212018-01-10 16:06:12 -0800693 return deps
694}
695
696func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
697 j.addDeps(ctx)
698}
699
700func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
701 deps := j.collectDeps(ctx)
702
Colin Crossdaa4c672019-07-15 22:53:46 -0700703 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhang581fd212018-01-10 16:06:12 -0800704
Colin Crossdaa4c672019-07-15 22:53:46 -0700705 outDir := android.PathForModuleOut(ctx, "out")
706 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
707
708 j.stubsSrcJar = nil
709
710 rule := android.NewRuleBuilder()
711
712 rule.Command().Text("rm -rf").Text(outDir.String())
713 rule.Command().Text("mkdir -p").Text(outDir.String())
714
715 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars)
Nan Zhang357466b2018-04-17 17:38:36 -0700716
Colin Cross83bb3162018-06-25 15:48:06 -0700717 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800718
Colin Crossdaa4c672019-07-15 22:53:46 -0700719 cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList,
720 deps.systemModules, deps.classpath, j.sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800721
Colin Cross1e743852019-10-28 11:37:20 -0700722 cmd.FlagWithArg("-source ", javaVersion.String()).
Colin Crossdaa4c672019-07-15 22:53:46 -0700723 Flag("-J-Xmx1024m").
724 Flag("-XDignore.symbol.file").
725 Flag("-Xdoclint:none")
Nan Zhang581fd212018-01-10 16:06:12 -0800726
Colin Crossdaa4c672019-07-15 22:53:46 -0700727 rule.Command().
728 BuiltTool(ctx, "soong_zip").
729 Flag("-write_if_changed").
730 Flag("-d").
731 FlagWithOutput("-o ", j.docZip).
732 FlagWithArg("-C ", outDir.String()).
733 FlagWithArg("-D ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -0700734
Colin Crossdaa4c672019-07-15 22:53:46 -0700735 rule.Restat()
736
737 zipSyncCleanupCmd(rule, srcJarDir)
738
739 rule.Build(pctx, ctx, "javadoc", "javadoc")
Nan Zhang581fd212018-01-10 16:06:12 -0800740}
741
Nan Zhanga40da042018-08-01 12:48:00 -0700742//
743// Droiddoc
744//
745type Droiddoc struct {
746 Javadoc
747
748 properties DroiddocProperties
749 apiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700750 privateApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700751 removedApiFile android.WritablePath
752 removedDexApiFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700753
754 checkCurrentApiTimestamp android.WritablePath
755 updateCurrentApiTimestamp android.WritablePath
756 checkLastReleasedApiTimestamp android.WritablePath
757
Nan Zhanga40da042018-08-01 12:48:00 -0700758 apiFilePath android.Path
759}
760
Colin Crossa3002fc2019-07-08 16:48:04 -0700761// droiddoc converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700762func DroiddocFactory() android.Module {
763 module := &Droiddoc{}
764
765 module.AddProperties(&module.properties,
766 &module.Javadoc.properties)
767
768 InitDroiddocModule(module, android.HostAndDeviceSupported)
769 return module
770}
771
Colin Crossa3002fc2019-07-08 16:48:04 -0700772// droiddoc_host converts .java source files to documentation using doclava or dokka.
Nan Zhanga40da042018-08-01 12:48:00 -0700773func DroiddocHostFactory() android.Module {
774 module := &Droiddoc{}
775
776 module.AddProperties(&module.properties,
777 &module.Javadoc.properties)
778
779 InitDroiddocModule(module, android.HostSupported)
780 return module
781}
782
783func (d *Droiddoc) ApiFilePath() android.Path {
784 return d.apiFilePath
785}
786
Nan Zhang581fd212018-01-10 16:06:12 -0800787func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
788 d.Javadoc.addDeps(ctx)
789
Inseob Kim38449af2019-02-28 14:24:05 +0900790 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
791 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
792 }
793
Nan Zhang79614d12018-04-19 18:03:39 -0700794 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800795 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
796 }
Nan Zhang581fd212018-01-10 16:06:12 -0800797}
798
Colin Crossab054432019-07-15 16:13:59 -0700799func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) {
Colin Cross2a2e0db2020-02-21 16:55:46 -0800800 buildNumberFile := ctx.Config().BuildNumberFile(ctx)
Nan Zhang443fa522018-08-20 20:58:28 -0700801 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
802 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
803 // 1.9 language features.
Colin Crossab054432019-07-15 16:13:59 -0700804 cmd.FlagWithArg("-source ", "1.8").
805 Flag("-J-Xmx1600m").
806 Flag("-J-XX:-OmitStackTraceInFastThrow").
807 Flag("-XDignore.symbol.file").
808 FlagWithArg("-doclet ", "com.google.doclava.Doclava").
809 FlagWithInputList("-docletpath ", docletPath.Paths(), ":").
Colin Cross2a2e0db2020-02-21 16:55:46 -0800810 FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile).
Elliott Hughes26bce342019-09-12 15:05:13 -0700811 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 -0700812
Nan Zhanga40da042018-08-01 12:48:00 -0700813 if String(d.properties.Custom_template) == "" {
814 // TODO: This is almost always droiddoc-templates-sdk
815 ctx.PropertyErrorf("custom_template", "must specify a template")
816 }
817
818 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
Nan Zhangf4936b02018-08-01 15:00:28 -0700819 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Crossab054432019-07-15 16:13:59 -0700820 cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps)
Nan Zhanga40da042018-08-01 12:48:00 -0700821 } else {
Paul Duffin884363e2019-12-19 10:21:09 +0000822 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m))
Nan Zhanga40da042018-08-01 12:48:00 -0700823 }
824 })
825
826 if len(d.properties.Html_dirs) > 0 {
Colin Crossab054432019-07-15 16:13:59 -0700827 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
828 cmd.FlagWithArg("-htmldir ", htmlDir.String()).
829 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700830 }
831
832 if len(d.properties.Html_dirs) > 1 {
Colin Crossab054432019-07-15 16:13:59 -0700833 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
834 cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()).
835 Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")}))
Nan Zhanga40da042018-08-01 12:48:00 -0700836 }
837
838 if len(d.properties.Html_dirs) > 2 {
839 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
840 }
841
Colin Cross8a497952019-03-05 22:25:09 -0800842 knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags)
Colin Crossab054432019-07-15 16:13:59 -0700843 cmd.FlagForEachInput("-knowntags ", knownTags)
Nan Zhanga40da042018-08-01 12:48:00 -0700844
Colin Crossab054432019-07-15 16:13:59 -0700845 cmd.FlagForEachArg("-hdf ", d.properties.Hdf)
Nan Zhanga40da042018-08-01 12:48:00 -0700846
847 if String(d.properties.Proofread_file) != "" {
848 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
Colin Crossab054432019-07-15 16:13:59 -0700849 cmd.FlagWithOutput("-proofread ", proofreadFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700850 }
851
852 if String(d.properties.Todo_file) != "" {
853 // tricky part:
854 // we should not compute full path for todo_file through PathForModuleOut().
855 // the non-standard doclet will get the full path relative to "-o".
Colin Crossab054432019-07-15 16:13:59 -0700856 cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)).
857 ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file)))
Nan Zhanga40da042018-08-01 12:48:00 -0700858 }
859
860 if String(d.properties.Resourcesdir) != "" {
861 // TODO: should we add files under resourcesDir to the implicits? It seems that
862 // resourcesDir is one sub dir of htmlDir
863 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
Colin Crossab054432019-07-15 16:13:59 -0700864 cmd.FlagWithArg("-resourcesdir ", resourcesDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700865 }
866
867 if String(d.properties.Resourcesoutdir) != "" {
868 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
Colin Crossab054432019-07-15 16:13:59 -0700869 cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir))
Nan Zhanga40da042018-08-01 12:48:00 -0700870 }
Nan Zhanga40da042018-08-01 12:48:00 -0700871}
872
Colin Crossab054432019-07-15 16:13:59 -0700873func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200874 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
875 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700876 String(d.properties.Api_filename) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700877
Nan Zhanga40da042018-08-01 12:48:00 -0700878 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Crossab054432019-07-15 16:13:59 -0700879 cmd.FlagWithOutput("-api ", d.apiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700880 d.apiFilePath = d.apiFile
881 }
882
Luca Stefanid63ea0a2019-09-01 21:49:45 +0200883 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
884 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -0700885 String(d.properties.Removed_api_filename) != "" {
Nan Zhanga40da042018-08-01 12:48:00 -0700886 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Crossab054432019-07-15 16:13:59 -0700887 cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700888 }
889
Nan Zhanga40da042018-08-01 12:48:00 -0700890 if String(d.properties.Removed_dex_api_filename) != "" {
891 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Crossab054432019-07-15 16:13:59 -0700892 cmd.FlagWithOutput("-removedDexApi ", d.removedDexApiFile)
Nan Zhanga40da042018-08-01 12:48:00 -0700893 }
894
Nan Zhanga40da042018-08-01 12:48:00 -0700895 if BoolDefault(d.properties.Create_stubs, true) {
Colin Crossab054432019-07-15 16:13:59 -0700896 cmd.FlagWithArg("-stubs ", stubsDir.String())
Nan Zhanga40da042018-08-01 12:48:00 -0700897 }
898
899 if Bool(d.properties.Write_sdk_values) {
Colin Crossab054432019-07-15 16:13:59 -0700900 cmd.FlagWithArg("-sdkvalues ", android.PathForModuleOut(ctx, "out").String())
Nan Zhanga40da042018-08-01 12:48:00 -0700901 }
Nan Zhanga40da042018-08-01 12:48:00 -0700902}
903
Colin Crossab054432019-07-15 16:13:59 -0700904func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) {
Nan Zhanga40da042018-08-01 12:48:00 -0700905 if String(d.properties.Static_doc_index_redirect) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700906 staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect))
907 rule.Command().Text("cp").
908 Input(staticDocIndexRedirect).
909 Output(android.PathForModuleOut(ctx, "out", "index.html"))
Nan Zhanga40da042018-08-01 12:48:00 -0700910 }
911
912 if String(d.properties.Static_doc_properties) != "" {
Colin Crossab054432019-07-15 16:13:59 -0700913 staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties))
914 rule.Command().Text("cp").
915 Input(staticDocProperties).
916 Output(android.PathForModuleOut(ctx, "out", "source.properties"))
Nan Zhanga40da042018-08-01 12:48:00 -0700917 }
Nan Zhanga40da042018-08-01 12:48:00 -0700918}
919
Colin Crossab054432019-07-15 16:13:59 -0700920func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
Colin Crossdaa4c672019-07-15 22:53:46 -0700921 outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand {
Colin Crossab054432019-07-15 16:13:59 -0700922
923 cmd := rule.Command().
924 BuiltTool(ctx, "soong_javac_wrapper").Tool(config.JavadocCmd(ctx)).
925 Flag(config.JavacVmFlags).
926 FlagWithArg("-encoding ", "UTF-8").
Colin Crossab054432019-07-15 16:13:59 -0700927 FlagWithRspFileInputList("@", srcs).
928 FlagWithInput("@", srcJarList)
929
Colin Crossab054432019-07-15 16:13:59 -0700930 // TODO(ccross): Remove this if- statement once we finish migration for all Doclava
931 // based stubs generation.
932 // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar
933 // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out
934 // the correct package name base path.
935 if len(sourcepaths) > 0 {
936 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
937 } else {
938 cmd.FlagWithArg("-sourcepath ", srcJarDir.String())
939 }
940
941 cmd.FlagWithArg("-d ", outDir.String()).
942 Flag("-quiet")
943
944 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700945}
946
Colin Crossdaa4c672019-07-15 22:53:46 -0700947func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
948 outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules,
949 classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand {
950
951 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
952
953 flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device())
954 cmd.Flag(flag).Implicits(deps)
955
956 cmd.FlagWithArg("--patch-module ", "java.base=.")
957
958 if len(classpath) > 0 {
959 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
960 }
961
962 return cmd
Nan Zhang1598a9e2018-09-04 17:14:32 -0700963}
964
Colin Crossdaa4c672019-07-15 22:53:46 -0700965func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths,
966 outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath,
967 sourcepaths android.Paths) *android.RuleBuilderCommand {
968
969 cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths)
970
971 if len(bootclasspath) == 0 && ctx.Device() {
972 // explicitly specify -bootclasspath "" if the bootclasspath is empty to
973 // ensure java does not fall back to the default bootclasspath.
974 cmd.FlagWithArg("-bootclasspath ", `""`)
975 } else if len(bootclasspath) > 0 {
976 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
977 }
978
979 if len(classpath) > 0 {
980 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
981 }
982
983 return cmd
984}
985
Colin Crossab054432019-07-15 16:13:59 -0700986func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
987 outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand {
Nan Zhang1598a9e2018-09-04 17:14:32 -0700988
Colin Crossab054432019-07-15 16:13:59 -0700989 // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka.
990 dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...)
991
992 return rule.Command().
993 BuiltTool(ctx, "dokka").
994 Flag(config.JavacVmFlags).
995 Flag(srcJarDir.String()).
996 FlagWithInputList("-classpath ", dokkaClasspath, ":").
997 FlagWithArg("-format ", "dac").
998 FlagWithArg("-dacRoot ", "/reference/kotlin").
999 FlagWithArg("-output ", outDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001000}
1001
1002func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1003 deps := d.Javadoc.collectDeps(ctx)
1004
Colin Crossdaa4c672019-07-15 22:53:46 -07001005 d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
1006 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1007
Nan Zhang1598a9e2018-09-04 17:14:32 -07001008 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1009 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1010 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1011 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
1012
Colin Crossab054432019-07-15 16:13:59 -07001013 outDir := android.PathForModuleOut(ctx, "out")
1014 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
1015 stubsDir := android.PathForModuleOut(ctx, "stubsDir")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001016
Colin Crossab054432019-07-15 16:13:59 -07001017 rule := android.NewRuleBuilder()
Nan Zhang1598a9e2018-09-04 17:14:32 -07001018
Colin Crossab054432019-07-15 16:13:59 -07001019 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1020 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang1598a9e2018-09-04 17:14:32 -07001021
Colin Crossab054432019-07-15 16:13:59 -07001022 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1023
1024 var cmd *android.RuleBuilderCommand
Nan Zhang1598a9e2018-09-04 17:14:32 -07001025 if Bool(d.properties.Dokka_enabled) {
Colin Crossab054432019-07-15 16:13:59 -07001026 cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001027 } else {
Colin Crossdaa4c672019-07-15 22:53:46 -07001028 cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001029 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001030 }
1031
Colin Crossab054432019-07-15 16:13:59 -07001032 d.stubsFlags(ctx, cmd, stubsDir)
1033
Liz Kammer585cac22020-07-06 09:12:57 -07001034 cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
Colin Crossab054432019-07-15 16:13:59 -07001035
Mathew Inwoodabd49ab2019-12-19 14:27:08 +00001036 if d.properties.Compat_config != nil {
1037 compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config))
1038 cmd.FlagWithInput("-compatconfig ", compatConfig)
1039 }
1040
Colin Crossab054432019-07-15 16:13:59 -07001041 var desc string
1042 if Bool(d.properties.Dokka_enabled) {
1043 desc = "dokka"
1044 } else {
1045 d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava})
1046
1047 for _, o := range d.Javadoc.properties.Out {
1048 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1049 }
1050
1051 d.postDoclavaCmds(ctx, rule)
1052 desc = "doclava"
1053 }
1054
1055 rule.Command().
1056 BuiltTool(ctx, "soong_zip").
1057 Flag("-write_if_changed").
1058 Flag("-d").
1059 FlagWithOutput("-o ", d.docZip).
1060 FlagWithArg("-C ", outDir.String()).
1061 FlagWithArg("-D ", outDir.String())
1062
1063 rule.Command().
1064 BuiltTool(ctx, "soong_zip").
1065 Flag("-write_if_changed").
1066 Flag("-jar").
1067 FlagWithOutput("-o ", d.stubsSrcJar).
1068 FlagWithArg("-C ", stubsDir.String()).
1069 FlagWithArg("-D ", stubsDir.String())
1070
1071 rule.Restat()
1072
1073 zipSyncCleanupCmd(rule, srcJarDir)
1074
1075 rule.Build(pctx, ctx, "javadoc", desc)
1076
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001077 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001078 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001079
1080 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1081 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001082
1083 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001084
1085 rule := android.NewRuleBuilder()
1086
1087 rule.Command().Text("( true")
1088
1089 rule.Command().
1090 BuiltTool(ctx, "apicheck").
1091 Flag("-JXmx1024m").
1092 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1093 OptionalFlag(d.properties.Check_api.Current.Args).
1094 Input(apiFile).
1095 Input(d.apiFile).
1096 Input(removedApiFile).
1097 Input(d.removedApiFile)
1098
1099 msg := fmt.Sprintf(`\n******************************\n`+
1100 `You have tried to change the API from what has been previously approved.\n\n`+
1101 `To make these errors go away, you have two choices:\n`+
1102 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1103 ` errors above.\n\n`+
1104 ` 2. You can update current.txt by executing the following command:\n`+
1105 ` make %s-update-current-api\n\n`+
1106 ` To submit the revised current.txt to the main Android repository,\n`+
1107 ` you will need approval.\n`+
1108 `******************************\n`, ctx.ModuleName())
1109
1110 rule.Command().
1111 Text("touch").Output(d.checkCurrentApiTimestamp).
1112 Text(") || (").
1113 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1114 Text("; exit 38").
1115 Text(")")
1116
1117 rule.Build(pctx, ctx, "doclavaCurrentApiCheck", "check current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001118
1119 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001120
1121 // update API rule
1122 rule = android.NewRuleBuilder()
1123
1124 rule.Command().Text("( true")
1125
1126 rule.Command().
1127 Text("cp").Flag("-f").
1128 Input(d.apiFile).Flag(apiFile.String())
1129
1130 rule.Command().
1131 Text("cp").Flag("-f").
1132 Input(d.removedApiFile).Flag(removedApiFile.String())
1133
1134 msg = "failed to update public API"
1135
1136 rule.Command().
1137 Text("touch").Output(d.updateCurrentApiTimestamp).
1138 Text(") || (").
1139 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1140 Text("; exit 38").
1141 Text(")")
1142
1143 rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001144 }
1145
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001146 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001147 !ctx.Config().IsPdkBuild() {
Colin Crossab054432019-07-15 16:13:59 -07001148
1149 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1150 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
Nan Zhang1598a9e2018-09-04 17:14:32 -07001151
1152 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Colin Crossab054432019-07-15 16:13:59 -07001153
1154 rule := android.NewRuleBuilder()
1155
1156 rule.Command().
1157 Text("(").
1158 BuiltTool(ctx, "apicheck").
1159 Flag("-JXmx1024m").
1160 FlagWithInputList("-Jclasspath\\ ", checkApiClasspath.Paths(), ":").
1161 OptionalFlag(d.properties.Check_api.Last_released.Args).
1162 Input(apiFile).
1163 Input(d.apiFile).
1164 Input(removedApiFile).
1165 Input(d.removedApiFile)
1166
1167 msg := `\n******************************\n` +
1168 `You have tried to change the API from what has been previously released in\n` +
1169 `an SDK. Please fix the errors listed above.\n` +
1170 `******************************\n`
1171
1172 rule.Command().
1173 Text("touch").Output(d.checkLastReleasedApiTimestamp).
1174 Text(") || (").
1175 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1176 Text("; exit 38").
1177 Text(")")
1178
1179 rule.Build(pctx, ctx, "doclavaLastApiCheck", "check last API")
Nan Zhang1598a9e2018-09-04 17:14:32 -07001180 }
1181}
1182
1183//
1184// Droidstubs
1185//
1186type Droidstubs struct {
1187 Javadoc
Paul Duffin91547182019-11-12 19:39:36 +00001188 android.SdkBase
Nan Zhang1598a9e2018-09-04 17:14:32 -07001189
Pete Gillin581d6082018-10-22 15:55:04 +01001190 properties DroidstubsProperties
1191 apiFile android.WritablePath
1192 apiXmlFile android.WritablePath
1193 lastReleasedApiXmlFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001194 privateApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001195 removedApiFile android.WritablePath
1196 removedDexApiFile android.WritablePath
Pete Gillin581d6082018-10-22 15:55:04 +01001197 nullabilityWarningsFile android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001198
1199 checkCurrentApiTimestamp android.WritablePath
1200 updateCurrentApiTimestamp android.WritablePath
1201 checkLastReleasedApiTimestamp android.WritablePath
Adrian Roos075eedc2019-10-10 12:07:03 +02001202 apiLintTimestamp android.WritablePath
Adrian Roos3b8f1cd2019-11-01 13:42:39 +01001203 apiLintReport android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001204
Pete Gillin581d6082018-10-22 15:55:04 +01001205 checkNullabilityWarningsTimestamp android.WritablePath
1206
Nan Zhang1598a9e2018-09-04 17:14:32 -07001207 annotationsZip android.WritablePath
Nan Zhang9c69a122018-08-22 10:22:08 -07001208 apiVersionsXml android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001209
1210 apiFilePath android.Path
Nan Zhang71bbe632018-09-17 14:32:21 -07001211
1212 jdiffDocZip android.WritablePath
1213 jdiffStubsSrcJar android.WritablePath
Jerome Gaillard0f599032019-10-10 19:29:11 +01001214
1215 metadataZip android.WritablePath
1216 metadataDir android.WritablePath
Nan Zhang1598a9e2018-09-04 17:14:32 -07001217}
1218
Colin Crossa3002fc2019-07-08 16:48:04 -07001219// droidstubs passes sources files through Metalava to generate stub .java files that only contain the API to be
1220// documented, filtering out hidden classes and methods. The resulting .java files are intended to be passed to
1221// a droiddoc module to generate documentation.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001222func DroidstubsFactory() android.Module {
1223 module := &Droidstubs{}
1224
1225 module.AddProperties(&module.properties,
1226 &module.Javadoc.properties)
1227
1228 InitDroiddocModule(module, android.HostAndDeviceSupported)
Paul Duffin91547182019-11-12 19:39:36 +00001229 android.InitSdkAwareModule(module)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001230 return module
1231}
1232
Colin Crossa3002fc2019-07-08 16:48:04 -07001233// droidstubs_host passes sources files through Metalava to generate stub .java files that only contain the API
1234// to be documented, filtering out hidden classes and methods. The resulting .java files are intended to be
1235// passed to a droiddoc_host module to generate documentation. Use a droidstubs_host instead of a droidstubs
1236// module when symbols needed by the source files are provided by java_library_host modules.
Nan Zhang1598a9e2018-09-04 17:14:32 -07001237func DroidstubsHostFactory() android.Module {
1238 module := &Droidstubs{}
1239
1240 module.AddProperties(&module.properties,
1241 &module.Javadoc.properties)
1242
1243 InitDroiddocModule(module, android.HostSupported)
1244 return module
1245}
1246
Colin Cross014489c2020-06-02 20:09:13 -07001247func (d *Droidstubs) OutputFiles(tag string) (android.Paths, error) {
1248 switch tag {
1249 case "":
1250 return android.Paths{d.stubsSrcJar}, nil
1251 case ".docs.zip":
1252 return android.Paths{d.docZip}, nil
1253 case ".annotations.zip":
1254 return android.Paths{d.annotationsZip}, nil
1255 case ".api_versions.xml":
1256 return android.Paths{d.apiVersionsXml}, nil
1257 default:
1258 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
1259 }
1260}
1261
Nan Zhang1598a9e2018-09-04 17:14:32 -07001262func (d *Droidstubs) ApiFilePath() android.Path {
1263 return d.apiFilePath
1264}
1265
Paul Duffin1fd005d2020-04-09 01:08:11 +01001266func (d *Droidstubs) RemovedApiFilePath() android.Path {
1267 return d.removedApiFile
1268}
1269
Paul Duffin3d1248c2020-04-09 00:10:17 +01001270func (d *Droidstubs) StubsSrcJar() android.Path {
1271 return d.stubsSrcJar
1272}
1273
Nan Zhang1598a9e2018-09-04 17:14:32 -07001274func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
1275 d.Javadoc.addDeps(ctx)
1276
Paul Duffin160fe412020-05-10 19:32:20 +01001277 // If requested clear any properties that provide information about the latest version
1278 // of an API and which reference non-existent modules.
Inseob Kim38449af2019-02-28 14:24:05 +09001279 if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
1280 ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
Paul Duffin160fe412020-05-10 19:32:20 +01001281
1282 // If the new_since references a module, e.g. :module-latest-api and the module
1283 // does not exist then clear it.
1284 newSinceSrc := d.properties.Check_api.Api_lint.New_since
1285 newSinceSrcModule := android.SrcIsModule(proptools.String(newSinceSrc))
1286 if newSinceSrcModule != "" && !ctx.OtherModuleExists(newSinceSrcModule) {
1287 d.properties.Check_api.Api_lint.New_since = nil
1288 }
Inseob Kim38449af2019-02-28 14:24:05 +09001289 }
1290
Nan Zhang1598a9e2018-09-04 17:14:32 -07001291 if len(d.properties.Merge_annotations_dirs) != 0 {
1292 for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs {
1293 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
1294 }
1295 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001296
Pete Gillin77167902018-09-19 18:16:26 +01001297 if len(d.properties.Merge_inclusion_annotations_dirs) != 0 {
1298 for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs {
1299 ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir)
1300 }
1301 }
1302
Nan Zhang9c69a122018-08-22 10:22:08 -07001303 if len(d.properties.Api_levels_annotations_dirs) != 0 {
1304 for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs {
1305 ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir)
1306 }
1307 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001308}
1309
Paul Duffin3ae29512020-04-08 18:18:03 +01001310func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001311 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1312 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001313 String(d.properties.Api_filename) != "" {
1314 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001315 cmd.FlagWithOutput("--api ", d.apiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001316 d.apiFilePath = d.apiFile
1317 }
1318
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001319 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
1320 apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
Nan Zhang1598a9e2018-09-04 17:14:32 -07001321 String(d.properties.Removed_api_filename) != "" {
1322 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001323 cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001324 }
1325
Nan Zhang1598a9e2018-09-04 17:14:32 -07001326 if String(d.properties.Removed_dex_api_filename) != "" {
1327 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
Colin Cross33961b52019-07-11 11:01:22 -07001328 cmd.FlagWithOutput("--removed-dex-api ", d.removedDexApiFile)
Nan Zhang1598a9e2018-09-04 17:14:32 -07001329 }
1330
Nan Zhang9c69a122018-08-22 10:22:08 -07001331 if Bool(d.properties.Write_sdk_values) {
Jerome Gaillard0f599032019-10-10 19:29:11 +01001332 d.metadataDir = android.PathForModuleOut(ctx, "metadata")
1333 cmd.FlagWithArg("--sdk-values ", d.metadataDir.String())
Nan Zhang9c69a122018-08-22 10:22:08 -07001334 }
1335
Paul Duffin3ae29512020-04-08 18:18:03 +01001336 if stubsDir.Valid() {
1337 if Bool(d.properties.Create_doc_stubs) {
1338 cmd.FlagWithArg("--doc-stubs ", stubsDir.String())
1339 } else {
1340 cmd.FlagWithArg("--stubs ", stubsDir.String())
1341 cmd.Flag("--exclude-documentation-from-stubs")
1342 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001343 }
Nan Zhang1598a9e2018-09-04 17:14:32 -07001344}
1345
Colin Cross33961b52019-07-11 11:01:22 -07001346func (d *Droidstubs) annotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001347 if Bool(d.properties.Annotations_enabled) {
Colin Cross33961b52019-07-11 11:01:22 -07001348 cmd.Flag("--include-annotations")
1349
Pete Gillinc382a562018-11-14 18:45:46 +00001350 validatingNullability :=
Liz Kammer585cac22020-07-06 09:12:57 -07001351 android.InList("--validate-nullability-from-merged-stubs", d.Javadoc.args) ||
Pete Gillinc382a562018-11-14 18:45:46 +00001352 String(d.properties.Validate_nullability_from_list) != ""
Paul Duffin13a9dd62019-11-04 10:26:47 +00001353
Pete Gillina262c052018-09-14 14:25:48 +01001354 migratingNullability := String(d.properties.Previous_api) != ""
Pete Gillina262c052018-09-14 14:25:48 +01001355 if migratingNullability {
Colin Cross8a497952019-03-05 22:25:09 -08001356 previousApi := android.PathForModuleSrc(ctx, String(d.properties.Previous_api))
Colin Cross33961b52019-07-11 11:01:22 -07001357 cmd.FlagWithInput("--migrate-nullness ", previousApi)
Pete Gillina262c052018-09-14 14:25:48 +01001358 }
Colin Cross33961b52019-07-11 11:01:22 -07001359
Pete Gillinc382a562018-11-14 18:45:46 +00001360 if s := String(d.properties.Validate_nullability_from_list); s != "" {
Colin Cross33961b52019-07-11 11:01:22 -07001361 cmd.FlagWithInput("--validate-nullability-from-list ", android.PathForModuleSrc(ctx, s))
Pete Gillinc382a562018-11-14 18:45:46 +00001362 }
Colin Cross33961b52019-07-11 11:01:22 -07001363
Pete Gillina262c052018-09-14 14:25:48 +01001364 if validatingNullability {
Pete Gillin581d6082018-10-22 15:55:04 +01001365 d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt")
Colin Cross33961b52019-07-11 11:01:22 -07001366 cmd.FlagWithOutput("--nullability-warnings-txt ", d.nullabilityWarningsFile)
Pete Gillina262c052018-09-14 14:25:48 +01001367 }
Nan Zhanga40da042018-08-01 12:48:00 -07001368
1369 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
Colin Cross33961b52019-07-11 11:01:22 -07001370 cmd.FlagWithOutput("--extract-annotations ", d.annotationsZip)
Nan Zhangf4936b02018-08-01 15:00:28 -07001371
Anton Hansson9d7c3fb2020-05-21 10:11:31 +01001372 if len(d.properties.Merge_annotations_dirs) != 0 {
1373 d.mergeAnnoDirFlags(ctx, cmd)
Nan Zhanga40da042018-08-01 12:48:00 -07001374 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001375
Colin Cross33961b52019-07-11 11:01:22 -07001376 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1377 cmd.FlagWithArg("--hide ", "HiddenTypedefConstant").
1378 FlagWithArg("--hide ", "SuperfluousPrefix").
1379 FlagWithArg("--hide ", "AnnotationExtraction")
1380 }
Neil Fullerb2f14ec2018-10-21 22:13:19 +01001381}
1382
Colin Cross33961b52019-07-11 11:01:22 -07001383func (d *Droidstubs) mergeAnnoDirFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
1384 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1385 if t, ok := m.(*ExportedDroiddocDir); ok {
1386 cmd.FlagWithArg("--merge-qualifier-annotations ", t.dir.String()).Implicits(t.deps)
1387 } else {
1388 ctx.PropertyErrorf("merge_annotations_dirs",
1389 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1390 }
1391 })
1392}
1393
1394func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Pete Gillin77167902018-09-19 18:16:26 +01001395 ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) {
1396 if t, ok := m.(*ExportedDroiddocDir); ok {
Colin Cross33961b52019-07-11 11:01:22 -07001397 cmd.FlagWithArg("--merge-inclusion-annotations ", t.dir.String()).Implicits(t.deps)
Pete Gillin77167902018-09-19 18:16:26 +01001398 } else {
1399 ctx.PropertyErrorf("merge_inclusion_annotations_dirs",
1400 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1401 }
1402 })
Nan Zhanga40da042018-08-01 12:48:00 -07001403}
1404
Colin Cross33961b52019-07-11 11:01:22 -07001405func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Nan Zhang9c69a122018-08-22 10:22:08 -07001406 if Bool(d.properties.Api_levels_annotations_enabled) {
1407 d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")
Nan Zhang9c69a122018-08-22 10:22:08 -07001408
1409 if len(d.properties.Api_levels_annotations_dirs) == 0 {
1410 ctx.PropertyErrorf("api_levels_annotations_dirs",
1411 "has to be non-empty if api levels annotations was enabled!")
1412 }
1413
Colin Cross33961b52019-07-11 11:01:22 -07001414 cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml)
1415 cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml)
1416 cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
1417 cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())
Nan Zhang9c69a122018-08-22 10:22:08 -07001418
1419 ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
1420 if t, ok := m.(*ExportedDroiddocDir); ok {
Nan Zhang9c69a122018-08-22 10:22:08 -07001421 for _, dep := range t.deps {
1422 if strings.HasSuffix(dep.String(), "android.jar") {
Colin Cross33961b52019-07-11 11:01:22 -07001423 cmd.Implicit(dep)
Nan Zhang9c69a122018-08-22 10:22:08 -07001424 }
1425 }
Colin Cross33961b52019-07-11 11:01:22 -07001426 cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
Nan Zhang9c69a122018-08-22 10:22:08 -07001427 } else {
1428 ctx.PropertyErrorf("api_levels_annotations_dirs",
1429 "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
1430 }
1431 })
1432
1433 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001434}
1435
Colin Cross33961b52019-07-11 11:01:22 -07001436func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
Paul Duffin10269f12020-06-19 18:39:55 +01001437 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() && d.apiFile != nil {
Nan Zhang71bbe632018-09-17 14:32:21 -07001438 if d.apiFile.String() == "" {
1439 ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.")
1440 }
1441
1442 d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001443 cmd.FlagWithOutput("--api-xml ", d.apiXmlFile)
Nan Zhang71bbe632018-09-17 14:32:21 -07001444
1445 if String(d.properties.Check_api.Last_released.Api_file) == "" {
1446 ctx.PropertyErrorf("check_api.last_released.api_file",
1447 "has to be non-empty if jdiff was enabled!")
1448 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001449
Colin Cross33961b52019-07-11 11:01:22 -07001450 lastReleasedApi := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
Nan Zhang71bbe632018-09-17 14:32:21 -07001451 d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml")
Colin Cross33961b52019-07-11 11:01:22 -07001452 cmd.FlagWithInput("--convert-to-jdiff ", lastReleasedApi).Output(d.lastReleasedApiXmlFile)
1453 }
1454}
Nan Zhang71bbe632018-09-17 14:32:21 -07001455
Colin Cross1e743852019-10-28 11:37:20 -07001456func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersion javaVersion, srcs android.Paths,
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001457 srcJarList android.Path, bootclasspath, classpath classpath, sourcepaths android.Paths, implicitsRsp android.WritablePath, sandbox bool) *android.RuleBuilderCommand {
Colin Cross8b8bec32019-11-15 13:18:43 -08001458 // Metalava uses lots of memory, restrict the number of metalava jobs that can run in parallel.
1459 rule.HighMem()
Ramy Medhat427683c2020-04-30 03:08:37 -04001460 cmd := rule.Command()
1461 if ctx.Config().IsEnvTrue("RBE_METALAVA") {
1462 rule.Remoteable(android.RemoteRuleSupports{RBE: true})
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001463 pool := ctx.Config().GetenvWithDefault("RBE_METALAVA_POOL", "metalava")
1464 execStrategy := ctx.Config().GetenvWithDefault("RBE_METALAVA_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
1465 labels := map[string]string{"type": "compile", "lang": "java", "compiler": "metalava"}
1466 if !sandbox {
1467 execStrategy = remoteexec.LocalExecStrategy
1468 labels["shallow"] = "true"
Ramy Medhat427683c2020-04-30 03:08:37 -04001469 }
1470 inputs := []string{android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "metalava.jar").String()}
1471 if v := ctx.Config().Getenv("RBE_METALAVA_INPUTS"); v != "" {
1472 inputs = append(inputs, strings.Split(v, ",")...)
1473 }
1474 cmd.Text((&remoteexec.REParams{
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001475 Labels: labels,
Ramy Medhat427683c2020-04-30 03:08:37 -04001476 ExecStrategy: execStrategy,
1477 Inputs: inputs,
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001478 RSPFile: implicitsRsp.String(),
Ramy Medhat427683c2020-04-30 03:08:37 -04001479 ToolchainInputs: []string{config.JavaCmd(ctx).String()},
1480 Platform: map[string]string{remoteexec.PoolKey: pool},
1481 }).NoVarTemplate(ctx.Config()))
1482 }
1483
1484 cmd.BuiltTool(ctx, "metalava").
Colin Cross33961b52019-07-11 11:01:22 -07001485 Flag(config.JavacVmFlags).
1486 FlagWithArg("-encoding ", "UTF-8").
Colin Cross1e743852019-10-28 11:37:20 -07001487 FlagWithArg("-source ", javaVersion.String()).
Colin Cross33961b52019-07-11 11:01:22 -07001488 FlagWithRspFileInputList("@", srcs).
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001489 FlagWithInput("@", srcJarList)
1490
1491 if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" {
1492 cmd.Implicit(android.PathForSource(ctx, javaHome))
1493 }
1494
1495 if sandbox {
1496 cmd.FlagWithOutput("--strict-input-files ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
1497 } else {
1498 cmd.FlagWithOutput("--strict-input-files:warn ", android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"violations.txt"))
1499 }
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001500
Colin Cross238c1f32020-06-07 16:58:18 -07001501 if implicitsRsp != nil {
Ramy Medhatc8d60bc2020-06-04 01:54:07 -04001502 cmd.FlagWithArg("--strict-input-files-exempt ", "@"+implicitsRsp.String())
1503 }
Colin Cross33961b52019-07-11 11:01:22 -07001504
1505 if len(bootclasspath) > 0 {
1506 cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":")
Nan Zhang71bbe632018-09-17 14:32:21 -07001507 }
1508
Colin Cross33961b52019-07-11 11:01:22 -07001509 if len(classpath) > 0 {
1510 cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":")
1511 }
Nan Zhang71bbe632018-09-17 14:32:21 -07001512
Colin Cross33961b52019-07-11 11:01:22 -07001513 if len(sourcepaths) > 0 {
1514 cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":")
1515 } else {
1516 cmd.FlagWithArg("-sourcepath ", `""`)
1517 }
Nan Zhang9c69a122018-08-22 10:22:08 -07001518
Colin Cross33961b52019-07-11 11:01:22 -07001519 cmd.Flag("--no-banner").
1520 Flag("--color").
1521 Flag("--quiet").
1522 Flag("--format=v2")
Nan Zhang86d2d552018-08-09 15:33:27 -07001523
Colin Cross33961b52019-07-11 11:01:22 -07001524 return cmd
Nan Zhang71bbe632018-09-17 14:32:21 -07001525}
1526
Nan Zhang1598a9e2018-09-04 17:14:32 -07001527func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Nan Zhanga40da042018-08-01 12:48:00 -07001528 deps := d.Javadoc.collectDeps(ctx)
1529
1530 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhang581fd212018-01-10 16:06:12 -08001531
Colin Cross33961b52019-07-11 11:01:22 -07001532 // Create rule for metalava
Nan Zhanga40da042018-08-01 12:48:00 -07001533
Colin Cross33961b52019-07-11 11:01:22 -07001534 srcJarDir := android.PathForModuleOut(ctx, "srcjars")
Nan Zhang71bbe632018-09-17 14:32:21 -07001535
Colin Cross33961b52019-07-11 11:01:22 -07001536 rule := android.NewRuleBuilder()
Nan Zhanga40da042018-08-01 12:48:00 -07001537
Paul Duffin3ae29512020-04-08 18:18:03 +01001538 generateStubs := BoolDefault(d.properties.Generate_stubs, true)
1539 var stubsDir android.OptionalPath
1540 if generateStubs {
1541 d.Javadoc.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
1542 stubsDir = android.OptionalPathForPath(android.PathForModuleOut(ctx, "stubsDir"))
1543 rule.Command().Text("rm -rf").Text(stubsDir.String())
1544 rule.Command().Text("mkdir -p").Text(stubsDir.String())
1545 }
Nan Zhanga40da042018-08-01 12:48:00 -07001546
Colin Cross33961b52019-07-11 11:01:22 -07001547 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1548
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001549 implicitsRsp := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"implicits.rsp")
1550
Colin Cross33961b52019-07-11 11:01:22 -07001551 cmd := metalavaCmd(ctx, rule, javaVersion, d.Javadoc.srcFiles, srcJarList,
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001552 deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths, implicitsRsp,
1553 Bool(d.Javadoc.properties.Sandbox))
1554 cmd.Implicits(d.Javadoc.implicits)
Colin Cross33961b52019-07-11 11:01:22 -07001555
1556 d.stubsFlags(ctx, cmd, stubsDir)
1557
1558 d.annotationsFlags(ctx, cmd)
1559 d.inclusionAnnotationsFlags(ctx, cmd)
1560 d.apiLevelsAnnotationsFlags(ctx, cmd)
1561 d.apiToXmlFlags(ctx, cmd)
Nan Zhang71bbe632018-09-17 14:32:21 -07001562
Liz Kammer585cac22020-07-06 09:12:57 -07001563 if android.InList("--generate-documentation", d.Javadoc.args) {
Nan Zhang1598a9e2018-09-04 17:14:32 -07001564 // Currently Metalava have the ability to invoke Javadoc in a seperate process.
1565 // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives
1566 // "--generate-documentation" arg. This is not needed when Metalava removes this feature.
Liz Kammer585cac22020-07-06 09:12:57 -07001567 d.Javadoc.args = append(d.Javadoc.args, "-nodocs")
Nan Zhang79614d12018-04-19 18:03:39 -07001568 }
Colin Cross33961b52019-07-11 11:01:22 -07001569
Liz Kammer585cac22020-07-06 09:12:57 -07001570 cmd.Flag(strings.Join(d.Javadoc.args, " ")).Implicits(d.Javadoc.argFiles)
Colin Cross33961b52019-07-11 11:01:22 -07001571 for _, o := range d.Javadoc.properties.Out {
1572 cmd.ImplicitOutput(android.PathForModuleGen(ctx, o))
1573 }
1574
Makoto Onuki88b99052020-04-27 17:22:16 -07001575 // Add options for the other optional tasks: API-lint and check-released.
1576 // We generate separate timestamp files for them.
1577
1578 doApiLint := false
1579 doCheckReleased := false
1580
1581 // Add API lint options.
1582
1583 if BoolDefault(d.properties.Check_api.Api_lint.Enabled, false) && !ctx.Config().IsPdkBuild() {
1584 doApiLint = true
1585
1586 newSince := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.New_since)
1587 if newSince.Valid() {
1588 cmd.FlagWithInput("--api-lint ", newSince.Path())
1589 } else {
1590 cmd.Flag("--api-lint")
1591 }
1592 d.apiLintReport = android.PathForModuleOut(ctx, "api_lint_report.txt")
1593 cmd.FlagWithOutput("--report-even-if-suppressed ", d.apiLintReport) // TODO: Change to ":api-lint"
1594
1595 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Api_lint.Baseline_file)
1596 updatedBaselineOutput := android.PathForModuleOut(ctx, "api_lint_baseline.txt")
1597 d.apiLintTimestamp = android.PathForModuleOut(ctx, "api_lint.timestamp")
1598
1599 // Note this string includes a special shell quote $' ... ', which decodes the "\n"s.
1600 // However, because $' ... ' doesn't expand environmental variables, we can't just embed
1601 // $PWD, so we have to terminate $'...', use "$PWD", then start $' ... ' again,
1602 // which is why we have '"$PWD"$' in it.
1603 //
1604 // TODO: metalava also has a slightly different message hardcoded. Should we unify this
1605 // message and metalava's one?
1606 msg := `$'` + // Enclose with $' ... '
1607 `************************************************************\n` +
1608 `Your API changes are triggering API Lint warnings or errors.\n` +
1609 `To make these errors go away, fix the code according to the\n` +
1610 `error and/or warning messages above.\n` +
1611 `\n` +
1612 `If it is not possible to do so, there are workarounds:\n` +
1613 `\n` +
1614 `1. You can suppress the errors with @SuppressLint("<id>")\n`
1615
1616 if baselineFile.Valid() {
1617 cmd.FlagWithInput("--baseline:api-lint ", baselineFile.Path())
1618 cmd.FlagWithOutput("--update-baseline:api-lint ", updatedBaselineOutput)
1619
1620 msg += fmt.Sprintf(``+
1621 `2. You can update the baseline by executing the following\n`+
1622 ` command:\n`+
Anton Hansson3361a292020-05-11 15:38:31 +01001623 ` cp \\\n`+
1624 ` "'"$PWD"$'/%s" \\\n`+
1625 ` "'"$PWD"$'/%s"\n`+
Makoto Onuki88b99052020-04-27 17:22:16 -07001626 ` To submit the revised baseline.txt to the main Android\n`+
1627 ` repository, you will need approval.\n`, updatedBaselineOutput, baselineFile.Path())
1628 } else {
1629 msg += fmt.Sprintf(``+
1630 `2. You can add a baseline file of existing lint failures\n`+
1631 ` to the build rule of %s.\n`, d.Name())
1632 }
1633 // Note the message ends with a ' (single quote), to close the $' ... ' .
1634 msg += `************************************************************\n'`
1635
1636 cmd.FlagWithArg("--error-message:api-lint ", msg)
1637 }
1638
1639 // Add "check released" options. (Detect incompatible API changes from the last public release)
1640
1641 if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
1642 !ctx.Config().IsPdkBuild() {
1643 doCheckReleased = true
1644
1645 if len(d.Javadoc.properties.Out) > 0 {
1646 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1647 }
1648
1649 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
1650 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Removed_api_file))
1651 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Last_released.Baseline_file)
1652 updatedBaselineOutput := android.PathForModuleOut(ctx, "last_released_baseline.txt")
1653
1654 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
1655
1656 cmd.FlagWithInput("--check-compatibility:api:released ", apiFile)
1657 cmd.FlagWithInput("--check-compatibility:removed:released ", removedApiFile)
1658
1659 if baselineFile.Valid() {
1660 cmd.FlagWithInput("--baseline:compatibility:released ", baselineFile.Path())
1661 cmd.FlagWithOutput("--update-baseline:compatibility:released ", updatedBaselineOutput)
1662 }
1663
1664 // Note this string includes quote ($' ... '), which decodes the "\n"s.
1665 msg := `$'\n******************************\n` +
1666 `You have tried to change the API from what has been previously released in\n` +
1667 `an SDK. Please fix the errors listed above.\n` +
1668 `******************************\n'`
1669
1670 cmd.FlagWithArg("--error-message:compatibility:released ", msg)
1671 }
1672
Ramy Medhat2f99eec2020-06-13 17:38:27 -04001673 impRule := android.NewRuleBuilder()
1674 impCmd := impRule.Command()
1675 // A dummy action that copies the ninja generated rsp file to a new location. This allows us to
1676 // add a large number of inputs to a file without exceeding bash command length limits (which
1677 // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the
1678 // rsp file to be ${output}.rsp.
1679 impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp)
1680 impRule.Build(pctx, ctx, "implicitsGen", "implicits generation")
1681 cmd.Implicit(implicitsRsp)
1682
Paul Duffin3ae29512020-04-08 18:18:03 +01001683 if generateStubs {
1684 rule.Command().
1685 BuiltTool(ctx, "soong_zip").
1686 Flag("-write_if_changed").
1687 Flag("-jar").
1688 FlagWithOutput("-o ", d.Javadoc.stubsSrcJar).
1689 FlagWithArg("-C ", stubsDir.String()).
1690 FlagWithArg("-D ", stubsDir.String())
1691 }
Jerome Gaillard0f599032019-10-10 19:29:11 +01001692
1693 if Bool(d.properties.Write_sdk_values) {
1694 d.metadataZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-metadata.zip")
1695 rule.Command().
1696 BuiltTool(ctx, "soong_zip").
1697 Flag("-write_if_changed").
1698 Flag("-d").
1699 FlagWithOutput("-o ", d.metadataZip).
1700 FlagWithArg("-C ", d.metadataDir.String()).
1701 FlagWithArg("-D ", d.metadataDir.String())
1702 }
1703
Makoto Onuki88b99052020-04-27 17:22:16 -07001704 // TODO: We don't really need two separate API files, but this is a reminiscence of how
1705 // we used to run metalava separately for API lint and the "last_released" check. Unify them.
1706 if doApiLint {
1707 rule.Command().Text("touch").Output(d.apiLintTimestamp)
1708 }
1709 if doCheckReleased {
1710 rule.Command().Text("touch").Output(d.checkLastReleasedApiTimestamp)
1711 }
1712
Colin Cross33961b52019-07-11 11:01:22 -07001713 rule.Restat()
1714
1715 zipSyncCleanupCmd(rule, srcJarDir)
1716
Makoto Onuki88b99052020-04-27 17:22:16 -07001717 rule.Build(pctx, ctx, "metalava", "metalava merged")
Adrian Roos075eedc2019-10-10 12:07:03 +02001718
Luca Stefanid63ea0a2019-09-01 21:49:45 +02001719 if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
Nan Zhang1598a9e2018-09-04 17:14:32 -07001720 !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001721
1722 if len(d.Javadoc.properties.Out) > 0 {
1723 ctx.PropertyErrorf("out", "out property may not be combined with check_api")
1724 }
1725
1726 apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
1727 removedApiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Removed_api_file))
Adrian Roos14f75a92019-08-12 17:54:09 +02001728 baselineFile := android.OptionalPathForModuleSrc(ctx, d.properties.Check_api.Current.Baseline_file)
Makoto Onuki5405a732020-04-16 17:02:40 -07001729
1730 if baselineFile.Valid() {
Makoto Onuki88b99052020-04-27 17:22:16 -07001731 ctx.PropertyErrorf("baseline_file", "current API check can't have a baseline file. (module %s)", ctx.ModuleName())
Makoto Onuki5405a732020-04-16 17:02:40 -07001732 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001733
Nan Zhang2760dfc2018-08-24 17:32:54 +00001734 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang2760dfc2018-08-24 17:32:54 +00001735
Colin Cross33961b52019-07-11 11:01:22 -07001736 rule := android.NewRuleBuilder()
1737
Makoto Onuki5405a732020-04-16 17:02:40 -07001738 // Diff command line.
Makoto Onuki88b99052020-04-27 17:22:16 -07001739 // -F matches the closest "opening" line, such as "package android {"
1740 // and " public class Intent {".
Makoto Onuki5405a732020-04-16 17:02:40 -07001741 diff := `diff -u -F '{ *$'`
1742
Colin Cross33961b52019-07-11 11:01:22 -07001743 rule.Command().Text("( true")
Makoto Onuki5405a732020-04-16 17:02:40 -07001744 rule.Command().
1745 Text(diff).
1746 Input(apiFile).Input(d.apiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001747
Makoto Onuki5405a732020-04-16 17:02:40 -07001748 rule.Command().
1749 Text(diff).
1750 Input(removedApiFile).Input(d.removedApiFile)
Colin Cross33961b52019-07-11 11:01:22 -07001751
1752 msg := fmt.Sprintf(`\n******************************\n`+
1753 `You have tried to change the API from what has been previously approved.\n\n`+
1754 `To make these errors go away, you have two choices:\n`+
Makoto Onuki5405a732020-04-16 17:02:40 -07001755 ` 1. You can add '@hide' javadoc comments (and remove @SystemApi/@TestApi/etc)\n`+
1756 ` to the new methods, etc. shown in the above diff.\n\n`+
1757 ` 2. You can update current.txt and/or removed.txt by executing the following command:\n`+
Colin Cross33961b52019-07-11 11:01:22 -07001758 ` make %s-update-current-api\n\n`+
1759 ` To submit the revised current.txt to the main Android repository,\n`+
1760 ` you will need approval.\n`+
1761 `******************************\n`, ctx.ModuleName())
1762
1763 rule.Command().
1764 Text("touch").Output(d.checkCurrentApiTimestamp).
1765 Text(") || (").
1766 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1767 Text("; exit 38").
1768 Text(")")
1769
Makoto Onuki5405a732020-04-16 17:02:40 -07001770 rule.Build(pctx, ctx, "metalavaCurrentApiCheck", "check current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001771
1772 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001773
1774 // update API rule
1775 rule = android.NewRuleBuilder()
1776
1777 rule.Command().Text("( true")
1778
1779 rule.Command().
1780 Text("cp").Flag("-f").
1781 Input(d.apiFile).Flag(apiFile.String())
1782
1783 rule.Command().
1784 Text("cp").Flag("-f").
1785 Input(d.removedApiFile).Flag(removedApiFile.String())
1786
1787 msg = "failed to update public API"
1788
1789 rule.Command().
1790 Text("touch").Output(d.updateCurrentApiTimestamp).
1791 Text(") || (").
1792 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1793 Text("; exit 38").
1794 Text(")")
1795
1796 rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
Nan Zhang61819ce2018-05-04 18:49:16 -07001797 }
Nan Zhanga40da042018-08-01 12:48:00 -07001798
Pete Gillin581d6082018-10-22 15:55:04 +01001799 if String(d.properties.Check_nullability_warnings) != "" {
1800 if d.nullabilityWarningsFile == nil {
1801 ctx.PropertyErrorf("check_nullability_warnings",
1802 "Cannot specify check_nullability_warnings unless validating nullability")
1803 }
Colin Cross33961b52019-07-11 11:01:22 -07001804
1805 checkNullabilityWarnings := android.PathForModuleSrc(ctx, String(d.properties.Check_nullability_warnings))
1806
Pete Gillin581d6082018-10-22 15:55:04 +01001807 d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp")
Colin Cross33961b52019-07-11 11:01:22 -07001808
Pete Gillin581d6082018-10-22 15:55:04 +01001809 msg := fmt.Sprintf(`\n******************************\n`+
1810 `The warnings encountered during nullability annotation validation did\n`+
1811 `not match the checked in file of expected warnings. The diffs are shown\n`+
1812 `above. You have two options:\n`+
1813 ` 1. Resolve the differences by editing the nullability annotations.\n`+
1814 ` 2. Update the file of expected warnings by running:\n`+
1815 ` cp %s %s\n`+
1816 ` and submitting the updated file as part of your change.`,
1817 d.nullabilityWarningsFile, checkNullabilityWarnings)
Colin Cross33961b52019-07-11 11:01:22 -07001818
1819 rule := android.NewRuleBuilder()
1820
1821 rule.Command().
1822 Text("(").
1823 Text("diff").Input(checkNullabilityWarnings).Input(d.nullabilityWarningsFile).
1824 Text("&&").
1825 Text("touch").Output(d.checkNullabilityWarningsTimestamp).
1826 Text(") || (").
1827 Text("echo").Flag("-e").Flag(`"` + msg + `"`).
1828 Text("; exit 38").
1829 Text(")")
1830
1831 rule.Build(pctx, ctx, "nullabilityWarningsCheck", "nullability warnings check")
Pete Gillin581d6082018-10-22 15:55:04 +01001832 }
1833
Nan Zhang71bbe632018-09-17 14:32:21 -07001834 if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() {
Colin Cross33961b52019-07-11 11:01:22 -07001835 if len(d.Javadoc.properties.Out) > 0 {
1836 ctx.PropertyErrorf("out", "out property may not be combined with jdiff")
1837 }
1838
1839 outDir := android.PathForModuleOut(ctx, "jdiff-out")
1840 srcJarDir := android.PathForModuleOut(ctx, "jdiff-srcjars")
1841 stubsDir := android.PathForModuleOut(ctx, "jdiff-stubsDir")
1842
1843 rule := android.NewRuleBuilder()
Nan Zhang71bbe632018-09-17 14:32:21 -07001844
Nan Zhang86b06202018-09-21 17:09:21 -07001845 // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below
1846 // since there's cron job downstream that fetch this .zip file periodically.
1847 // See b/116221385 for reference.
Nan Zhang71bbe632018-09-17 14:32:21 -07001848 d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip")
1849 d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar")
1850
Nan Zhang71bbe632018-09-17 14:32:21 -07001851 jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar")
Nan Zhang71bbe632018-09-17 14:32:21 -07001852
Colin Cross33961b52019-07-11 11:01:22 -07001853 rule.Command().Text("rm -rf").Text(outDir.String()).Text(stubsDir.String())
1854 rule.Command().Text("mkdir -p").Text(outDir.String()).Text(stubsDir.String())
Nan Zhang71bbe632018-09-17 14:32:21 -07001855
Colin Cross33961b52019-07-11 11:01:22 -07001856 srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars)
1857
Colin Crossdaa4c672019-07-15 22:53:46 -07001858 cmd := javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList,
Colin Crossab054432019-07-15 16:13:59 -07001859 deps.bootClasspath, deps.classpath, d.sourcepaths)
1860
1861 cmd.Flag("-J-Xmx1600m").
Colin Cross33961b52019-07-11 11:01:22 -07001862 Flag("-XDignore.symbol.file").
1863 FlagWithArg("-doclet ", "jdiff.JDiff").
1864 FlagWithInput("-docletpath ", jdiff).
Paul Duffin10269f12020-06-19 18:39:55 +01001865 Flag("-quiet")
1866
1867 if d.apiXmlFile != nil {
1868 cmd.FlagWithArg("-newapi ", strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext())).
1869 FlagWithArg("-newapidir ", filepath.Dir(d.apiXmlFile.String())).
1870 Implicit(d.apiXmlFile)
1871 }
1872
1873 if d.lastReleasedApiXmlFile != nil {
1874 cmd.FlagWithArg("-oldapi ", strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext())).
1875 FlagWithArg("-oldapidir ", filepath.Dir(d.lastReleasedApiXmlFile.String())).
1876 Implicit(d.lastReleasedApiXmlFile)
1877 }
Colin Cross33961b52019-07-11 11:01:22 -07001878
Colin Cross33961b52019-07-11 11:01:22 -07001879 rule.Command().
1880 BuiltTool(ctx, "soong_zip").
1881 Flag("-write_if_changed").
1882 Flag("-d").
1883 FlagWithOutput("-o ", d.jdiffDocZip).
1884 FlagWithArg("-C ", outDir.String()).
1885 FlagWithArg("-D ", outDir.String())
1886
1887 rule.Command().
1888 BuiltTool(ctx, "soong_zip").
1889 Flag("-write_if_changed").
1890 Flag("-jar").
1891 FlagWithOutput("-o ", d.jdiffStubsSrcJar).
1892 FlagWithArg("-C ", stubsDir.String()).
1893 FlagWithArg("-D ", stubsDir.String())
1894
1895 rule.Restat()
1896
1897 zipSyncCleanupCmd(rule, srcJarDir)
1898
1899 rule.Build(pctx, ctx, "jdiff", "jdiff")
Nan Zhang71bbe632018-09-17 14:32:21 -07001900 }
Nan Zhang581fd212018-01-10 16:06:12 -08001901}
Dan Willemsencc090972018-02-26 14:33:31 -08001902
Nan Zhanga40da042018-08-01 12:48:00 -07001903//
Nan Zhangf4936b02018-08-01 15:00:28 -07001904// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001905//
Dan Willemsencc090972018-02-26 14:33:31 -08001906var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001907var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Pete Gillin77167902018-09-19 18:16:26 +01001908var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"}
Nan Zhang9c69a122018-08-22 10:22:08 -07001909var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001910
Nan Zhangf4936b02018-08-01 15:00:28 -07001911type ExportedDroiddocDirProperties struct {
1912 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001913 Path *string
1914}
1915
Nan Zhangf4936b02018-08-01 15:00:28 -07001916type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001917 android.ModuleBase
1918
Nan Zhangf4936b02018-08-01 15:00:28 -07001919 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001920
1921 deps android.Paths
1922 dir android.Path
1923}
1924
Colin Crossa3002fc2019-07-08 16:48:04 -07001925// droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava.
Nan Zhangf4936b02018-08-01 15:00:28 -07001926func ExportedDroiddocDirFactory() android.Module {
1927 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001928 module.AddProperties(&module.properties)
1929 android.InitAndroidModule(module)
1930 return module
1931}
1932
Nan Zhangf4936b02018-08-01 15:00:28 -07001933func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001934
Nan Zhangf4936b02018-08-01 15:00:28 -07001935func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Cross07e51612019-03-05 12:46:40 -08001936 path := String(d.properties.Path)
1937 d.dir = android.PathForModuleSrc(ctx, path)
Colin Cross8a497952019-03-05 22:25:09 -08001938 d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")})
Dan Willemsencc090972018-02-26 14:33:31 -08001939}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001940
1941//
1942// Defaults
1943//
1944type DocDefaults struct {
1945 android.ModuleBase
1946 android.DefaultsModuleBase
1947}
1948
Nan Zhangb2b33de2018-02-23 11:18:47 -08001949func DocDefaultsFactory() android.Module {
1950 module := &DocDefaults{}
1951
1952 module.AddProperties(
1953 &JavadocProperties{},
1954 &DroiddocProperties{},
1955 )
1956
1957 android.InitDefaultsModule(module)
1958
1959 return module
1960}
Nan Zhang1598a9e2018-09-04 17:14:32 -07001961
1962func StubsDefaultsFactory() android.Module {
1963 module := &DocDefaults{}
1964
1965 module.AddProperties(
1966 &JavadocProperties{},
1967 &DroidstubsProperties{},
1968 )
1969
1970 android.InitDefaultsModule(module)
1971
1972 return module
1973}
Colin Cross33961b52019-07-11 11:01:22 -07001974
1975func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder,
1976 srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath {
1977
1978 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1979 rule.Command().Text("mkdir -p").Text(srcJarDir.String())
1980 srcJarList := srcJarDir.Join(ctx, "list")
1981
1982 rule.Temporary(srcJarList)
1983
1984 rule.Command().BuiltTool(ctx, "zipsync").
1985 FlagWithArg("-d ", srcJarDir.String()).
1986 FlagWithOutput("-l ", srcJarList).
1987 FlagWithArg("-f ", `"*.java"`).
1988 Inputs(srcJars)
1989
1990 return srcJarList
1991}
1992
1993func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) {
1994 rule.Command().Text("rm -rf").Text(srcJarDir.String())
1995}
Paul Duffin91547182019-11-12 19:39:36 +00001996
1997var _ android.PrebuiltInterface = (*PrebuiltStubsSources)(nil)
1998
1999type PrebuiltStubsSourcesProperties struct {
2000 Srcs []string `android:"path"`
2001}
2002
2003type PrebuiltStubsSources struct {
2004 android.ModuleBase
2005 android.DefaultableModuleBase
2006 prebuilt android.Prebuilt
2007 android.SdkBase
2008
2009 properties PrebuiltStubsSourcesProperties
2010
Paul Duffin9b478b02019-12-10 13:41:51 +00002011 // The source directories containing stubs source files.
2012 srcDirs android.Paths
Paul Duffin91547182019-11-12 19:39:36 +00002013 stubsSrcJar android.ModuleOutPath
2014}
2015
Paul Duffin9b478b02019-12-10 13:41:51 +00002016func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
2017 switch tag {
2018 case "":
2019 return android.Paths{p.stubsSrcJar}, nil
2020 default:
2021 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
2022 }
2023}
2024
Paul Duffin0f8faff2020-05-20 16:18:00 +01002025func (d *PrebuiltStubsSources) StubsSrcJar() android.Path {
2026 return d.stubsSrcJar
2027}
2028
Paul Duffin91547182019-11-12 19:39:36 +00002029func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Paul Duffin9b478b02019-12-10 13:41:51 +00002030 p.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
2031
2032 p.srcDirs = android.PathsForModuleSrc(ctx, p.properties.Srcs)
2033
2034 rule := android.NewRuleBuilder()
2035 command := rule.Command().
2036 BuiltTool(ctx, "soong_zip").
2037 Flag("-write_if_changed").
2038 Flag("-jar").
2039 FlagWithOutput("-o ", p.stubsSrcJar)
2040
2041 for _, d := range p.srcDirs {
2042 dir := d.String()
2043 command.
2044 FlagWithArg("-C ", dir).
2045 FlagWithInput("-D ", d)
2046 }
2047
2048 rule.Restat()
2049
2050 rule.Build(pctx, ctx, "zip src", "Create srcjar from prebuilt source")
Paul Duffin91547182019-11-12 19:39:36 +00002051}
2052
2053func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
2054 return &p.prebuilt
2055}
2056
2057func (p *PrebuiltStubsSources) Name() string {
2058 return p.prebuilt.Name(p.ModuleBase.Name())
2059}
2060
Paul Duffin91547182019-11-12 19:39:36 +00002061// prebuilt_stubs_sources imports a set of java source files as if they were
2062// generated by droidstubs.
2063//
2064// By default, a prebuilt_stubs_sources has a single variant that expects a
2065// set of `.java` files generated by droidstubs.
2066//
2067// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
2068// for host modules.
2069//
2070// Intended only for use by sdk snapshots.
2071func PrebuiltStubsSourcesFactory() android.Module {
2072 module := &PrebuiltStubsSources{}
2073
2074 module.AddProperties(&module.properties)
2075
2076 android.InitPrebuiltModule(module, &module.properties.Srcs)
2077 android.InitSdkAwareModule(module)
2078 InitDroiddocModule(module, android.HostAndDeviceSupported)
2079 return module
2080}
2081
Paul Duffin13879572019-11-28 14:31:38 +00002082type droidStubsSdkMemberType struct {
Paul Duffin255f18e2019-12-13 11:22:16 +00002083 android.SdkMemberTypeBase
Paul Duffin13879572019-11-28 14:31:38 +00002084}
2085
2086func (mt *droidStubsSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
2087 mctx.AddVariationDependencies(nil, dependencyTag, names...)
2088}
2089
2090func (mt *droidStubsSdkMemberType) IsInstance(module android.Module) bool {
2091 _, ok := module.(*Droidstubs)
2092 return ok
2093}
2094
Paul Duffin495ffb92020-03-20 13:35:40 +00002095func (mt *droidStubsSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
2096 return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_stubs_sources")
2097}
2098
2099func (mt *droidStubsSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
2100 return &droidStubsInfoProperties{}
2101}
2102
2103type droidStubsInfoProperties struct {
2104 android.SdkMemberPropertiesBase
2105
2106 StubsSrcJar android.Path
2107}
2108
2109func (p *droidStubsInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
2110 droidstubs := variant.(*Droidstubs)
2111 p.StubsSrcJar = droidstubs.stubsSrcJar
2112}
2113
2114func (p *droidStubsInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
2115 if p.StubsSrcJar != nil {
2116 builder := ctx.SnapshotBuilder()
2117
2118 snapshotRelativeDir := filepath.Join("java", ctx.Name()+"_stubs_sources")
2119
2120 builder.UnzipToSnapshot(p.StubsSrcJar, snapshotRelativeDir)
2121
2122 propertySet.AddProperty("srcs", []string{snapshotRelativeDir})
Paul Duffin13879572019-11-28 14:31:38 +00002123 }
Paul Duffin91547182019-11-12 19:39:36 +00002124}