blob: 68d78610b62d067170a24b06ef0eccc82966432a [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 (
18 "android/soong/android"
19 "android/soong/java/config"
20 "fmt"
Nan Zhangb2b33de2018-02-23 11:18:47 -080021 "path/filepath"
Nan Zhang46130972018-06-04 11:28:01 -070022 "runtime"
Nan Zhang581fd212018-01-10 16:06:12 -080023 "strings"
24
25 "github.com/google/blueprint"
26)
27
28var (
29 javadoc = pctx.AndroidStaticRule("javadoc",
30 blueprint.RuleParams{
31 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
Colin Cross436b7652018-03-15 16:24:10 -070032 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhangaf322cc2018-06-19 15:15:38 -070033 `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
Nan Zhang581fd212018-01-10 16:06:12 -080034 `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
35 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
Nan Zhange2ba5d42018-07-11 15:16:55 -070037 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`,
Nan Zhang581fd212018-01-10 16:06:12 -080038 CommandDeps: []string{
Colin Cross436b7652018-03-15 16:24:10 -070039 "${config.ZipSyncCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080040 "${config.JavadocCmd}",
41 "${config.SoongZipCmd}",
Nan Zhang581fd212018-01-10 16:06:12 -080042 },
43 Rspfile: "$out.rsp",
44 RspfileContent: "$in",
45 Restat: true,
46 },
Nan Zhangaf322cc2018-06-19 15:15:38 -070047 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhange2ba5d42018-07-11 15:16:55 -070048 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "postDoclavaCmds")
Nan Zhang61819ce2018-05-04 18:49:16 -070049
50 apiCheck = pctx.AndroidStaticRule("apiCheck",
51 blueprint.RuleParams{
52 Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` +
53 `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` +
Jiyong Parkeeb8a642018-05-12 22:21:20 +090054 `&& touch $out ) || (echo -e "$msg" ; exit 38)`,
Nan Zhang61819ce2018-05-04 18:49:16 -070055 CommandDeps: []string{
56 "${config.ApiCheckCmd}",
57 },
58 },
59 "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg")
60
61 updateApi = pctx.AndroidStaticRule("updateApi",
62 blueprint.RuleParams{
63 Command: `( ( cp -f $apiFileToCheck $apiFile && cp -f $removedApiFileToCheck $removedApiFile ) ` +
64 `&& touch $out ) || (echo failed to update public API ; exit 38)`,
65 },
66 "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck")
Nan Zhang79614d12018-04-19 18:03:39 -070067
68 metalava = pctx.AndroidStaticRule("metalava",
69 blueprint.RuleParams{
Nan Zhangde860a42018-08-08 16:32:21 -070070 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
71 `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" "$docStubsDir" && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070072 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
Nan Zhang357466b2018-04-17 17:38:36 -070073 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
Nan Zhang16c0a312018-06-13 17:42:48 -070074 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
75 `--stubs $stubsDir $opts && ` +
Nan Zhang79614d12018-04-19 18:03:39 -070076 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
77 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
78 CommandDeps: []string{
79 "${config.ZipSyncCmd}",
80 "${config.JavaCmd}",
81 "${config.MetalavaJar}",
82 "${config.JavadocCmd}",
83 "${config.SoongZipCmd}",
84 },
85 Rspfile: "$out.rsp",
86 RspfileContent: "$in",
87 Restat: true,
88 },
Nan Zhangde860a42018-08-08 16:32:21 -070089 "outDir", "srcJarDir", "stubsDir", "docStubsDir", "srcJars", "javaVersion", "bootclasspathArgs",
Nan Zhang357466b2018-04-17 17:38:36 -070090 "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang2760dfc2018-08-24 17:32:54 +000091
92 metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck",
93 blueprint.RuleParams{
94 Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` +
95 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
96 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` +
97 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color --quiet ` +
98 `$opts && touch $out ) || ` +
99 `( echo -e "$msg" ; exit 38 )`,
100 CommandDeps: []string{
101 "${config.ZipSyncCmd}",
102 "${config.JavaCmd}",
103 "${config.MetalavaJar}",
104 },
105 Rspfile: "$out.rsp",
106 RspfileContent: "$in",
107 },
108 "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "msg")
Nan Zhang581fd212018-01-10 16:06:12 -0800109)
110
111func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -0800112 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
113
Nan Zhang581fd212018-01-10 16:06:12 -0800114 android.RegisterModuleType("droiddoc", DroiddocFactory)
115 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Nan Zhangf4936b02018-08-01 15:00:28 -0700116 android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory)
Nan Zhang581fd212018-01-10 16:06:12 -0800117 android.RegisterModuleType("javadoc", JavadocFactory)
118 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
119}
120
Colin Crossa1ce2a02018-06-20 15:19:39 -0700121var (
122 srcsLibTag = dependencyTag{name: "sources from javalib"}
123)
124
Nan Zhang581fd212018-01-10 16:06:12 -0800125type JavadocProperties struct {
126 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
127 // or .aidl files.
128 Srcs []string `android:"arch_variant"`
129
130 // list of directories rooted at the Android.bp file that will
131 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // list of source files that should not be used to build the Java module.
135 // This is most useful in the arch/multilib variants to remove non-common files
136 // filegroup or genrule can be included within this property.
137 Exclude_srcs []string `android:"arch_variant"`
138
Nan Zhangb2b33de2018-02-23 11:18:47 -0800139 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800140 Libs []string `android:"arch_variant"`
141
Nan Zhange66c7272018-03-06 12:59:27 -0800142 // don't build against the framework libraries (legacy-test, core-junit,
143 // ext, and framework for device targets)
144 No_framework_libs *bool
145
Nan Zhangb2b33de2018-02-23 11:18:47 -0800146 // the java library (in classpath) for documentation that provides java srcs and srcjars.
147 Srcs_lib *string
148
149 // the base dirs under srcs_lib will be scanned for java srcs.
150 Srcs_lib_whitelist_dirs []string
151
152 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
153 Srcs_lib_whitelist_pkgs []string
154
Nan Zhang581fd212018-01-10 16:06:12 -0800155 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800156 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800157
158 // if not blank, set to the version of the sdk to compile against
159 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900160
161 Aidl struct {
162 // Top level directories to pass to aidl tool
163 Include_dirs []string
164
165 // Directories rooted at the Android.bp file to pass to aidl tool
166 Local_include_dirs []string
167 }
Nan Zhang357466b2018-04-17 17:38:36 -0700168
169 // If not blank, set the java version passed to javadoc as -source
170 Java_version *string
Nan Zhang581fd212018-01-10 16:06:12 -0800171}
172
Nan Zhang61819ce2018-05-04 18:49:16 -0700173type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900174 // path to the API txt file that the new API extracted from source code is checked
175 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700176 Api_file *string
177
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900178 // path to the API txt file that the new @removed API extractd from source code is
179 // checked against. The path can be local to the module or from other module (via
180 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700181 Removed_api_file *string
182
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900183 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700184 Args *string
185}
186
Nan Zhang581fd212018-01-10 16:06:12 -0800187type DroiddocProperties struct {
188 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800189 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800190
Nan Zhanga40da042018-08-01 12:48:00 -0700191 // directories under current module source which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800192 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800193
194 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800195 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800196
197 // proofread file contains all of the text content of the javadocs concatenated into one file,
198 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800199 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800200
201 // a todo file lists the program elements that are missing documentation.
202 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800203 Todo_file *string
204
205 // directory under current module source that provide additional resources (images).
206 Resourcesdir *string
207
208 // resources output directory under out/soong/.intermediates.
209 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800210
211 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800212 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800213
214 // user customized droiddoc args.
215 // Available variables for substitution:
216 //
217 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800218 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800219
220 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800221 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800222
Nan Zhange2ba5d42018-07-11 15:16:55 -0700223 // if set to true, collect the values used by the Dev tools and
224 // write them in files packaged with the SDK. Defaults to false.
225 Write_sdk_values *bool
226
227 // index.html under current module will be copied to docs out dir, if not null.
228 Static_doc_index_redirect *string
229
230 // source.properties under current module will be copied to docs out dir, if not null.
231 Static_doc_properties *string
232
Nan Zhang581fd212018-01-10 16:06:12 -0800233 // a list of files under current module source dir which contains known tags in Java sources.
234 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800235 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700236
237 // the tag name used to distinguish if the API files belong to public/system/test.
238 Api_tag_name *string
239
240 // the generated public API filename by Doclava.
241 Api_filename *string
242
David Brazdilfbe4cc32018-05-31 13:56:46 +0100243 // the generated public Dex API filename by Doclava.
244 Dex_api_filename *string
245
Nan Zhang28c68b92018-03-13 16:17:01 -0700246 // the generated private API filename by Doclava.
247 Private_api_filename *string
248
249 // the generated private Dex API filename by Doclava.
250 Private_dex_api_filename *string
251
252 // the generated removed API filename by Doclava.
253 Removed_api_filename *string
254
David Brazdilaac0c3c2018-04-24 16:23:29 +0100255 // the generated removed Dex API filename by Doclava.
256 Removed_dex_api_filename *string
257
Mathew Inwood76c3de12018-06-22 15:28:11 +0100258 // mapping of dex signatures to source file and line number. This is a temporary property and
259 // will be deleted; you probably shouldn't be using it.
260 Dex_mapping_filename *string
261
Nan Zhang28c68b92018-03-13 16:17:01 -0700262 // the generated exact API filename by Doclava.
263 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700264
Nan Zhang66dc2362018-08-14 20:41:04 -0700265 // the generated proguard filename by Doclava.
266 Proguard_filename *string
267
Nan Zhang853f4202018-04-12 16:55:56 -0700268 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
269 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700270
271 Check_api struct {
272 Last_released ApiToCheck
273
274 Current ApiToCheck
275 }
Nan Zhang79614d12018-04-19 18:03:39 -0700276
277 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
278 // currently still used for documentation generation, and will be replaced by Dokka soon.
279 Metalava_enabled *bool
280
281 // user can specify the version of previous released API file in order to do compatibility check.
282 Metalava_previous_api *string
283
284 // is set to true, Metalava will allow framework SDK to contain annotations.
285 Metalava_annotations_enabled *bool
286
Pete Gillinb13a0152018-07-19 17:56:49 +0100287 // a list of top-level directories containing files to merge annotations from.
288 Metalava_merge_annotations_dirs []string
Nan Zhang86d2d552018-08-09 15:33:27 -0700289
290 // if set to true, generate docs through Dokka instead of Doclava. Valid only when
291 // metalava_enabled is set to true.
292 Dokka_enabled *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800293}
294
Nan Zhanga40da042018-08-01 12:48:00 -0700295//
296// Common flags passed down to build rule
297//
298type droiddocBuilderFlags struct {
Nan Zhang86d2d552018-08-09 15:33:27 -0700299 args string
300 bootClasspathArgs string
301 classpathArgs string
302 dokkaClasspathArgs string
303 aidlFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700304
Nan Zhanga40da042018-08-01 12:48:00 -0700305 doclavaStubsFlags string
Nan Zhang86d2d552018-08-09 15:33:27 -0700306 doclavaDocsFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700307 postDoclavaCmds string
308
Nan Zhang2760dfc2018-08-24 17:32:54 +0000309 metalavaStubsFlags string
310 metalavaAnnotationsFlags string
311 metalavaJavadocFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700312
Nan Zhang86d2d552018-08-09 15:33:27 -0700313 metalavaDokkaFlags string
Nan Zhanga40da042018-08-01 12:48:00 -0700314}
315
316func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
317 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
318 android.InitDefaultableModule(module)
319}
320
321//
322// Javadoc
323//
Nan Zhang581fd212018-01-10 16:06:12 -0800324type Javadoc struct {
325 android.ModuleBase
326 android.DefaultableModuleBase
327
328 properties JavadocProperties
329
330 srcJars android.Paths
331 srcFiles android.Paths
332 sourcepaths android.Paths
333
Nan Zhangccff0f72018-03-08 17:26:16 -0800334 docZip android.WritablePath
335 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800336}
337
Nan Zhangb2b33de2018-02-23 11:18:47 -0800338func (j *Javadoc) Srcs() android.Paths {
339 return android.Paths{j.stubsSrcJar}
340}
341
Nan Zhang581fd212018-01-10 16:06:12 -0800342func JavadocFactory() android.Module {
343 module := &Javadoc{}
344
345 module.AddProperties(&module.properties)
346
347 InitDroiddocModule(module, android.HostAndDeviceSupported)
348 return module
349}
350
351func JavadocHostFactory() android.Module {
352 module := &Javadoc{}
353
354 module.AddProperties(&module.properties)
355
356 InitDroiddocModule(module, android.HostSupported)
357 return module
358}
359
Nan Zhanga40da042018-08-01 12:48:00 -0700360var _ android.SourceFileProducer = (*Javadoc)(nil)
Nan Zhang581fd212018-01-10 16:06:12 -0800361
Colin Cross83bb3162018-06-25 15:48:06 -0700362func (j *Javadoc) sdkVersion() string {
363 return String(j.properties.Sdk_version)
364}
365
366func (j *Javadoc) minSdkVersion() string {
367 return j.sdkVersion()
368}
369
Nan Zhang581fd212018-01-10 16:06:12 -0800370func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
371 if ctx.Device() {
Colin Cross83bb3162018-06-25 15:48:06 -0700372 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800373 if sdkDep.useDefaultLibs {
Colin Cross42d48b72018-08-29 14:10:52 -0700374 ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang357466b2018-04-17 17:38:36 -0700375 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700376 ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700377 }
Nan Zhang9cbe6772018-03-21 17:56:39 -0700378 if !Bool(j.properties.No_framework_libs) {
Colin Cross42d48b72018-08-29 14:10:52 -0700379 ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
Nan Zhange66c7272018-03-06 12:59:27 -0800380 }
Nan Zhang581fd212018-01-10 16:06:12 -0800381 } else if sdkDep.useModule {
Nan Zhang357466b2018-04-17 17:38:36 -0700382 if ctx.Config().TargetOpenJDK9() {
Colin Cross42d48b72018-08-29 14:10:52 -0700383 ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
Nan Zhang357466b2018-04-17 17:38:36 -0700384 }
Colin Cross42d48b72018-08-29 14:10:52 -0700385 ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800386 }
387 }
388
Colin Cross42d48b72018-08-29 14:10:52 -0700389 ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700390 if j.properties.Srcs_lib != nil {
Colin Cross42d48b72018-08-29 14:10:52 -0700391 ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
Colin Crossa1ce2a02018-06-20 15:19:39 -0700392 }
Nan Zhang581fd212018-01-10 16:06:12 -0800393
394 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
395
396 // exclude_srcs may contain filegroup or genrule.
397 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
398}
399
Nan Zhangb2b33de2018-02-23 11:18:47 -0800400func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
401 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
402 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900403 // convert foo.bar.baz to foo/bar/baz
404 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
405 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800406 if _, found := whitelistPathPrefixes[prefix]; !found {
407 whitelistPathPrefixes[prefix] = true
408 }
409 }
410 }
411}
412
Nan Zhanga40da042018-08-01 12:48:00 -0700413func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
414 var flags droiddocBuilderFlags
Jiyong Park1e440682018-05-23 18:42:04 +0900415
416 // aidl flags.
417 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
418 if len(aidlFlags) > 0 {
419 // optimization.
420 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
421 flags.aidlFlags = "$aidlFlags"
422 }
423
424 return flags
425}
426
427func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
428 aidlIncludeDirs android.Paths) []string {
429
430 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
431 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
432
433 var flags []string
434 if aidlPreprocess.Valid() {
435 flags = append(flags, "-p"+aidlPreprocess.String())
436 } else {
437 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
438 }
439
440 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
441 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
442 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
443 flags = append(flags, "-I"+src.String())
444 }
445
446 return flags
447}
448
449func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
Nan Zhanga40da042018-08-01 12:48:00 -0700450 flags droiddocBuilderFlags) android.Paths {
Jiyong Park1e440682018-05-23 18:42:04 +0900451
452 outSrcFiles := make(android.Paths, 0, len(srcFiles))
453
454 for _, srcFile := range srcFiles {
455 switch srcFile.Ext() {
456 case ".aidl":
457 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
458 outSrcFiles = append(outSrcFiles, javaFile)
459 default:
460 outSrcFiles = append(outSrcFiles, srcFile)
461 }
462 }
463
464 return outSrcFiles
465}
466
Nan Zhang581fd212018-01-10 16:06:12 -0800467func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
468 var deps deps
469
Colin Cross83bb3162018-06-25 15:48:06 -0700470 sdkDep := decodeSdkDep(ctx, sdkContext(j))
Nan Zhang581fd212018-01-10 16:06:12 -0800471 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700472 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800473 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700474 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800475 }
476
477 ctx.VisitDirectDeps(func(module android.Module) {
478 otherName := ctx.OtherModuleName(module)
479 tag := ctx.OtherModuleDependencyTag(module)
480
Colin Cross2d24c1b2018-05-23 10:59:18 -0700481 switch tag {
482 case bootClasspathTag:
483 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800484 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700485 } else {
486 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
487 }
488 case libTag:
489 switch dep := module.(type) {
490 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800491 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700492 case SdkLibraryDependency:
Colin Cross83bb3162018-06-25 15:48:06 -0700493 sdkVersion := j.sdkVersion()
Jiyong Parkc678ad32018-04-10 13:07:10 +0900494 linkType := javaSdk
495 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
496 linkType = javaSystem
497 } else if sdkVersion == "" {
498 linkType = javaPlatform
499 }
Sundong Ahn241cd372018-07-13 16:16:44 +0900500 deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700501 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800502 checkProducesJars(ctx, dep)
503 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800504 default:
505 ctx.ModuleErrorf("depends on non-java module %q", otherName)
506 }
Colin Crossa1ce2a02018-06-20 15:19:39 -0700507 case srcsLibTag:
508 switch dep := module.(type) {
509 case Dependency:
510 srcs := dep.(SrcDependency).CompiledSrcs()
511 whitelistPathPrefixes := make(map[string]bool)
512 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
513 for _, src := range srcs {
514 if _, ok := src.(android.WritablePath); ok { // generated sources
515 deps.srcs = append(deps.srcs, src)
516 } else { // select source path for documentation based on whitelist path prefixs.
517 for k, _ := range whitelistPathPrefixes {
518 if strings.HasPrefix(src.Rel(), k) {
519 deps.srcs = append(deps.srcs, src)
520 break
521 }
522 }
523 }
524 }
525 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
526 default:
527 ctx.ModuleErrorf("depends on non-java module %q", otherName)
528 }
Nan Zhang357466b2018-04-17 17:38:36 -0700529 case systemModulesTag:
530 if deps.systemModules != nil {
531 panic("Found two system module dependencies")
532 }
533 sm := module.(*SystemModules)
534 if sm.outputFile == nil {
535 panic("Missing directory for system module dependency")
536 }
537 deps.systemModules = sm.outputFile
Nan Zhang581fd212018-01-10 16:06:12 -0800538 }
539 })
540 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
541 // may contain filegroup or genrule.
542 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Nan Zhanga40da042018-08-01 12:48:00 -0700543 flags := j.collectAidlFlags(ctx, deps)
Jiyong Park1e440682018-05-23 18:42:04 +0900544 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800545
546 // srcs may depend on some genrule output.
547 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800548 j.srcJars = append(j.srcJars, deps.srcJars...)
549
Nan Zhang581fd212018-01-10 16:06:12 -0800550 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800551 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800552
553 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800554 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800555
556 if j.properties.Local_sourcepaths == nil {
557 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
558 }
559 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800560
561 return deps
562}
563
564func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
565 j.addDeps(ctx)
566}
567
568func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
569 deps := j.collectDeps(ctx)
570
571 var implicits android.Paths
572 implicits = append(implicits, deps.bootClasspath...)
573 implicits = append(implicits, deps.classpath...)
574
575 var bootClasspathArgs, classpathArgs string
Nan Zhang357466b2018-04-17 17:38:36 -0700576
Colin Cross83bb3162018-06-25 15:48:06 -0700577 javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
Colin Cross997262f2018-06-19 22:49:39 -0700578 if len(deps.bootClasspath) > 0 {
579 var systemModules classpath
580 if deps.systemModules != nil {
581 systemModules = append(systemModules, deps.systemModules)
Nan Zhang581fd212018-01-10 16:06:12 -0800582 }
Colin Cross997262f2018-06-19 22:49:39 -0700583 bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device())
584 bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=."
Nan Zhang581fd212018-01-10 16:06:12 -0800585 }
586 if len(deps.classpath.Strings()) > 0 {
587 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
588 }
589
590 implicits = append(implicits, j.srcJars...)
591
Nan Zhangaf322cc2018-06-19 15:15:38 -0700592 opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
Nan Zhang581fd212018-01-10 16:06:12 -0800593
594 ctx.Build(pctx, android.BuildParams{
595 Rule: javadoc,
596 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800597 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800598 ImplicitOutput: j.docZip,
599 Inputs: j.srcFiles,
600 Implicits: implicits,
601 Args: map[string]string{
Nan Zhangde860a42018-08-08 16:32:21 -0700602 "outDir": android.PathForModuleOut(ctx, "out").String(),
603 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
604 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
Nan Zhang581fd212018-01-10 16:06:12 -0800605 "srcJars": strings.Join(j.srcJars.Strings(), " "),
606 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700607 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800608 "classpathArgs": classpathArgs,
609 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
610 "docZip": j.docZip.String(),
611 },
612 })
613}
614
Nan Zhanga40da042018-08-01 12:48:00 -0700615//
616// Droiddoc
617//
618type Droiddoc struct {
619 Javadoc
620
621 properties DroiddocProperties
622 apiFile android.WritablePath
623 dexApiFile android.WritablePath
624 privateApiFile android.WritablePath
625 privateDexApiFile android.WritablePath
626 removedApiFile android.WritablePath
627 removedDexApiFile android.WritablePath
628 exactApiFile android.WritablePath
629 apiMappingFile android.WritablePath
Nan Zhang66dc2362018-08-14 20:41:04 -0700630 proguardFile android.WritablePath
Nan Zhanga40da042018-08-01 12:48:00 -0700631
632 checkCurrentApiTimestamp android.WritablePath
633 updateCurrentApiTimestamp android.WritablePath
634 checkLastReleasedApiTimestamp android.WritablePath
635
636 annotationsZip android.WritablePath
637
638 apiFilePath android.Path
639}
640
641type ApiFilePath interface {
642 ApiFilePath() android.Path
643}
644
645func DroiddocFactory() android.Module {
646 module := &Droiddoc{}
647
648 module.AddProperties(&module.properties,
649 &module.Javadoc.properties)
650
651 InitDroiddocModule(module, android.HostAndDeviceSupported)
652 return module
653}
654
655func DroiddocHostFactory() android.Module {
656 module := &Droiddoc{}
657
658 module.AddProperties(&module.properties,
659 &module.Javadoc.properties)
660
661 InitDroiddocModule(module, android.HostSupported)
662 return module
663}
664
665func (d *Droiddoc) ApiFilePath() android.Path {
666 return d.apiFilePath
667}
668
Nan Zhang61819ce2018-05-04 18:49:16 -0700669func (d *Droiddoc) checkCurrentApi() bool {
670 if String(d.properties.Check_api.Current.Api_file) != "" &&
671 String(d.properties.Check_api.Current.Removed_api_file) != "" {
672 return true
673 } else if String(d.properties.Check_api.Current.Api_file) != "" {
674 panic("check_api.current.removed_api_file: has to be non empty!")
675 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
676 panic("check_api.current.api_file: has to be non empty!")
677 }
678
679 return false
680}
681
682func (d *Droiddoc) checkLastReleasedApi() bool {
683 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
684 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
685 return true
686 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
687 panic("check_api.last_released.removed_api_file: has to be non empty!")
688 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
689 panic("check_api.last_released.api_file: has to be non empty!")
690 }
691
692 return false
693}
694
Nan Zhang581fd212018-01-10 16:06:12 -0800695func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
696 d.Javadoc.addDeps(ctx)
697
Nan Zhang79614d12018-04-19 18:03:39 -0700698 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800699 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
700 }
701
Nan Zhanga40da042018-08-01 12:48:00 -0700702 // arg_files may contains filegroup or genrule.
Nan Zhang581fd212018-01-10 16:06:12 -0800703 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
704
705 // knowntags may contain filegroup or genrule.
706 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700707
Nan Zhange2ba5d42018-07-11 15:16:55 -0700708 if String(d.properties.Static_doc_index_redirect) != "" {
709 android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect)
710 }
711
712 if String(d.properties.Static_doc_properties) != "" {
713 android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties)
714 }
715
Nan Zhang61819ce2018-05-04 18:49:16 -0700716 if d.checkCurrentApi() {
717 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
718 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
719 }
720
721 if d.checkLastReleasedApi() {
722 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
723 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
724 }
Nan Zhang79614d12018-04-19 18:03:39 -0700725
726 if String(d.properties.Metalava_previous_api) != "" {
727 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
728 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700729
730 if len(d.properties.Metalava_merge_annotations_dirs) != 0 {
731 for _, mergeAnnotationsDir := range d.properties.Metalava_merge_annotations_dirs {
732 ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir)
733 }
734 }
Nan Zhang581fd212018-01-10 16:06:12 -0800735}
736
Nan Zhang66dc2362018-08-14 20:41:04 -0700737func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths,
738 deps deps) (droiddocBuilderFlags, error) {
Nan Zhanga40da042018-08-01 12:48:00 -0700739 var flags droiddocBuilderFlags
Nan Zhang581fd212018-01-10 16:06:12 -0800740
Nan Zhanga40da042018-08-01 12:48:00 -0700741 *implicits = append(*implicits, deps.bootClasspath...)
742 *implicits = append(*implicits, deps.classpath...)
Nan Zhang581fd212018-01-10 16:06:12 -0800743
Nan Zhangc94f9d82018-06-26 10:02:26 -0700744 // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled
745 // since it doesn't support system modules yet.
746 if len(deps.bootClasspath.Strings()) > 0 {
747 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
Nan Zhanga40da042018-08-01 12:48:00 -0700748 flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
Nan Zhang357466b2018-04-17 17:38:36 -0700749 }
Nan Zhanga40da042018-08-01 12:48:00 -0700750 flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath")
Nan Zhang86d2d552018-08-09 15:33:27 -0700751 // Dokka doesn't support boocClasspath, so combine these two classpath vars for Dokka.
752 dokkaClasspath := classpath{}
753 dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...)
754 dokkaClasspath = append(dokkaClasspath, deps.classpath...)
755 flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath")
Nan Zhang79614d12018-04-19 18:03:39 -0700756
Nan Zhang581fd212018-01-10 16:06:12 -0800757 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
758 argFilesMap := map[string]android.Path{}
759
760 for _, f := range argFiles {
Nan Zhanga40da042018-08-01 12:48:00 -0700761 *implicits = append(*implicits, f)
Nan Zhang581fd212018-01-10 16:06:12 -0800762 if _, exists := argFilesMap[f.Rel()]; !exists {
763 argFilesMap[f.Rel()] = f
764 } else {
765 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
766 f, argFilesMap[f.Rel()], f.Rel())
767 }
768 }
769
Nan Zhanga40da042018-08-01 12:48:00 -0700770 var err error
771 flags.args, err = android.Expand(String(d.properties.Args), func(name string) (string, error) {
Nan Zhang581fd212018-01-10 16:06:12 -0800772 if strings.HasPrefix(name, "location ") {
773 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
774 if f, ok := argFilesMap[label]; ok {
775 return f.String(), nil
776 } else {
777 return "", fmt.Errorf("unknown location label %q", label)
778 }
779 } else if name == "genDir" {
780 return android.PathForModuleGen(ctx).String(), nil
781 }
782 return "", fmt.Errorf("unknown variable '$(%s)'", name)
783 })
784
785 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700786 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhanga40da042018-08-01 12:48:00 -0700787 return droiddocBuilderFlags{}, err
Nan Zhang581fd212018-01-10 16:06:12 -0800788 }
Nan Zhanga40da042018-08-01 12:48:00 -0700789 return flags, nil
790}
Nan Zhang581fd212018-01-10 16:06:12 -0800791
Nan Zhanga40da042018-08-01 12:48:00 -0700792func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths,
Nan Zhang443fa522018-08-20 20:58:28 -0700793 jsilver, doclava android.Path) string {
Nan Zhang581fd212018-01-10 16:06:12 -0800794
Nan Zhanga40da042018-08-01 12:48:00 -0700795 *implicits = append(*implicits, jsilver)
796 *implicits = append(*implicits, doclava)
Nan Zhang30963742018-04-23 09:59:14 -0700797
Nan Zhang46130972018-06-04 11:28:01 -0700798 var date string
799 if runtime.GOOS == "darwin" {
800 date = `date -r`
801 } else {
802 date = `date -d`
803 }
804
Nan Zhang443fa522018-08-20 20:58:28 -0700805 // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9
806 // sources, droiddoc will get sources produced by metalava which will have already stripped out the
807 // 1.9 language features.
808 args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700809 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800810 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700811 `-hdf page.now "$$(` + date + ` @$$(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 {
Nan Zhanga40da042018-08-01 12:48:00 -0700820 *implicits = append(*implicits, t.deps...)
821 args = args + " -templatedir " + t.dir.String()
822 } else {
823 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
824 }
825 })
826
827 if len(d.properties.Html_dirs) > 0 {
828 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
829 *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
830 args = args + " -htmldir " + htmlDir.String()
831 }
832
833 if len(d.properties.Html_dirs) > 1 {
834 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
835 *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
836 args = args + " -htmldir2 " + htmlDir2.String()
837 }
838
839 if len(d.properties.Html_dirs) > 2 {
840 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
841 }
842
843 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
844 *implicits = append(*implicits, knownTags...)
845
846 for _, kt := range knownTags {
847 args = args + " -knowntags " + kt.String()
848 }
849
850 for _, hdf := range d.properties.Hdf {
851 args = args + " -hdf " + hdf
852 }
853
854 if String(d.properties.Proofread_file) != "" {
855 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
856 args = args + " -proofread " + proofreadFile.String()
857 }
858
859 if String(d.properties.Todo_file) != "" {
860 // tricky part:
861 // we should not compute full path for todo_file through PathForModuleOut().
862 // the non-standard doclet will get the full path relative to "-o".
863 args = args + " -todo " + String(d.properties.Todo_file)
864 }
865
866 if String(d.properties.Resourcesdir) != "" {
867 // TODO: should we add files under resourcesDir to the implicits? It seems that
868 // resourcesDir is one sub dir of htmlDir
869 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
870 args = args + " -resourcesdir " + resourcesDir.String()
871 }
872
873 if String(d.properties.Resourcesoutdir) != "" {
874 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
875 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
876 }
877 return args
878}
879
880func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, implicitOutputs *android.WritablePaths) (string, string) {
881 var doclavaFlags, MetalavaFlags string
882 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
883 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
884 doclavaFlags += " -api " + d.apiFile.String()
885 MetalavaFlags = MetalavaFlags + " --api " + d.apiFile.String()
886 *implicitOutputs = append(*implicitOutputs, d.apiFile)
887 d.apiFilePath = d.apiFile
888 }
889
890 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
891 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
892 doclavaFlags += " -removedApi " + d.removedApiFile.String()
893 MetalavaFlags = MetalavaFlags + " --removed-api " + d.removedApiFile.String()
894 *implicitOutputs = append(*implicitOutputs, d.removedApiFile)
895 }
896
897 if String(d.properties.Private_api_filename) != "" {
898 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
899 doclavaFlags += " -privateApi " + d.privateApiFile.String()
900 MetalavaFlags = MetalavaFlags + " --private-api " + d.privateApiFile.String()
901 *implicitOutputs = append(*implicitOutputs, d.privateApiFile)
902 }
903
904 if String(d.properties.Dex_api_filename) != "" {
905 d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename))
906 doclavaFlags += " -dexApi " + d.dexApiFile.String()
Nan Zhangaa43b942018-08-21 16:24:38 -0700907 MetalavaFlags += " --dex-api " + d.dexApiFile.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700908 *implicitOutputs = append(*implicitOutputs, d.dexApiFile)
909 }
910
911 if String(d.properties.Private_dex_api_filename) != "" {
912 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
913 doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String()
914 MetalavaFlags = MetalavaFlags + " --private-dex-api " + d.privateDexApiFile.String()
915 *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile)
916 }
917
918 if String(d.properties.Removed_dex_api_filename) != "" {
919 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
920 doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String()
921 MetalavaFlags = MetalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String()
922 *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile)
923 }
924
925 if String(d.properties.Exact_api_filename) != "" {
926 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
927 doclavaFlags += " -exactApi " + d.exactApiFile.String()
928 MetalavaFlags = MetalavaFlags + " --exact-api " + d.exactApiFile.String()
929 *implicitOutputs = append(*implicitOutputs, d.exactApiFile)
930 }
931
932 if String(d.properties.Dex_mapping_filename) != "" {
933 d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
934 doclavaFlags += " -apiMapping " + d.apiMappingFile.String()
935 // Omitted: metalava support
936 *implicitOutputs = append(*implicitOutputs, d.apiMappingFile)
937 }
938
Nan Zhang66dc2362018-08-14 20:41:04 -0700939 if String(d.properties.Proguard_filename) != "" {
940 d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename))
941 doclavaFlags += " -proguard " + d.proguardFile.String()
942 // Omitted: metalava support
943 *implicitOutputs = append(*implicitOutputs, d.proguardFile)
944 }
945
Nan Zhanga40da042018-08-01 12:48:00 -0700946 if BoolDefault(d.properties.Create_stubs, true) {
Nan Zhangde860a42018-08-08 16:32:21 -0700947 doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700948 }
949
950 if Bool(d.properties.Write_sdk_values) {
Nan Zhangde860a42018-08-08 16:32:21 -0700951 doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700952 }
953 return doclavaFlags, MetalavaFlags
954}
955
956func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string {
957 var cmds string
958 if String(d.properties.Static_doc_index_redirect) != "" {
959 static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect),
960 "static_doc_index_redirect")
961 *implicits = append(*implicits, static_doc_index_redirect)
962 cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700963 android.PathForModuleOut(ctx, "out", "index.html").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700964 }
965
966 if String(d.properties.Static_doc_properties) != "" {
967 static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties),
968 "static_doc_properties")
969 *implicits = append(*implicits, static_doc_properties)
970 cmds = cmds + " && cp " + static_doc_properties.String() + " " +
Nan Zhangde860a42018-08-08 16:32:21 -0700971 android.PathForModuleOut(ctx, "out", "source.properties").String()
Nan Zhanga40da042018-08-01 12:48:00 -0700972 }
973 return cmds
974}
975
976func (d *Droiddoc) collectMetalavaAnnotationsFlags(
977 ctx android.ModuleContext, implicits *android.Paths, implicitOutputs *android.WritablePaths) string {
978 var flags string
Nan Zhanga40da042018-08-01 12:48:00 -0700979 if Bool(d.properties.Metalava_annotations_enabled) {
980 if String(d.properties.Metalava_previous_api) == "" {
981 ctx.PropertyErrorf("metalava_previous_api",
982 "has to be non-empty if annotations was enabled!")
983 }
Nan Zhangde860a42018-08-08 16:32:21 -0700984 previousApi := ctx.ExpandSource(String(d.properties.Metalava_previous_api),
985 "metalava_previous_api")
986 *implicits = append(*implicits, previousApi)
Nan Zhangde860a42018-08-08 16:32:21 -0700987
Nan Zhangd05a4362018-08-15 13:28:54 -0700988 flags += " --include-annotations --migrate-nullness " + previousApi.String()
Nan Zhanga40da042018-08-01 12:48:00 -0700989
990 d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
991 *implicitOutputs = append(*implicitOutputs, d.annotationsZip)
992
Nan Zhangf4936b02018-08-01 15:00:28 -0700993 flags += " --extract-annotations " + d.annotationsZip.String()
994
Nan Zhanga40da042018-08-01 12:48:00 -0700995 if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
996 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
997 "has to be non-empty if annotations was enabled!")
998 }
Nan Zhangf4936b02018-08-01 15:00:28 -0700999 ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) {
1000 if t, ok := m.(*ExportedDroiddocDir); ok {
1001 *implicits = append(*implicits, t.deps...)
1002 flags += " --merge-annotations " + t.dir.String()
1003 } else {
1004 ctx.PropertyErrorf("metalava_merge_annotations_dirs",
1005 "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m))
1006 }
1007 })
Nan Zhanga40da042018-08-01 12:48:00 -07001008 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
1009 flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction "
1010 }
1011
1012 return flags
1013}
1014
Nan Zhang86d2d552018-08-09 15:33:27 -07001015func (d *Droiddoc) collectMetalavaJavadocFlags(ctx android.ModuleContext,
Nan Zhangde860a42018-08-08 16:32:21 -07001016 bootClasspathArgs, classpathArgs, outDir, docStubsDir string) string {
1017 return " --doc-stubs " + docStubsDir +
1018 " --write-doc-stubs-source-list " + android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
Nan Zhanga40da042018-08-01 12:48:00 -07001019 " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 DOC_STUBS_SOURCE_LIST " +
1020 bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
Nan Zhangde860a42018-08-08 16:32:21 -07001021 docStubsDir + " -quiet -d " + outDir
Nan Zhanga40da042018-08-01 12:48:00 -07001022}
1023
Nan Zhang86d2d552018-08-09 15:33:27 -07001024func (d *Droiddoc) collectMetalavaDokkaFlags(ctx android.ModuleContext, implicits *android.Paths,
1025 classpathArgs, outDir, docStubsDir string) string {
1026 dokka := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "dokka.jar")
1027 *implicits = append(*implicits, dokka)
1028
1029 return " --doc-stubs " + docStubsDir + " --write-doc-stubs-source-list " +
1030 android.PathForModuleOut(ctx, "doc_stubs.srclist").String() +
1031 " --generate-documentation ${config.JavaCmd} -jar " + dokka.String() + " " +
1032 docStubsDir + " " + classpathArgs + " -format dac -dacRoot /reference/kotlin -output " + outDir
1033}
1034
1035func (d *Droiddoc) transformMetalava(ctx android.ModuleContext, implicits android.Paths,
1036 implicitOutputs android.WritablePaths, outDir, docStubsDir, javaVersion,
1037 bootclasspathArgs, classpathArgs, opts string) {
1038 ctx.Build(pctx, android.BuildParams{
1039 Rule: metalava,
1040 Description: "Metalava",
1041 Output: d.Javadoc.stubsSrcJar,
1042 Inputs: d.Javadoc.srcFiles,
1043 Implicits: implicits,
1044 ImplicitOutputs: implicitOutputs,
1045 Args: map[string]string{
1046 "outDir": outDir,
1047 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1048 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1049 "docStubsDir": docStubsDir,
1050 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1051 "javaVersion": javaVersion,
1052 "bootclasspathArgs": bootclasspathArgs,
1053 "classpathArgs": classpathArgs,
1054 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1055 "docZip": d.Javadoc.docZip.String(),
1056 "opts": opts,
1057 },
1058 })
1059}
1060
1061func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths,
1062 implicitOutputs android.WritablePaths, bootclasspathArgs, classpathArgs, opts, postDoclavaCmds string) {
1063 ctx.Build(pctx, android.BuildParams{
1064 Rule: javadoc,
1065 Description: "Doclava",
1066 Output: d.Javadoc.stubsSrcJar,
1067 Inputs: d.Javadoc.srcFiles,
1068 Implicits: implicits,
1069 ImplicitOutputs: implicitOutputs,
1070 Args: map[string]string{
1071 "outDir": android.PathForModuleOut(ctx, "out").String(),
1072 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1073 "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(),
1074 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1075 "opts": opts,
1076 "bootclasspathArgs": bootclasspathArgs,
1077 "classpathArgs": classpathArgs,
1078 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1079 "docZip": d.Javadoc.docZip.String(),
1080 "postDoclavaCmds": postDoclavaCmds,
1081 },
1082 })
1083}
1084
1085func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1086 checkApiClasspath classpath, msg, opts string, output android.WritablePath) {
1087 ctx.Build(pctx, android.BuildParams{
1088 Rule: apiCheck,
Nan Zhanga05ff572018-08-20 20:33:38 -07001089 Description: "Doclava Check API",
Nan Zhang86d2d552018-08-09 15:33:27 -07001090 Output: output,
1091 Inputs: nil,
1092 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1093 checkApiClasspath...),
1094 Args: map[string]string{
1095 "classpath": checkApiClasspath.FormJavaClassPath(""),
1096 "opts": opts,
1097 "apiFile": apiFile.String(),
1098 "apiFileToCheck": d.apiFile.String(),
1099 "removedApiFile": removedApiFile.String(),
1100 "removedApiFileToCheck": d.removedApiFile.String(),
Colin Cross86bc9d42018-08-29 15:36:33 -07001101 "msg": msg,
Nan Zhang86d2d552018-08-09 15:33:27 -07001102 },
1103 })
1104}
1105
Nan Zhang2760dfc2018-08-24 17:32:54 +00001106func (d *Droiddoc) transformMetalavaCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1107 implicits android.Paths, javaVersion, bootclasspathArgs, classpathArgs, opts, msg string,
1108 output android.WritablePath) {
1109 ctx.Build(pctx, android.BuildParams{
1110 Rule: metalavaApiCheck,
1111 Description: "Metalava Check API",
1112 Output: output,
1113 Inputs: d.Javadoc.srcFiles,
1114 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
1115 implicits...),
1116 Args: map[string]string{
1117 "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(),
1118 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
1119 "javaVersion": javaVersion,
1120 "bootclasspathArgs": bootclasspathArgs,
1121 "classpathArgs": classpathArgs,
1122 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
1123 "opts": opts,
1124 "msg": msg,
1125 },
1126 })
1127}
1128
Nan Zhang86d2d552018-08-09 15:33:27 -07001129func (d *Droiddoc) transformUpdateApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path,
1130 output android.WritablePath) {
1131 ctx.Build(pctx, android.BuildParams{
1132 Rule: updateApi,
1133 Description: "Update API",
1134 Output: output,
1135 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
1136 Args: map[string]string{
1137 "apiFile": apiFile.String(),
1138 "apiFileToCheck": d.apiFile.String(),
1139 "removedApiFile": removedApiFile.String(),
1140 "removedApiFileToCheck": d.removedApiFile.String(),
1141 },
1142 })
1143}
1144
Nan Zhanga40da042018-08-01 12:48:00 -07001145func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1146 deps := d.Javadoc.collectDeps(ctx)
1147
1148 javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d))
Nan Zhanga40da042018-08-01 12:48:00 -07001149 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
1150 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
1151 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
1152 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
Nan Zhang581fd212018-01-10 16:06:12 -08001153
Nan Zhanga40da042018-08-01 12:48:00 -07001154 var implicits android.Paths
1155 implicits = append(implicits, d.Javadoc.srcJars...)
1156
1157 var implicitOutputs android.WritablePaths
1158 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
1159 for _, o := range d.properties.Out {
1160 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
1161 }
1162
1163 flags, err := d.initBuilderFlags(ctx, &implicits, deps)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001164 metalavaCheckApiImplicits := implicits
Nan Zhanga40da042018-08-01 12:48:00 -07001165 if err != nil {
1166 return
1167 }
1168
1169 flags.doclavaStubsFlags, flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs)
1170 if Bool(d.properties.Metalava_enabled) {
Nan Zhanga40da042018-08-01 12:48:00 -07001171 flags.metalavaAnnotationsFlags = d.collectMetalavaAnnotationsFlags(ctx, &implicits, &implicitOutputs)
Nan Zhang86d2d552018-08-09 15:33:27 -07001172 outDir := android.PathForModuleOut(ctx, "out").String()
Nan Zhangde860a42018-08-08 16:32:21 -07001173 docStubsDir := android.PathForModuleOut(ctx, "docStubsDir").String()
Nan Zhang86d2d552018-08-09 15:33:27 -07001174 // TODO(nanzhang): Add a Soong property to handle documentation args.
1175 if strings.Contains(flags.args, "--generate-documentation") { // enable docs generation
1176 if Bool(d.properties.Dokka_enabled) {
1177 flags.metalavaDokkaFlags = d.collectMetalavaDokkaFlags(ctx, &implicits,
1178 flags.dokkaClasspathArgs, outDir, docStubsDir)
1179 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1180 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhang2760dfc2018-08-24 17:32:54 +00001181 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001182 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001183 flags.metalavaDokkaFlags+" "+strings.Split(flags.args, "--generate-documentation")[1])
1184 } else {
1185 flags.metalavaJavadocFlags = d.collectMetalavaJavadocFlags(
1186 ctx, flags.bootClasspathArgs, flags.classpathArgs, outDir, docStubsDir)
Nan Zhang443fa522018-08-20 20:58:28 -07001187 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhang86d2d552018-08-09 15:33:27 -07001188 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1189 flags.bootClasspathArgs, flags.classpathArgs, flags.metalavaStubsFlags+
Nan Zhang2760dfc2018-08-24 17:32:54 +00001190 flags.metalavaAnnotationsFlags+" "+
Nan Zhanga05ff572018-08-20 20:33:38 -07001191 strings.Split(flags.args, "--generate-documentation")[0]+
Nan Zhang86d2d552018-08-09 15:33:27 -07001192 flags.metalavaJavadocFlags+flags.doclavaDocsFlags+
1193 " "+strings.Split(flags.args, "--generate-documentation")[1])
1194 }
Nan Zhanga40da042018-08-01 12:48:00 -07001195 } else {
Nan Zhang86d2d552018-08-09 15:33:27 -07001196 d.transformMetalava(ctx, implicits, implicitOutputs, outDir, docStubsDir, javaVersion,
1197 flags.bootClasspathArgs, flags.classpathArgs,
Nan Zhang2760dfc2018-08-24 17:32:54 +00001198 flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+" "+flags.args)
Nan Zhang79614d12018-04-19 18:03:39 -07001199 }
Nan Zhanga40da042018-08-01 12:48:00 -07001200 } else {
Nan Zhang443fa522018-08-20 20:58:28 -07001201 flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava)
Nan Zhanga40da042018-08-01 12:48:00 -07001202 flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits)
Nan Zhang86d2d552018-08-09 15:33:27 -07001203 d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs,
1204 flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+flags.args,
1205 flags.postDoclavaCmds)
Nan Zhang79614d12018-04-19 18:03:39 -07001206 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001207
Nan Zhang61819ce2018-05-04 18:49:16 -07001208 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001209 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
1210 "check_api.current.api_file")
1211 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
1212 "check_api.current_removed_api_file")
1213
Nan Zhang2760dfc2018-08-24 17:32:54 +00001214 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
Nan Zhang55e0bf42018-08-16 16:23:11 -07001215 if !Bool(d.properties.Metalava_enabled) {
Nan Zhang55e0bf42018-08-16 16:23:11 -07001216 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1217 fmt.Sprintf(`\n******************************\n`+
1218 `You have tried to change the API from what has been previously approved.\n\n`+
1219 `To make these errors go away, you have two choices:\n`+
1220 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1221 ` errors above.\n\n`+
1222 ` 2. You can update current.txt by executing the following command:\n`+
1223 ` make %s-update-current-api\n\n`+
1224 ` To submit the revised current.txt to the main Android repository,\n`+
1225 ` you will need approval.\n`+
1226 `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args),
1227 d.checkCurrentApiTimestamp)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001228 } else {
1229 opts := flags.args + " --check-compatibility:api:current " + apiFile.String() +
1230 " --check-compatibility:removed:current " + removedApiFile.String() + " "
1231
1232 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1233 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts,
1234 fmt.Sprintf(`\n******************************\n`+
1235 `You have tried to change the API from what has been previously approved.\n\n`+
1236 `To make these errors go away, you have two choices:\n`+
1237 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
1238 ` errors above.\n\n`+
1239 ` 2. You can update current.txt by executing the following command:\n`+
1240 ` make %s-update-current-api\n\n`+
1241 ` To submit the revised current.txt to the main Android repository,\n`+
1242 ` you will need approval.\n`+
1243 `******************************\n`, ctx.ModuleName()),
1244 d.checkCurrentApiTimestamp)
Nan Zhang55e0bf42018-08-16 16:23:11 -07001245 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001246
1247 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
Nan Zhang86d2d552018-08-09 15:33:27 -07001248 d.transformUpdateApi(ctx, apiFile, removedApiFile, d.updateCurrentApiTimestamp)
Nan Zhang61819ce2018-05-04 18:49:16 -07001249 }
Nan Zhanga40da042018-08-01 12:48:00 -07001250
Nan Zhang61819ce2018-05-04 18:49:16 -07001251 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
Nan Zhang61819ce2018-05-04 18:49:16 -07001252 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
1253 "check_api.last_released.api_file")
1254 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
1255 "check_api.last_released.removed_api_file")
1256
Nan Zhang2760dfc2018-08-24 17:32:54 +00001257 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
Nan Zhanga05ff572018-08-20 20:33:38 -07001258 if !Bool(d.properties.Metalava_enabled) {
Nan Zhanga05ff572018-08-20 20:33:38 -07001259 d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath,
1260 `\n******************************\n`+
1261 `You have tried to change the API from what has been previously released in\n`+
1262 `an SDK. Please fix the errors listed above.\n`+
1263 `******************************\n`, String(d.properties.Check_api.Last_released.Args),
1264 d.checkLastReleasedApiTimestamp)
Nan Zhang2760dfc2018-08-24 17:32:54 +00001265 } else {
1266 opts := flags.args + " --check-compatibility:api:released " + apiFile.String() +
1267 " --check-compatibility:removed:released " + removedApiFile.String() + " "
1268
1269 d.transformMetalavaCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits,
1270 javaVersion, flags.bootClasspathArgs, flags.classpathArgs, opts,
1271 `\n******************************\n`+
1272 `You have tried to change the API from what has been previously released in\n`+
1273 `an SDK. Please fix the errors listed above.\n`+
1274 `******************************\n`,
1275 d.checkLastReleasedApiTimestamp)
Nan Zhanga05ff572018-08-20 20:33:38 -07001276 }
Nan Zhang61819ce2018-05-04 18:49:16 -07001277 }
Nan Zhang581fd212018-01-10 16:06:12 -08001278}
Dan Willemsencc090972018-02-26 14:33:31 -08001279
Nan Zhanga40da042018-08-01 12:48:00 -07001280//
Nan Zhangf4936b02018-08-01 15:00:28 -07001281// Exported Droiddoc Directory
Nan Zhanga40da042018-08-01 12:48:00 -07001282//
Dan Willemsencc090972018-02-26 14:33:31 -08001283var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
Nan Zhangf4936b02018-08-01 15:00:28 -07001284var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"}
Dan Willemsencc090972018-02-26 14:33:31 -08001285
Nan Zhangf4936b02018-08-01 15:00:28 -07001286type ExportedDroiddocDirProperties struct {
1287 // path to the directory containing Droiddoc related files.
Dan Willemsencc090972018-02-26 14:33:31 -08001288 Path *string
1289}
1290
Nan Zhangf4936b02018-08-01 15:00:28 -07001291type ExportedDroiddocDir struct {
Dan Willemsencc090972018-02-26 14:33:31 -08001292 android.ModuleBase
1293
Nan Zhangf4936b02018-08-01 15:00:28 -07001294 properties ExportedDroiddocDirProperties
Dan Willemsencc090972018-02-26 14:33:31 -08001295
1296 deps android.Paths
1297 dir android.Path
1298}
1299
Nan Zhangf4936b02018-08-01 15:00:28 -07001300func ExportedDroiddocDirFactory() android.Module {
1301 module := &ExportedDroiddocDir{}
Dan Willemsencc090972018-02-26 14:33:31 -08001302 module.AddProperties(&module.properties)
1303 android.InitAndroidModule(module)
1304 return module
1305}
1306
Nan Zhangf4936b02018-08-01 15:00:28 -07001307func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {}
Dan Willemsencc090972018-02-26 14:33:31 -08001308
Nan Zhangf4936b02018-08-01 15:00:28 -07001309func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Dan Willemsencc090972018-02-26 14:33:31 -08001310 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1311 d.dir = path
1312 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1313}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001314
1315//
1316// Defaults
1317//
1318type DocDefaults struct {
1319 android.ModuleBase
1320 android.DefaultsModuleBase
1321}
1322
1323func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1324}
1325
1326func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1327}
1328
1329func DocDefaultsFactory() android.Module {
1330 module := &DocDefaults{}
1331
1332 module.AddProperties(
1333 &JavadocProperties{},
1334 &DroiddocProperties{},
1335 )
1336
1337 android.InitDefaultsModule(module)
1338
1339 return module
1340}