blob: b6410417b5bb797fcbd57002ce9b425bf92c556f [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 Zhang581fd212018-01-10 16:06:12 -080033 `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` +
34 `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` +
35 `-d $outDir -quiet && ` +
36 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
37 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
38 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 },
47 "outDir", "srcJarDir", "stubsDir", "srcJars", "opts",
Nan Zhang30963742018-04-23 09:59:14 -070048 "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip")
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{
70 Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` +
71 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
72 `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source 1.8 @$out.rsp @$srcJarDir/list ` +
73 `$bootclasspathArgs $classpathArgs -sourcepath $sourcepath --no-banner --color ` +
74 `--stubs $stubsDir --quiet --write-stubs-source-list $outDir/stubs_src_list $opts && ` +
75 `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` +
76 `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`,
77 CommandDeps: []string{
78 "${config.ZipSyncCmd}",
79 "${config.JavaCmd}",
80 "${config.MetalavaJar}",
81 "${config.JavadocCmd}",
82 "${config.SoongZipCmd}",
83 },
84 Rspfile: "$out.rsp",
85 RspfileContent: "$in",
86 Restat: true,
87 },
88 "outDir", "srcJarDir", "stubsDir", "srcJars", "bootclasspathArgs", "classpathArgs", "sourcepath", "opts", "docZip")
Nan Zhang581fd212018-01-10 16:06:12 -080089)
90
91func init() {
Nan Zhangb2b33de2018-02-23 11:18:47 -080092 android.RegisterModuleType("doc_defaults", DocDefaultsFactory)
93
Nan Zhang581fd212018-01-10 16:06:12 -080094 android.RegisterModuleType("droiddoc", DroiddocFactory)
95 android.RegisterModuleType("droiddoc_host", DroiddocHostFactory)
Dan Willemsencc090972018-02-26 14:33:31 -080096 android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory)
Nan Zhang581fd212018-01-10 16:06:12 -080097 android.RegisterModuleType("javadoc", JavadocFactory)
98 android.RegisterModuleType("javadoc_host", JavadocHostFactory)
99}
100
101type JavadocProperties struct {
102 // list of source files used to compile the Java module. May be .java, .logtags, .proto,
103 // or .aidl files.
104 Srcs []string `android:"arch_variant"`
105
106 // list of directories rooted at the Android.bp file that will
107 // be added to the search paths for finding source files when passing package names.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800108 Local_sourcepaths []string
Nan Zhang581fd212018-01-10 16:06:12 -0800109
110 // list of source files that should not be used to build the Java module.
111 // This is most useful in the arch/multilib variants to remove non-common files
112 // filegroup or genrule can be included within this property.
113 Exclude_srcs []string `android:"arch_variant"`
114
Nan Zhangb2b33de2018-02-23 11:18:47 -0800115 // list of java libraries that will be in the classpath.
Nan Zhang581fd212018-01-10 16:06:12 -0800116 Libs []string `android:"arch_variant"`
117
Nan Zhange66c7272018-03-06 12:59:27 -0800118 // don't build against the framework libraries (legacy-test, core-junit,
119 // ext, and framework for device targets)
120 No_framework_libs *bool
121
Nan Zhangb2b33de2018-02-23 11:18:47 -0800122 // the java library (in classpath) for documentation that provides java srcs and srcjars.
123 Srcs_lib *string
124
125 // the base dirs under srcs_lib will be scanned for java srcs.
126 Srcs_lib_whitelist_dirs []string
127
128 // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
129 Srcs_lib_whitelist_pkgs []string
130
Nan Zhang581fd212018-01-10 16:06:12 -0800131 // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800132 Installable *bool
Nan Zhang581fd212018-01-10 16:06:12 -0800133
134 // if not blank, set to the version of the sdk to compile against
135 Sdk_version *string `android:"arch_variant"`
Jiyong Park1e440682018-05-23 18:42:04 +0900136
137 Aidl struct {
138 // Top level directories to pass to aidl tool
139 Include_dirs []string
140
141 // Directories rooted at the Android.bp file to pass to aidl tool
142 Local_include_dirs []string
143 }
Nan Zhang581fd212018-01-10 16:06:12 -0800144}
145
Nan Zhang61819ce2018-05-04 18:49:16 -0700146type ApiToCheck struct {
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900147 // path to the API txt file that the new API extracted from source code is checked
148 // against. The path can be local to the module or from other module (via :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700149 Api_file *string
150
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900151 // path to the API txt file that the new @removed API extractd from source code is
152 // checked against. The path can be local to the module or from other module (via
153 // :module syntax).
Nan Zhang61819ce2018-05-04 18:49:16 -0700154 Removed_api_file *string
155
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900156 // Arguments to the apicheck tool.
Nan Zhang61819ce2018-05-04 18:49:16 -0700157 Args *string
158}
159
Nan Zhang581fd212018-01-10 16:06:12 -0800160type DroiddocProperties struct {
161 // directory relative to top of the source tree that contains doc templates files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800162 Custom_template *string
Nan Zhang581fd212018-01-10 16:06:12 -0800163
164 // directories relative to top of the source tree which contains html/jd files.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800165 Html_dirs []string
Nan Zhang581fd212018-01-10 16:06:12 -0800166
167 // set a value in the Clearsilver hdf namespace.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800168 Hdf []string
Nan Zhang581fd212018-01-10 16:06:12 -0800169
170 // proofread file contains all of the text content of the javadocs concatenated into one file,
171 // suitable for spell-checking and other goodness.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800172 Proofread_file *string
Nan Zhang581fd212018-01-10 16:06:12 -0800173
174 // a todo file lists the program elements that are missing documentation.
175 // At some point, this might be improved to show more warnings.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800176 Todo_file *string
177
178 // directory under current module source that provide additional resources (images).
179 Resourcesdir *string
180
181 // resources output directory under out/soong/.intermediates.
182 Resourcesoutdir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800183
184 // local files that are used within user customized droiddoc options.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800185 Arg_files []string
Nan Zhang581fd212018-01-10 16:06:12 -0800186
187 // user customized droiddoc args.
188 // Available variables for substitution:
189 //
190 // $(location <label>): the path to the arg_files with name <label>
Nan Zhangb2b33de2018-02-23 11:18:47 -0800191 Args *string
Nan Zhang581fd212018-01-10 16:06:12 -0800192
193 // names of the output files used in args that will be generated
Nan Zhangb2b33de2018-02-23 11:18:47 -0800194 Out []string
Nan Zhang581fd212018-01-10 16:06:12 -0800195
196 // a list of files under current module source dir which contains known tags in Java sources.
197 // filegroup or genrule can be included within this property.
Nan Zhangb2b33de2018-02-23 11:18:47 -0800198 Knowntags []string
Nan Zhang28c68b92018-03-13 16:17:01 -0700199
200 // the tag name used to distinguish if the API files belong to public/system/test.
201 Api_tag_name *string
202
203 // the generated public API filename by Doclava.
204 Api_filename *string
205
206 // the generated private API filename by Doclava.
207 Private_api_filename *string
208
209 // the generated private Dex API filename by Doclava.
210 Private_dex_api_filename *string
211
212 // the generated removed API filename by Doclava.
213 Removed_api_filename *string
214
David Brazdilaac0c3c2018-04-24 16:23:29 +0100215 // the generated removed Dex API filename by Doclava.
216 Removed_dex_api_filename *string
217
Nan Zhang28c68b92018-03-13 16:17:01 -0700218 // the generated exact API filename by Doclava.
219 Exact_api_filename *string
Nan Zhang853f4202018-04-12 16:55:56 -0700220
221 // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true.
222 Create_stubs *bool
Nan Zhang61819ce2018-05-04 18:49:16 -0700223
224 Check_api struct {
225 Last_released ApiToCheck
226
227 Current ApiToCheck
228 }
Nan Zhang79614d12018-04-19 18:03:39 -0700229
230 // if set to true, create stubs through Metalava instead of Doclava. Javadoc/Doclava is
231 // currently still used for documentation generation, and will be replaced by Dokka soon.
232 Metalava_enabled *bool
233
234 // user can specify the version of previous released API file in order to do compatibility check.
235 Metalava_previous_api *string
236
237 // is set to true, Metalava will allow framework SDK to contain annotations.
238 Metalava_annotations_enabled *bool
239
240 // a XML files set to merge annotations.
241 Metalava_merge_annotations_dir *string
Nan Zhang581fd212018-01-10 16:06:12 -0800242}
243
244type Javadoc struct {
245 android.ModuleBase
246 android.DefaultableModuleBase
247
248 properties JavadocProperties
249
250 srcJars android.Paths
251 srcFiles android.Paths
252 sourcepaths android.Paths
253
Nan Zhangccff0f72018-03-08 17:26:16 -0800254 docZip android.WritablePath
255 stubsSrcJar android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800256}
257
Nan Zhangb2b33de2018-02-23 11:18:47 -0800258func (j *Javadoc) Srcs() android.Paths {
259 return android.Paths{j.stubsSrcJar}
260}
261
262var _ android.SourceFileProducer = (*Javadoc)(nil)
263
Nan Zhang581fd212018-01-10 16:06:12 -0800264type Droiddoc struct {
265 Javadoc
266
Nan Zhang28c68b92018-03-13 16:17:01 -0700267 properties DroiddocProperties
268 apiFile android.WritablePath
269 privateApiFile android.WritablePath
270 privateDexApiFile android.WritablePath
271 removedApiFile android.WritablePath
David Brazdilaac0c3c2018-04-24 16:23:29 +0100272 removedDexApiFile android.WritablePath
Nan Zhang28c68b92018-03-13 16:17:01 -0700273 exactApiFile android.WritablePath
Nan Zhang61819ce2018-05-04 18:49:16 -0700274
275 checkCurrentApiTimestamp android.WritablePath
276 updateCurrentApiTimestamp android.WritablePath
277 checkLastReleasedApiTimestamp android.WritablePath
Nan Zhang581fd212018-01-10 16:06:12 -0800278}
279
280func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
281 android.InitAndroidArchModule(module, hod, android.MultilibCommon)
282 android.InitDefaultableModule(module)
283}
284
285func JavadocFactory() android.Module {
286 module := &Javadoc{}
287
288 module.AddProperties(&module.properties)
289
290 InitDroiddocModule(module, android.HostAndDeviceSupported)
291 return module
292}
293
294func JavadocHostFactory() android.Module {
295 module := &Javadoc{}
296
297 module.AddProperties(&module.properties)
298
299 InitDroiddocModule(module, android.HostSupported)
300 return module
301}
302
303func DroiddocFactory() android.Module {
304 module := &Droiddoc{}
305
306 module.AddProperties(&module.properties,
307 &module.Javadoc.properties)
308
309 InitDroiddocModule(module, android.HostAndDeviceSupported)
310 return module
311}
312
313func DroiddocHostFactory() android.Module {
314 module := &Droiddoc{}
315
316 module.AddProperties(&module.properties,
317 &module.Javadoc.properties)
318
319 InitDroiddocModule(module, android.HostSupported)
320 return module
321}
322
323func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
324 if ctx.Device() {
325 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
326 if sdkDep.useDefaultLibs {
327 ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...)
Nan Zhang9cbe6772018-03-21 17:56:39 -0700328 if !Bool(j.properties.No_framework_libs) {
Nan Zhange66c7272018-03-06 12:59:27 -0800329 ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...)
330 }
Nan Zhang581fd212018-01-10 16:06:12 -0800331 } else if sdkDep.useModule {
Colin Cross86a60ae2018-05-29 14:44:55 -0700332 ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...)
Nan Zhang581fd212018-01-10 16:06:12 -0800333 }
334 }
335
336 ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
337
338 android.ExtractSourcesDeps(ctx, j.properties.Srcs)
339
340 // exclude_srcs may contain filegroup or genrule.
341 android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
342}
343
Nan Zhangb2b33de2018-02-23 11:18:47 -0800344func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
345 for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
346 for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
Jiyong Park82484c02018-04-23 21:41:26 +0900347 // convert foo.bar.baz to foo/bar/baz
348 pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
349 prefix := filepath.Join(dir, pkgAsPath)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800350 if _, found := whitelistPathPrefixes[prefix]; !found {
351 whitelistPathPrefixes[prefix] = true
352 }
353 }
354 }
355}
356
Jiyong Park1e440682018-05-23 18:42:04 +0900357func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
358 var flags javaBuilderFlags
359
360 // aidl flags.
361 aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
362 if len(aidlFlags) > 0 {
363 // optimization.
364 ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " "))
365 flags.aidlFlags = "$aidlFlags"
366 }
367
368 return flags
369}
370
371func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
372 aidlIncludeDirs android.Paths) []string {
373
374 aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs)
375 aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...)
376
377 var flags []string
378 if aidlPreprocess.Valid() {
379 flags = append(flags, "-p"+aidlPreprocess.String())
380 } else {
381 flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
382 }
383
384 flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
385 flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
386 if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
387 flags = append(flags, "-I"+src.String())
388 }
389
390 return flags
391}
392
393func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths,
394 flags javaBuilderFlags) android.Paths {
395
396 outSrcFiles := make(android.Paths, 0, len(srcFiles))
397
398 for _, srcFile := range srcFiles {
399 switch srcFile.Ext() {
400 case ".aidl":
401 javaFile := genAidl(ctx, srcFile, flags.aidlFlags)
402 outSrcFiles = append(outSrcFiles, javaFile)
403 default:
404 outSrcFiles = append(outSrcFiles, srcFile)
405 }
406 }
407
408 return outSrcFiles
409}
410
Nan Zhang581fd212018-01-10 16:06:12 -0800411func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
412 var deps deps
413
414 sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version))
415 if sdkDep.invalidVersion {
Colin Cross86a60ae2018-05-29 14:44:55 -0700416 ctx.AddMissingDependencies(sdkDep.modules)
Nan Zhang581fd212018-01-10 16:06:12 -0800417 } else if sdkDep.useFiles {
Colin Cross86a60ae2018-05-29 14:44:55 -0700418 deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...)
Nan Zhang581fd212018-01-10 16:06:12 -0800419 }
420
421 ctx.VisitDirectDeps(func(module android.Module) {
422 otherName := ctx.OtherModuleName(module)
423 tag := ctx.OtherModuleDependencyTag(module)
424
Colin Cross2d24c1b2018-05-23 10:59:18 -0700425 switch tag {
426 case bootClasspathTag:
427 if dep, ok := module.(Dependency); ok {
Nan Zhang581fd212018-01-10 16:06:12 -0800428 deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700429 } else {
430 panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName()))
431 }
432 case libTag:
433 switch dep := module.(type) {
434 case Dependency:
Nan Zhang581fd212018-01-10 16:06:12 -0800435 deps.classpath = append(deps.classpath, dep.ImplementationJars()...)
Nan Zhangb2b33de2018-02-23 11:18:47 -0800436 if otherName == String(j.properties.Srcs_lib) {
437 srcs := dep.(SrcDependency).CompiledSrcs()
438 whitelistPathPrefixes := make(map[string]bool)
439 j.genWhitelistPathPrefixes(whitelistPathPrefixes)
440 for _, src := range srcs {
441 if _, ok := src.(android.WritablePath); ok { // generated sources
442 deps.srcs = append(deps.srcs, src)
443 } else { // select source path for documentation based on whitelist path prefixs.
444 for k, _ := range whitelistPathPrefixes {
445 if strings.HasPrefix(src.Rel(), k) {
446 deps.srcs = append(deps.srcs, src)
447 break
448 }
449 }
450 }
451 }
452 deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
453 }
Colin Cross2d24c1b2018-05-23 10:59:18 -0700454 case SdkLibraryDependency:
Jiyong Parkc678ad32018-04-10 13:07:10 +0900455 sdkVersion := String(j.properties.Sdk_version)
456 linkType := javaSdk
457 if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
458 linkType = javaSystem
459 } else if sdkVersion == "" {
460 linkType = javaPlatform
461 }
462 deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
Colin Cross2d24c1b2018-05-23 10:59:18 -0700463 case android.SourceFileProducer:
Nan Zhang581fd212018-01-10 16:06:12 -0800464 checkProducesJars(ctx, dep)
465 deps.classpath = append(deps.classpath, dep.Srcs()...)
Nan Zhang581fd212018-01-10 16:06:12 -0800466 default:
467 ctx.ModuleErrorf("depends on non-java module %q", otherName)
468 }
469 }
470 })
471 // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs
472 // may contain filegroup or genrule.
473 srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
Jiyong Park1e440682018-05-23 18:42:04 +0900474 flags := j.collectBuilderFlags(ctx, deps)
475 srcFiles = j.genSources(ctx, srcFiles, flags)
Nan Zhang581fd212018-01-10 16:06:12 -0800476
477 // srcs may depend on some genrule output.
478 j.srcJars = srcFiles.FilterByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800479 j.srcJars = append(j.srcJars, deps.srcJars...)
480
Nan Zhang581fd212018-01-10 16:06:12 -0800481 j.srcFiles = srcFiles.FilterOutByExt(".srcjar")
Nan Zhangb2b33de2018-02-23 11:18:47 -0800482 j.srcFiles = append(j.srcFiles, deps.srcs...)
Nan Zhang581fd212018-01-10 16:06:12 -0800483
484 j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip")
Nan Zhangccff0f72018-03-08 17:26:16 -0800485 j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")
Nan Zhang581fd212018-01-10 16:06:12 -0800486
487 if j.properties.Local_sourcepaths == nil {
488 j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".")
489 }
490 j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths)
Nan Zhang581fd212018-01-10 16:06:12 -0800491
492 return deps
493}
494
495func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) {
496 j.addDeps(ctx)
497}
498
499func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
500 deps := j.collectDeps(ctx)
501
502 var implicits android.Paths
503 implicits = append(implicits, deps.bootClasspath...)
504 implicits = append(implicits, deps.classpath...)
505
506 var bootClasspathArgs, classpathArgs string
507 if ctx.Config().UseOpenJDK9() {
508 if len(deps.bootClasspath) > 0 {
509 // For OpenJDK 9 we use --patch-module to define the core libraries code.
510 // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9
511 // modules. Here we treat all code in core libraries as being in java.base
512 // to work around the OpenJDK 9 module system. http://b/62049770
513 bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":")
514 }
515 } else {
516 if len(deps.bootClasspath.Strings()) > 0 {
517 // For OpenJDK 8 we can use -bootclasspath to define the core libraries code.
518 bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath")
519 }
520 }
521 if len(deps.classpath.Strings()) > 0 {
522 classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":")
523 }
524
525 implicits = append(implicits, j.srcJars...)
526
527 opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none"
528
529 ctx.Build(pctx, android.BuildParams{
530 Rule: javadoc,
531 Description: "Javadoc",
Nan Zhangccff0f72018-03-08 17:26:16 -0800532 Output: j.stubsSrcJar,
Nan Zhang581fd212018-01-10 16:06:12 -0800533 ImplicitOutput: j.docZip,
534 Inputs: j.srcFiles,
535 Implicits: implicits,
536 Args: map[string]string{
537 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
538 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
539 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
540 "srcJars": strings.Join(j.srcJars.Strings(), " "),
541 "opts": opts,
Nan Zhang853f4202018-04-12 16:55:56 -0700542 "bootclasspathArgs": bootClasspathArgs,
Nan Zhang581fd212018-01-10 16:06:12 -0800543 "classpathArgs": classpathArgs,
544 "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"),
545 "docZip": j.docZip.String(),
546 },
547 })
548}
549
Nan Zhang61819ce2018-05-04 18:49:16 -0700550func (d *Droiddoc) checkCurrentApi() bool {
551 if String(d.properties.Check_api.Current.Api_file) != "" &&
552 String(d.properties.Check_api.Current.Removed_api_file) != "" {
553 return true
554 } else if String(d.properties.Check_api.Current.Api_file) != "" {
555 panic("check_api.current.removed_api_file: has to be non empty!")
556 } else if String(d.properties.Check_api.Current.Removed_api_file) != "" {
557 panic("check_api.current.api_file: has to be non empty!")
558 }
559
560 return false
561}
562
563func (d *Droiddoc) checkLastReleasedApi() bool {
564 if String(d.properties.Check_api.Last_released.Api_file) != "" &&
565 String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
566 return true
567 } else if String(d.properties.Check_api.Last_released.Api_file) != "" {
568 panic("check_api.last_released.removed_api_file: has to be non empty!")
569 } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" {
570 panic("check_api.last_released.api_file: has to be non empty!")
571 }
572
573 return false
574}
575
Nan Zhang581fd212018-01-10 16:06:12 -0800576func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
577 d.Javadoc.addDeps(ctx)
578
Nan Zhang79614d12018-04-19 18:03:39 -0700579 if String(d.properties.Custom_template) != "" {
Dan Willemsencc090972018-02-26 14:33:31 -0800580 ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
581 }
582
Nan Zhang581fd212018-01-10 16:06:12 -0800583 // extra_arg_files may contains filegroup or genrule.
584 android.ExtractSourcesDeps(ctx, d.properties.Arg_files)
585
586 // knowntags may contain filegroup or genrule.
587 android.ExtractSourcesDeps(ctx, d.properties.Knowntags)
Nan Zhang61819ce2018-05-04 18:49:16 -0700588
589 if d.checkCurrentApi() {
590 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
591 android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
592 }
593
594 if d.checkLastReleasedApi() {
595 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file)
596 android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file)
597 }
Nan Zhang79614d12018-04-19 18:03:39 -0700598
599 if String(d.properties.Metalava_previous_api) != "" {
600 android.ExtractSourceDeps(ctx, d.properties.Metalava_previous_api)
601 }
Nan Zhang581fd212018-01-10 16:06:12 -0800602}
603
604func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) {
605 deps := d.Javadoc.collectDeps(ctx)
606
607 var implicits android.Paths
608 implicits = append(implicits, deps.bootClasspath...)
609 implicits = append(implicits, deps.classpath...)
610
Nan Zhang79614d12018-04-19 18:03:39 -0700611 bootClasspathArgs := deps.bootClasspath.FormJavaClassPath("-bootclasspath")
612 classpathArgs := deps.classpath.FormJavaClassPath("-classpath")
613
Nan Zhang581fd212018-01-10 16:06:12 -0800614 argFiles := ctx.ExpandSources(d.properties.Arg_files, nil)
615 argFilesMap := map[string]android.Path{}
616
617 for _, f := range argFiles {
618 implicits = append(implicits, f)
619 if _, exists := argFilesMap[f.Rel()]; !exists {
620 argFilesMap[f.Rel()] = f
621 } else {
622 ctx.ModuleErrorf("multiple arg_files for %q, %q and %q",
623 f, argFilesMap[f.Rel()], f.Rel())
624 }
625 }
626
627 args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) {
628 if strings.HasPrefix(name, "location ") {
629 label := strings.TrimSpace(strings.TrimPrefix(name, "location "))
630 if f, ok := argFilesMap[label]; ok {
631 return f.String(), nil
632 } else {
633 return "", fmt.Errorf("unknown location label %q", label)
634 }
635 } else if name == "genDir" {
636 return android.PathForModuleGen(ctx).String(), nil
637 }
638 return "", fmt.Errorf("unknown variable '$(%s)'", name)
639 })
640
641 if err != nil {
Nan Zhang79614d12018-04-19 18:03:39 -0700642 ctx.PropertyErrorf("args", "%s", err.Error())
Nan Zhang581fd212018-01-10 16:06:12 -0800643 return
644 }
645
Nan Zhang79614d12018-04-19 18:03:39 -0700646 genDocsForMetalava := false
647 var metalavaArgs string
648 if Bool(d.properties.Metalava_enabled) {
649 if strings.Contains(args, "--generate-documentation") {
650 if !strings.Contains(args, "-nodocs") {
651 genDocsForMetalava = true
652 }
653 // TODO(nanzhang): Add a Soong property to handle documentation args.
654 metalavaArgs = strings.Split(args, "--generate-documentation")[0]
Dan Willemsencc090972018-02-26 14:33:31 -0800655 } else {
Nan Zhang79614d12018-04-19 18:03:39 -0700656 metalavaArgs = args
Dan Willemsencc090972018-02-26 14:33:31 -0800657 }
Nan Zhang581fd212018-01-10 16:06:12 -0800658 }
659
Nan Zhang79614d12018-04-19 18:03:39 -0700660 var templateDir, htmlDirArgs, htmlDir2Args string
661 if !Bool(d.properties.Metalava_enabled) || genDocsForMetalava {
662 if String(d.properties.Custom_template) == "" {
663 // TODO: This is almost always droiddoc-templates-sdk
664 ctx.PropertyErrorf("custom_template", "must specify a template")
665 }
666
667 ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) {
668 if t, ok := m.(*DroiddocTemplate); ok {
669 implicits = append(implicits, t.deps...)
670 templateDir = t.dir.String()
671 } else {
672 ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m))
673 }
674 })
675
676 if len(d.properties.Html_dirs) > 0 {
677 htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0])
678 implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...)
679 htmlDirArgs = "-htmldir " + htmlDir.String()
680 }
681
682 if len(d.properties.Html_dirs) > 1 {
683 htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1])
684 implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...)
685 htmlDir2Args = "-htmldir2 " + htmlDir2.String()
686 }
687
688 if len(d.properties.Html_dirs) > 2 {
689 ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs")
690 }
691
692 knownTags := ctx.ExpandSources(d.properties.Knowntags, nil)
693 implicits = append(implicits, knownTags...)
694
695 for _, kt := range knownTags {
696 args = args + " -knowntags " + kt.String()
697 }
698
699 for _, hdf := range d.properties.Hdf {
700 args = args + " -hdf " + hdf
701 }
702
703 if String(d.properties.Proofread_file) != "" {
704 proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file))
705 args = args + " -proofread " + proofreadFile.String()
706 }
707
708 if String(d.properties.Todo_file) != "" {
709 // tricky part:
710 // we should not compute full path for todo_file through PathForModuleOut().
711 // the non-standard doclet will get the full path relative to "-o".
712 args = args + " -todo " + String(d.properties.Todo_file)
713 }
714
715 if String(d.properties.Resourcesdir) != "" {
716 // TODO: should we add files under resourcesDir to the implicits? It seems that
717 // resourcesDir is one sub dir of htmlDir
718 resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir))
719 args = args + " -resourcesdir " + resourcesDir.String()
720 }
721
722 if String(d.properties.Resourcesoutdir) != "" {
723 // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere.
724 args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir)
725 }
Dan Willemsencc090972018-02-26 14:33:31 -0800726 }
727
Nan Zhang79614d12018-04-19 18:03:39 -0700728 var docArgsForMetalava string
729 if Bool(d.properties.Metalava_enabled) && genDocsForMetalava {
730 docArgsForMetalava = strings.Split(args, "--generate-documentation")[1]
Nan Zhangb2b33de2018-02-23 11:18:47 -0800731 }
732
Nan Zhang28c68b92018-03-13 16:17:01 -0700733 var implicitOutputs android.WritablePaths
Nan Zhang61819ce2018-05-04 18:49:16 -0700734
735 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" {
736 d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
Nan Zhang28c68b92018-03-13 16:17:01 -0700737 args = args + " -api " + d.apiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700738 metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700739 implicitOutputs = append(implicitOutputs, d.apiFile)
740 }
741
Nan Zhang61819ce2018-05-04 18:49:16 -0700742 if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
743 d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
744 args = args + " -removedApi " + d.removedApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700745 metalavaArgs = metalavaArgs + " --removed-api " + d.removedApiFile.String()
Nan Zhang61819ce2018-05-04 18:49:16 -0700746 implicitOutputs = append(implicitOutputs, d.removedApiFile)
747 }
748
Nan Zhang28c68b92018-03-13 16:17:01 -0700749 if String(d.properties.Private_api_filename) != "" {
750 d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename))
751 args = args + " -privateApi " + d.privateApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700752 metalavaArgs = metalavaArgs + " --private-api " + d.privateApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700753 implicitOutputs = append(implicitOutputs, d.privateApiFile)
754 }
755
756 if String(d.properties.Private_dex_api_filename) != "" {
757 d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename))
758 args = args + " -privateDexApi " + d.privateDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700759 metalavaArgs = metalavaArgs + " --private-dex-api " + d.privateDexApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700760 implicitOutputs = append(implicitOutputs, d.privateDexApiFile)
761 }
762
David Brazdilaac0c3c2018-04-24 16:23:29 +0100763 if String(d.properties.Removed_dex_api_filename) != "" {
764 d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename))
765 args = args + " -removedDexApi " + d.removedDexApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700766 metalavaArgs = metalavaArgs + " --removed-dex-api " + d.removedDexApiFile.String()
David Brazdilaac0c3c2018-04-24 16:23:29 +0100767 implicitOutputs = append(implicitOutputs, d.removedDexApiFile)
768 }
769
Nan Zhang28c68b92018-03-13 16:17:01 -0700770 if String(d.properties.Exact_api_filename) != "" {
771 d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename))
772 args = args + " -exactApi " + d.exactApiFile.String()
Nan Zhang79614d12018-04-19 18:03:39 -0700773 metalavaArgs = metalavaArgs + " --exact-api " + d.exactApiFile.String()
Nan Zhang28c68b92018-03-13 16:17:01 -0700774 implicitOutputs = append(implicitOutputs, d.exactApiFile)
775 }
776
Nan Zhang581fd212018-01-10 16:06:12 -0800777 implicits = append(implicits, d.Javadoc.srcJars...)
778
Nan Zhang79614d12018-04-19 18:03:39 -0700779 implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
780 for _, o := range d.properties.Out {
781 implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o))
782 }
783
Nan Zhang30963742018-04-23 09:59:14 -0700784 jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar")
785 doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar")
Nan Zhang30963742018-04-23 09:59:14 -0700786
Nan Zhang46130972018-06-04 11:28:01 -0700787 var date string
788 if runtime.GOOS == "darwin" {
789 date = `date -r`
790 } else {
791 date = `date -d`
792 }
793
Nan Zhang79614d12018-04-19 18:03:39 -0700794 doclavaOpts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " +
Nan Zhang30963742018-04-23 09:59:14 -0700795 "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " +
Colin Cross480cd762018-02-22 14:39:17 -0800796 "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " +
Nan Zhang581fd212018-01-10 16:06:12 -0800797 "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " +
Nan Zhang79614d12018-04-19 18:03:39 -0700798 `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" `
Nan Zhang46130972018-06-04 11:28:01 -0700799
Nan Zhang79614d12018-04-19 18:03:39 -0700800 if !Bool(d.properties.Metalava_enabled) {
801 opts := doclavaOpts + args
Nan Zhang581fd212018-01-10 16:06:12 -0800802
Nan Zhang79614d12018-04-19 18:03:39 -0700803 implicits = append(implicits, jsilver)
804 implicits = append(implicits, doclava)
Nan Zhang581fd212018-01-10 16:06:12 -0800805
Nan Zhang79614d12018-04-19 18:03:39 -0700806 if BoolDefault(d.properties.Create_stubs, true) {
807 opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String()
808 }
809
810 ctx.Build(pctx, android.BuildParams{
811 Rule: javadoc,
812 Description: "Droiddoc",
813 Output: d.Javadoc.stubsSrcJar,
814 Inputs: d.Javadoc.srcFiles,
815 Implicits: implicits,
816 ImplicitOutputs: implicitOutputs,
817 Args: map[string]string{
818 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
819 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
820 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
821 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
822 "opts": opts,
823 "bootclasspathArgs": bootClasspathArgs,
824 "classpathArgs": classpathArgs,
825 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
826 "docZip": d.Javadoc.docZip.String(),
827 },
828 })
829 } else {
830 opts := metalavaArgs
831
832 buildArgs := map[string]string{
Nan Zhang581fd212018-01-10 16:06:12 -0800833 "outDir": android.PathForModuleOut(ctx, "docs", "out").String(),
834 "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(),
835 "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(),
836 "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "),
Nan Zhang581fd212018-01-10 16:06:12 -0800837 "bootclasspathArgs": bootClasspathArgs,
838 "classpathArgs": classpathArgs,
839 "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"),
840 "docZip": d.Javadoc.docZip.String(),
Nan Zhang79614d12018-04-19 18:03:39 -0700841 }
842
843 var previousApi android.Path
844 if String(d.properties.Metalava_previous_api) != "" {
845 previousApi = ctx.ExpandSource(String(d.properties.Metalava_previous_api),
846 "metalava_previous_api")
847 opts += " --check-compatibility --previous-api " + previousApi.String()
848 implicits = append(implicits, previousApi)
849 }
850
851 if Bool(d.properties.Metalava_annotations_enabled) {
852 if String(d.properties.Metalava_previous_api) == "" {
853 ctx.PropertyErrorf("metalava_previous_api",
854 "has to be non-empty if annotations was enabled!")
855 }
856 opts += " --include-annotations --migrate-nullness"
857
858 annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
859 implicitOutputs = append(implicitOutputs, annotationsZip)
860
861 if String(d.properties.Metalava_merge_annotations_dir) == "" {
862 ctx.PropertyErrorf("metalava_merge_annotations",
863 "has to be non-empty if annotations was enabled!")
864 }
865
866 mergeAnnotationsDir := android.PathForModuleSrc(ctx,
867 String(d.properties.Metalava_merge_annotations_dir))
868 implicits = append(implicits, ctx.Glob(mergeAnnotationsDir.Join(ctx, "**/*").String(), nil)...)
869
870 opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
871 // TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
872 opts += "--hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
873 }
874
875 if genDocsForMetalava {
876 opts += " --generate-documentation ${config.JavadocCmd} -encoding UTF-8 STUBS_SOURCE_LIST " +
877 doclavaOpts + docArgsForMetalava + bootClasspathArgs + " " + classpathArgs + " " + " -sourcepath " +
878 strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + " -quiet -d $outDir "
879 implicits = append(implicits, jsilver)
880 implicits = append(implicits, doclava)
881 }
882
883 buildArgs["opts"] = opts
884 ctx.Build(pctx, android.BuildParams{
885 Rule: metalava,
886 Description: "Metalava",
887 Output: d.Javadoc.stubsSrcJar,
888 Inputs: d.Javadoc.srcFiles,
889 Implicits: implicits,
890 ImplicitOutputs: implicitOutputs,
891 Args: buildArgs,
892 })
893 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700894
895 java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
896
897 checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")}
898
899 if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() {
900 d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp")
901
902 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file),
903 "check_api.current.api_file")
904 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file),
905 "check_api.current_removed_api_file")
906
907 ctx.Build(pctx, android.BuildParams{
908 Rule: apiCheck,
909 Description: "Current API check",
910 Output: d.checkCurrentApiTimestamp,
911 Inputs: nil,
912 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
913 checkApiClasspath...),
914 Args: map[string]string{
915 "classpath": checkApiClasspath.FormJavaClassPath(""),
916 "opts": String(d.properties.Check_api.Current.Args),
917 "apiFile": apiFile.String(),
918 "apiFileToCheck": d.apiFile.String(),
919 "removedApiFile": removedApiFile.String(),
920 "removedApiFileToCheck": d.removedApiFile.String(),
921 "msg": fmt.Sprintf(`\n******************************\n`+
922 `You have tried to change the API from what has been previously approved.\n\n`+
923 `To make these errors go away, you have two choices:\n`+
924 ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+
925 ` errors above.\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900926 ` 2. You can update current.txt by executing the following command:\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700927 ` make %s-update-current-api\n\n`+
Jiyong Parkeeb8a642018-05-12 22:21:20 +0900928 ` To submit the revised current.txt to the main Android repository,\n`+
Nan Zhang61819ce2018-05-04 18:49:16 -0700929 ` you will need approval.\n`+
930 `******************************\n`, ctx.ModuleName()),
931 },
932 })
933
934 d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp")
935
936 ctx.Build(pctx, android.BuildParams{
937 Rule: updateApi,
938 Description: "update current API",
939 Output: d.updateCurrentApiTimestamp,
940 Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile),
941 Args: map[string]string{
942 "apiFile": apiFile.String(),
943 "apiFileToCheck": d.apiFile.String(),
944 "removedApiFile": removedApiFile.String(),
945 "removedApiFileToCheck": d.removedApiFile.String(),
946 },
947 })
948 }
Nan Zhang61819ce2018-05-04 18:49:16 -0700949 if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() {
950 d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp")
951
952 apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file),
953 "check_api.last_released.api_file")
954 removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file),
955 "check_api.last_released.removed_api_file")
956
957 ctx.Build(pctx, android.BuildParams{
958 Rule: apiCheck,
959 Description: "Last Released API check",
960 Output: d.checkLastReleasedApiTimestamp,
961 Inputs: nil,
962 Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile},
963 checkApiClasspath...),
964 Args: map[string]string{
965 "classpath": checkApiClasspath.FormJavaClassPath(""),
966 "opts": String(d.properties.Check_api.Last_released.Args),
967 "apiFile": apiFile.String(),
968 "apiFileToCheck": d.apiFile.String(),
969 "removedApiFile": removedApiFile.String(),
970 "removedApiFileToCheck": d.removedApiFile.String(),
971 "msg": `\n******************************\n` +
972 `You have tried to change the API from what has been previously released in\n` +
973 `an SDK. Please fix the errors listed above.\n` +
974 `******************************\n`,
975 },
976 })
977 }
Nan Zhang581fd212018-01-10 16:06:12 -0800978}
Dan Willemsencc090972018-02-26 14:33:31 -0800979
980var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
981
982type DroiddocTemplateProperties struct {
983 // path to the directory containing the droiddoc templates.
984 Path *string
985}
986
987type DroiddocTemplate struct {
988 android.ModuleBase
989
990 properties DroiddocTemplateProperties
991
992 deps android.Paths
993 dir android.Path
994}
995
996func DroiddocTemplateFactory() android.Module {
997 module := &DroiddocTemplate{}
998 module.AddProperties(&module.properties)
999 android.InitAndroidModule(module)
1000 return module
1001}
1002
1003func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {}
1004
1005func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1006 path := android.PathForModuleSrc(ctx, String(d.properties.Path))
1007 d.dir = path
1008 d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil)
1009}
Nan Zhangb2b33de2018-02-23 11:18:47 -08001010
1011//
1012// Defaults
1013//
1014type DocDefaults struct {
1015 android.ModuleBase
1016 android.DefaultsModuleBase
1017}
1018
1019func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1020}
1021
1022func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1023}
1024
1025func DocDefaultsFactory() android.Module {
1026 module := &DocDefaults{}
1027
1028 module.AddProperties(
1029 &JavadocProperties{},
1030 &DroiddocProperties{},
1031 )
1032
1033 android.InitDefaultsModule(module)
1034
1035 return module
1036}