Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java/config" |
| 20 | "fmt" |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 21 | "path/filepath" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 22 | "strings" |
| 23 | |
| 24 | "github.com/google/blueprint" |
| 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | javadoc = pctx.AndroidStaticRule("javadoc", |
| 29 | blueprint.RuleParams{ |
| 30 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame^] | 31 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 32 | `${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + |
| 33 | `$opts $bootclasspathArgs $classpathArgs -sourcepath $sourcepath ` + |
| 34 | `-d $outDir -quiet && ` + |
| 35 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
| 36 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, |
| 37 | CommandDeps: []string{ |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame^] | 38 | "${config.ZipSyncCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 39 | "${config.JavadocCmd}", |
| 40 | "${config.SoongZipCmd}", |
| 41 | "$JsilverJar", |
| 42 | "$DoclavaJar", |
| 43 | }, |
| 44 | Rspfile: "$out.rsp", |
| 45 | RspfileContent: "$in", |
| 46 | Restat: true, |
| 47 | }, |
| 48 | "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", |
| 49 | "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip", "JsilverJar", "DoclavaJar") |
| 50 | ) |
| 51 | |
| 52 | func init() { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 53 | android.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 54 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 55 | android.RegisterModuleType("droiddoc", DroiddocFactory) |
| 56 | android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 57 | android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 58 | android.RegisterModuleType("javadoc", JavadocFactory) |
| 59 | android.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 60 | } |
| 61 | |
| 62 | type JavadocProperties struct { |
| 63 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 64 | // or .aidl files. |
| 65 | Srcs []string `android:"arch_variant"` |
| 66 | |
| 67 | // list of directories rooted at the Android.bp file that will |
| 68 | // be added to the search paths for finding source files when passing package names. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 69 | Local_sourcepaths []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 70 | |
| 71 | // list of source files that should not be used to build the Java module. |
| 72 | // This is most useful in the arch/multilib variants to remove non-common files |
| 73 | // filegroup or genrule can be included within this property. |
| 74 | Exclude_srcs []string `android:"arch_variant"` |
| 75 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 76 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 77 | Libs []string `android:"arch_variant"` |
| 78 | |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 79 | // don't build against the framework libraries (legacy-test, core-junit, |
| 80 | // ext, and framework for device targets) |
| 81 | No_framework_libs *bool |
| 82 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 83 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 84 | Srcs_lib *string |
| 85 | |
| 86 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 87 | Srcs_lib_whitelist_dirs []string |
| 88 | |
| 89 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 90 | Srcs_lib_whitelist_pkgs []string |
| 91 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 92 | // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 93 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 94 | |
| 95 | // if not blank, set to the version of the sdk to compile against |
| 96 | Sdk_version *string `android:"arch_variant"` |
| 97 | } |
| 98 | |
| 99 | type DroiddocProperties struct { |
| 100 | // directory relative to top of the source tree that contains doc templates files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 101 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 102 | |
| 103 | // directories relative to top of the source tree which contains html/jd files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 104 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 105 | |
| 106 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 107 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 108 | |
| 109 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 110 | // suitable for spell-checking and other goodness. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 111 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 112 | |
| 113 | // a todo file lists the program elements that are missing documentation. |
| 114 | // At some point, this might be improved to show more warnings. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 115 | Todo_file *string |
| 116 | |
| 117 | // directory under current module source that provide additional resources (images). |
| 118 | Resourcesdir *string |
| 119 | |
| 120 | // resources output directory under out/soong/.intermediates. |
| 121 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 122 | |
| 123 | // local files that are used within user customized droiddoc options. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 124 | Arg_files []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 125 | |
| 126 | // user customized droiddoc args. |
| 127 | // Available variables for substitution: |
| 128 | // |
| 129 | // $(location <label>): the path to the arg_files with name <label> |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 130 | Args *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 131 | |
| 132 | // names of the output files used in args that will be generated |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 133 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 134 | |
| 135 | // a list of files under current module source dir which contains known tags in Java sources. |
| 136 | // filegroup or genrule can be included within this property. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 137 | Knowntags []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | type Javadoc struct { |
| 141 | android.ModuleBase |
| 142 | android.DefaultableModuleBase |
| 143 | |
| 144 | properties JavadocProperties |
| 145 | |
| 146 | srcJars android.Paths |
| 147 | srcFiles android.Paths |
| 148 | sourcepaths android.Paths |
| 149 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 150 | docZip android.WritablePath |
| 151 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 154 | func (j *Javadoc) Srcs() android.Paths { |
| 155 | return android.Paths{j.stubsSrcJar} |
| 156 | } |
| 157 | |
| 158 | var _ android.SourceFileProducer = (*Javadoc)(nil) |
| 159 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 160 | type Droiddoc struct { |
| 161 | Javadoc |
| 162 | |
| 163 | properties DroiddocProperties |
| 164 | } |
| 165 | |
| 166 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 167 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 168 | android.InitDefaultableModule(module) |
| 169 | } |
| 170 | |
| 171 | func JavadocFactory() android.Module { |
| 172 | module := &Javadoc{} |
| 173 | |
| 174 | module.AddProperties(&module.properties) |
| 175 | |
| 176 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 177 | return module |
| 178 | } |
| 179 | |
| 180 | func JavadocHostFactory() android.Module { |
| 181 | module := &Javadoc{} |
| 182 | |
| 183 | module.AddProperties(&module.properties) |
| 184 | |
| 185 | InitDroiddocModule(module, android.HostSupported) |
| 186 | return module |
| 187 | } |
| 188 | |
| 189 | func DroiddocFactory() android.Module { |
| 190 | module := &Droiddoc{} |
| 191 | |
| 192 | module.AddProperties(&module.properties, |
| 193 | &module.Javadoc.properties) |
| 194 | |
| 195 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 196 | return module |
| 197 | } |
| 198 | |
| 199 | func DroiddocHostFactory() android.Module { |
| 200 | module := &Droiddoc{} |
| 201 | |
| 202 | module.AddProperties(&module.properties, |
| 203 | &module.Javadoc.properties) |
| 204 | |
| 205 | InitDroiddocModule(module, android.HostSupported) |
| 206 | return module |
| 207 | } |
| 208 | |
| 209 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 210 | if ctx.Device() { |
| 211 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 212 | if sdkDep.useDefaultLibs { |
| 213 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 214 | if Bool(j.properties.No_framework_libs) { |
| 215 | ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...) |
| 216 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 217 | } else if sdkDep.useModule { |
| 218 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 223 | |
| 224 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
| 225 | |
| 226 | // exclude_srcs may contain filegroup or genrule. |
| 227 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
| 228 | } |
| 229 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 230 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { |
| 231 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { |
| 232 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { |
| 233 | prefix := filepath.Join(dir, pkg) |
| 234 | if _, found := whitelistPathPrefixes[prefix]; !found { |
| 235 | whitelistPathPrefixes[prefix] = true |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 241 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 242 | var deps deps |
| 243 | |
| 244 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 245 | if sdkDep.invalidVersion { |
| 246 | ctx.AddMissingDependencies([]string{sdkDep.module}) |
| 247 | } else if sdkDep.useFiles { |
| 248 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jar) |
| 249 | } |
| 250 | |
| 251 | ctx.VisitDirectDeps(func(module android.Module) { |
| 252 | otherName := ctx.OtherModuleName(module) |
| 253 | tag := ctx.OtherModuleDependencyTag(module) |
| 254 | |
| 255 | switch dep := module.(type) { |
| 256 | case Dependency: |
| 257 | switch tag { |
| 258 | case bootClasspathTag: |
| 259 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
| 260 | case libTag: |
| 261 | deps.classpath = append(deps.classpath, dep.ImplementationJars()...) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 262 | if otherName == String(j.properties.Srcs_lib) { |
| 263 | srcs := dep.(SrcDependency).CompiledSrcs() |
| 264 | whitelistPathPrefixes := make(map[string]bool) |
| 265 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) |
| 266 | for _, src := range srcs { |
| 267 | if _, ok := src.(android.WritablePath); ok { // generated sources |
| 268 | deps.srcs = append(deps.srcs, src) |
| 269 | } else { // select source path for documentation based on whitelist path prefixs. |
| 270 | for k, _ := range whitelistPathPrefixes { |
| 271 | if strings.HasPrefix(src.Rel(), k) { |
| 272 | deps.srcs = append(deps.srcs, src) |
| 273 | break |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) |
| 279 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 280 | default: |
| 281 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 282 | } |
| 283 | case android.SourceFileProducer: |
| 284 | switch tag { |
| 285 | case libTag: |
| 286 | checkProducesJars(ctx, dep) |
| 287 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 288 | case android.DefaultsDepTag, android.SourceDepTag: |
| 289 | // Nothing to do |
| 290 | default: |
| 291 | ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName) |
| 292 | } |
| 293 | default: |
| 294 | switch tag { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 295 | case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 296 | // Nothing to do |
| 297 | default: |
| 298 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 299 | } |
| 300 | } |
| 301 | }) |
| 302 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 303 | // may contain filegroup or genrule. |
| 304 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
| 305 | |
| 306 | // srcs may depend on some genrule output. |
| 307 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 308 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 309 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 310 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 311 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 312 | |
| 313 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 314 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 315 | |
| 316 | if j.properties.Local_sourcepaths == nil { |
| 317 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") |
| 318 | } |
| 319 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) |
| 320 | j.sourcepaths = append(j.sourcepaths, deps.bootClasspath...) |
| 321 | j.sourcepaths = append(j.sourcepaths, deps.classpath...) |
| 322 | |
| 323 | return deps |
| 324 | } |
| 325 | |
| 326 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 327 | j.addDeps(ctx) |
| 328 | } |
| 329 | |
| 330 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 331 | deps := j.collectDeps(ctx) |
| 332 | |
| 333 | var implicits android.Paths |
| 334 | implicits = append(implicits, deps.bootClasspath...) |
| 335 | implicits = append(implicits, deps.classpath...) |
| 336 | |
| 337 | var bootClasspathArgs, classpathArgs string |
| 338 | if ctx.Config().UseOpenJDK9() { |
| 339 | if len(deps.bootClasspath) > 0 { |
| 340 | // For OpenJDK 9 we use --patch-module to define the core libraries code. |
| 341 | // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9 |
| 342 | // modules. Here we treat all code in core libraries as being in java.base |
| 343 | // to work around the OpenJDK 9 module system. http://b/62049770 |
| 344 | bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":") |
| 345 | } |
| 346 | } else { |
| 347 | if len(deps.bootClasspath.Strings()) > 0 { |
| 348 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
| 349 | bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 350 | } |
| 351 | } |
| 352 | if len(deps.classpath.Strings()) > 0 { |
| 353 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 354 | } |
| 355 | |
| 356 | implicits = append(implicits, j.srcJars...) |
| 357 | |
| 358 | opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" |
| 359 | |
| 360 | ctx.Build(pctx, android.BuildParams{ |
| 361 | Rule: javadoc, |
| 362 | Description: "Javadoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 363 | Output: j.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 364 | ImplicitOutput: j.docZip, |
| 365 | Inputs: j.srcFiles, |
| 366 | Implicits: implicits, |
| 367 | Args: map[string]string{ |
| 368 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 369 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 370 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 371 | "srcJars": strings.Join(j.srcJars.Strings(), " "), |
| 372 | "opts": opts, |
| 373 | "bootClasspathArgs": bootClasspathArgs, |
| 374 | "classpathArgs": classpathArgs, |
| 375 | "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"), |
| 376 | "docZip": j.docZip.String(), |
| 377 | }, |
| 378 | }) |
| 379 | } |
| 380 | |
| 381 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 382 | d.Javadoc.addDeps(ctx) |
| 383 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 384 | if String(d.properties.Custom_template) == "" { |
| 385 | // TODO: This is almost always droiddoc-templates-sdk |
| 386 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 387 | } else { |
| 388 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 389 | } |
| 390 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 391 | // extra_arg_files may contains filegroup or genrule. |
| 392 | android.ExtractSourcesDeps(ctx, d.properties.Arg_files) |
| 393 | |
| 394 | // knowntags may contain filegroup or genrule. |
| 395 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) |
| 396 | } |
| 397 | |
| 398 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 399 | deps := d.Javadoc.collectDeps(ctx) |
| 400 | |
| 401 | var implicits android.Paths |
| 402 | implicits = append(implicits, deps.bootClasspath...) |
| 403 | implicits = append(implicits, deps.classpath...) |
| 404 | |
| 405 | argFiles := ctx.ExpandSources(d.properties.Arg_files, nil) |
| 406 | argFilesMap := map[string]android.Path{} |
| 407 | |
| 408 | for _, f := range argFiles { |
| 409 | implicits = append(implicits, f) |
| 410 | if _, exists := argFilesMap[f.Rel()]; !exists { |
| 411 | argFilesMap[f.Rel()] = f |
| 412 | } else { |
| 413 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
| 414 | f, argFilesMap[f.Rel()], f.Rel()) |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) { |
| 419 | if strings.HasPrefix(name, "location ") { |
| 420 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 421 | if f, ok := argFilesMap[label]; ok { |
| 422 | return f.String(), nil |
| 423 | } else { |
| 424 | return "", fmt.Errorf("unknown location label %q", label) |
| 425 | } |
| 426 | } else if name == "genDir" { |
| 427 | return android.PathForModuleGen(ctx).String(), nil |
| 428 | } |
| 429 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 430 | }) |
| 431 | |
| 432 | if err != nil { |
| 433 | ctx.PropertyErrorf("extra_args", "%s", err.Error()) |
| 434 | return |
| 435 | } |
| 436 | |
| 437 | var bootClasspathArgs, classpathArgs string |
| 438 | if len(deps.bootClasspath.Strings()) > 0 { |
| 439 | bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":") |
| 440 | } |
| 441 | if len(deps.classpath.Strings()) > 0 { |
| 442 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 443 | } |
| 444 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 445 | var templateDir string |
| 446 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
| 447 | if t, ok := m.(*DroiddocTemplate); ok { |
| 448 | implicits = append(implicits, t.deps...) |
| 449 | templateDir = t.dir.String() |
| 450 | } else { |
| 451 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) |
| 452 | } |
| 453 | }) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 454 | |
| 455 | var htmlDirArgs string |
| 456 | if len(d.properties.Html_dirs) > 0 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 457 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 458 | implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) |
| 459 | htmlDirArgs = "-htmldir " + htmlDir.String() |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | var htmlDir2Args string |
| 463 | if len(d.properties.Html_dirs) > 1 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 464 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 465 | implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) |
| 466 | htmlDir2Args = "-htmldir2 " + htmlDir2.String() |
| 467 | } |
| 468 | |
| 469 | if len(d.properties.Html_dirs) > 2 { |
| 470 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) |
| 474 | implicits = append(implicits, knownTags...) |
| 475 | |
| 476 | for _, kt := range knownTags { |
| 477 | args = args + " -knowntags " + kt.String() |
| 478 | } |
| 479 | for _, hdf := range d.properties.Hdf { |
| 480 | args = args + " -hdf " + hdf |
| 481 | } |
| 482 | |
| 483 | if String(d.properties.Proofread_file) != "" { |
| 484 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
| 485 | args = args + " -proofread " + proofreadFile.String() |
| 486 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 487 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 488 | if String(d.properties.Todo_file) != "" { |
| 489 | // tricky part: |
| 490 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 491 | // the non-standard doclet will get the full path relative to "-o". |
| 492 | args = args + " -todo " + String(d.properties.Todo_file) |
| 493 | } |
| 494 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 495 | if String(d.properties.Resourcesdir) != "" { |
| 496 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 497 | // resourcesDir is one sub dir of htmlDir |
| 498 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
| 499 | args = args + " -resourcesdir " + resourcesDir.String() |
| 500 | } |
| 501 | |
| 502 | if String(d.properties.Resourcesoutdir) != "" { |
| 503 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
| 504 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) |
| 505 | } |
| 506 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 507 | implicits = append(implicits, d.Javadoc.srcJars...) |
| 508 | |
| 509 | opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + |
| 510 | "-doclet com.google.doclava.Doclava -docletpath ${config.JsilverJar}:${config.DoclavaJar} " + |
Colin Cross | 480cd76 | 2018-02-22 14:39:17 -0800 | [diff] [blame] | 511 | "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 512 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + |
| 513 | "-hdf page.now " + `"$$(date -d @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")"` + " " + |
| 514 | args + " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String() |
| 515 | |
| 516 | var implicitOutputs android.WritablePaths |
| 517 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) |
| 518 | for _, o := range d.properties.Out { |
| 519 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 520 | } |
| 521 | |
| 522 | ctx.Build(pctx, android.BuildParams{ |
| 523 | Rule: javadoc, |
| 524 | Description: "Droiddoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 525 | Output: d.Javadoc.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 526 | Inputs: d.Javadoc.srcFiles, |
| 527 | Implicits: implicits, |
| 528 | ImplicitOutputs: implicitOutputs, |
| 529 | Args: map[string]string{ |
| 530 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 531 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 532 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 533 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 534 | "opts": opts, |
| 535 | "bootclasspathArgs": bootClasspathArgs, |
| 536 | "classpathArgs": classpathArgs, |
| 537 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 538 | "docZip": d.Javadoc.docZip.String(), |
| 539 | "JsilverJar": "${config.JsilverJar}", |
| 540 | "DoclavaJar": "${config.DoclavaJar}", |
| 541 | }, |
| 542 | }) |
| 543 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 544 | |
| 545 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
| 546 | |
| 547 | type DroiddocTemplateProperties struct { |
| 548 | // path to the directory containing the droiddoc templates. |
| 549 | Path *string |
| 550 | } |
| 551 | |
| 552 | type DroiddocTemplate struct { |
| 553 | android.ModuleBase |
| 554 | |
| 555 | properties DroiddocTemplateProperties |
| 556 | |
| 557 | deps android.Paths |
| 558 | dir android.Path |
| 559 | } |
| 560 | |
| 561 | func DroiddocTemplateFactory() android.Module { |
| 562 | module := &DroiddocTemplate{} |
| 563 | module.AddProperties(&module.properties) |
| 564 | android.InitAndroidModule(module) |
| 565 | return module |
| 566 | } |
| 567 | |
| 568 | func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {} |
| 569 | |
| 570 | func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 571 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) |
| 572 | d.dir = path |
| 573 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) |
| 574 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 575 | |
| 576 | // |
| 577 | // Defaults |
| 578 | // |
| 579 | type DocDefaults struct { |
| 580 | android.ModuleBase |
| 581 | android.DefaultsModuleBase |
| 582 | } |
| 583 | |
| 584 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 585 | } |
| 586 | |
| 587 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 588 | } |
| 589 | |
| 590 | func DocDefaultsFactory() android.Module { |
| 591 | module := &DocDefaults{} |
| 592 | |
| 593 | module.AddProperties( |
| 594 | &JavadocProperties{}, |
| 595 | &DroiddocProperties{}, |
| 596 | ) |
| 597 | |
| 598 | android.InitDefaultsModule(module) |
| 599 | |
| 600 | return module |
| 601 | } |