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 | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 22 | "runtime" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | javadoc = pctx.AndroidStaticRule("javadoc", |
| 30 | blueprint.RuleParams{ |
| 31 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 32 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 33 | `${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 Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 39 | "${config.ZipSyncCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 40 | "${config.JavadocCmd}", |
| 41 | "${config.SoongZipCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 42 | }, |
| 43 | Rspfile: "$out.rsp", |
| 44 | RspfileContent: "$in", |
| 45 | Restat: true, |
| 46 | }, |
| 47 | "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 48 | "bootclasspathArgs", "classpathArgs", "sourcepath", "docZip") |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 49 | |
| 50 | apiCheck = pctx.AndroidStaticRule("apiCheck", |
| 51 | blueprint.RuleParams{ |
| 52 | Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` + |
| 53 | `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` + |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 54 | `&& touch $out ) || (echo -e "$msg" ; exit 38)`, |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 55 | 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 Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 67 | ) |
| 68 | |
| 69 | func init() { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 70 | android.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 71 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 72 | android.RegisterModuleType("droiddoc", DroiddocFactory) |
| 73 | android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 74 | android.RegisterModuleType("droiddoc_template", DroiddocTemplateFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 75 | android.RegisterModuleType("javadoc", JavadocFactory) |
| 76 | android.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 77 | } |
| 78 | |
| 79 | type JavadocProperties struct { |
| 80 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 81 | // or .aidl files. |
| 82 | Srcs []string `android:"arch_variant"` |
| 83 | |
| 84 | // list of directories rooted at the Android.bp file that will |
| 85 | // 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] | 86 | Local_sourcepaths []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 87 | |
| 88 | // list of source files that should not be used to build the Java module. |
| 89 | // This is most useful in the arch/multilib variants to remove non-common files |
| 90 | // filegroup or genrule can be included within this property. |
| 91 | Exclude_srcs []string `android:"arch_variant"` |
| 92 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 93 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 94 | Libs []string `android:"arch_variant"` |
| 95 | |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 96 | // don't build against the framework libraries (legacy-test, core-junit, |
| 97 | // ext, and framework for device targets) |
| 98 | No_framework_libs *bool |
| 99 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 100 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 101 | Srcs_lib *string |
| 102 | |
| 103 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 104 | Srcs_lib_whitelist_dirs []string |
| 105 | |
| 106 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 107 | Srcs_lib_whitelist_pkgs []string |
| 108 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 109 | // 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] | 110 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 111 | |
| 112 | // if not blank, set to the version of the sdk to compile against |
| 113 | Sdk_version *string `android:"arch_variant"` |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 114 | |
| 115 | Aidl struct { |
| 116 | // Top level directories to pass to aidl tool |
| 117 | Include_dirs []string |
| 118 | |
| 119 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 120 | Local_include_dirs []string |
| 121 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 124 | type ApiToCheck struct { |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 125 | // path to the API txt file that the new API extracted from source code is checked |
| 126 | // against. The path can be local to the module or from other module (via :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 127 | Api_file *string |
| 128 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 129 | // path to the API txt file that the new @removed API extractd from source code is |
| 130 | // checked against. The path can be local to the module or from other module (via |
| 131 | // :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 132 | Removed_api_file *string |
| 133 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 134 | // Arguments to the apicheck tool. |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 135 | Args *string |
| 136 | } |
| 137 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 138 | type DroiddocProperties struct { |
| 139 | // 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] | 140 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 141 | |
| 142 | // 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] | 143 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 144 | |
| 145 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 146 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 147 | |
| 148 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 149 | // suitable for spell-checking and other goodness. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 150 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 151 | |
| 152 | // a todo file lists the program elements that are missing documentation. |
| 153 | // At some point, this might be improved to show more warnings. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 154 | Todo_file *string |
| 155 | |
| 156 | // directory under current module source that provide additional resources (images). |
| 157 | Resourcesdir *string |
| 158 | |
| 159 | // resources output directory under out/soong/.intermediates. |
| 160 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 161 | |
| 162 | // local files that are used within user customized droiddoc options. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 163 | Arg_files []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 164 | |
| 165 | // user customized droiddoc args. |
| 166 | // Available variables for substitution: |
| 167 | // |
| 168 | // $(location <label>): the path to the arg_files with name <label> |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 169 | Args *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 170 | |
| 171 | // names of the output files used in args that will be generated |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 172 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 173 | |
| 174 | // a list of files under current module source dir which contains known tags in Java sources. |
| 175 | // filegroup or genrule can be included within this property. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 176 | Knowntags []string |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 177 | |
| 178 | // the tag name used to distinguish if the API files belong to public/system/test. |
| 179 | Api_tag_name *string |
| 180 | |
| 181 | // the generated public API filename by Doclava. |
| 182 | Api_filename *string |
| 183 | |
| 184 | // the generated private API filename by Doclava. |
| 185 | Private_api_filename *string |
| 186 | |
| 187 | // the generated private Dex API filename by Doclava. |
| 188 | Private_dex_api_filename *string |
| 189 | |
| 190 | // the generated removed API filename by Doclava. |
| 191 | Removed_api_filename *string |
| 192 | |
David Brazdil | aac0c3c | 2018-04-24 16:23:29 +0100 | [diff] [blame] | 193 | // the generated removed Dex API filename by Doclava. |
| 194 | Removed_dex_api_filename *string |
| 195 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 196 | // the generated exact API filename by Doclava. |
| 197 | Exact_api_filename *string |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 198 | |
| 199 | // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true. |
| 200 | Create_stubs *bool |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 201 | |
| 202 | Check_api struct { |
| 203 | Last_released ApiToCheck |
| 204 | |
| 205 | Current ApiToCheck |
| 206 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | type Javadoc struct { |
| 210 | android.ModuleBase |
| 211 | android.DefaultableModuleBase |
| 212 | |
| 213 | properties JavadocProperties |
| 214 | |
| 215 | srcJars android.Paths |
| 216 | srcFiles android.Paths |
| 217 | sourcepaths android.Paths |
| 218 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 219 | docZip android.WritablePath |
| 220 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 223 | func (j *Javadoc) Srcs() android.Paths { |
| 224 | return android.Paths{j.stubsSrcJar} |
| 225 | } |
| 226 | |
| 227 | var _ android.SourceFileProducer = (*Javadoc)(nil) |
| 228 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 229 | type Droiddoc struct { |
| 230 | Javadoc |
| 231 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 232 | properties DroiddocProperties |
| 233 | apiFile android.WritablePath |
| 234 | privateApiFile android.WritablePath |
| 235 | privateDexApiFile android.WritablePath |
| 236 | removedApiFile android.WritablePath |
David Brazdil | aac0c3c | 2018-04-24 16:23:29 +0100 | [diff] [blame] | 237 | removedDexApiFile android.WritablePath |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 238 | exactApiFile android.WritablePath |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 239 | |
| 240 | checkCurrentApiTimestamp android.WritablePath |
| 241 | updateCurrentApiTimestamp android.WritablePath |
| 242 | checkLastReleasedApiTimestamp android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 246 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 247 | android.InitDefaultableModule(module) |
| 248 | } |
| 249 | |
| 250 | func JavadocFactory() android.Module { |
| 251 | module := &Javadoc{} |
| 252 | |
| 253 | module.AddProperties(&module.properties) |
| 254 | |
| 255 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 256 | return module |
| 257 | } |
| 258 | |
| 259 | func JavadocHostFactory() android.Module { |
| 260 | module := &Javadoc{} |
| 261 | |
| 262 | module.AddProperties(&module.properties) |
| 263 | |
| 264 | InitDroiddocModule(module, android.HostSupported) |
| 265 | return module |
| 266 | } |
| 267 | |
| 268 | func DroiddocFactory() android.Module { |
| 269 | module := &Droiddoc{} |
| 270 | |
| 271 | module.AddProperties(&module.properties, |
| 272 | &module.Javadoc.properties) |
| 273 | |
| 274 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 275 | return module |
| 276 | } |
| 277 | |
| 278 | func DroiddocHostFactory() android.Module { |
| 279 | module := &Droiddoc{} |
| 280 | |
| 281 | module.AddProperties(&module.properties, |
| 282 | &module.Javadoc.properties) |
| 283 | |
| 284 | InitDroiddocModule(module, android.HostSupported) |
| 285 | return module |
| 286 | } |
| 287 | |
| 288 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 289 | if ctx.Device() { |
| 290 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 291 | if sdkDep.useDefaultLibs { |
| 292 | ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) |
Nan Zhang | 9cbe677 | 2018-03-21 17:56:39 -0700 | [diff] [blame] | 293 | if !Bool(j.properties.No_framework_libs) { |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 294 | ctx.AddDependency(ctx.Module(), libTag, []string{"ext", "framework"}...) |
| 295 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 296 | } else if sdkDep.useModule { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 297 | ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.modules...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) |
| 302 | |
| 303 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
| 304 | |
| 305 | // exclude_srcs may contain filegroup or genrule. |
| 306 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
| 307 | } |
| 308 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 309 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { |
| 310 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { |
| 311 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 312 | // convert foo.bar.baz to foo/bar/baz |
| 313 | pkgAsPath := filepath.Join(strings.Split(pkg, ".")...) |
| 314 | prefix := filepath.Join(dir, pkgAsPath) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 315 | if _, found := whitelistPathPrefixes[prefix]; !found { |
| 316 | whitelistPathPrefixes[prefix] = true |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 322 | func (j *Javadoc) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags { |
| 323 | var flags javaBuilderFlags |
| 324 | |
| 325 | // aidl flags. |
| 326 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
| 327 | if len(aidlFlags) > 0 { |
| 328 | // optimization. |
| 329 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 330 | flags.aidlFlags = "$aidlFlags" |
| 331 | } |
| 332 | |
| 333 | return flags |
| 334 | } |
| 335 | |
| 336 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
| 337 | aidlIncludeDirs android.Paths) []string { |
| 338 | |
| 339 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) |
| 340 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) |
| 341 | |
| 342 | var flags []string |
| 343 | if aidlPreprocess.Valid() { |
| 344 | flags = append(flags, "-p"+aidlPreprocess.String()) |
| 345 | } else { |
| 346 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
| 347 | } |
| 348 | |
| 349 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 350 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 351 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
| 352 | flags = append(flags, "-I"+src.String()) |
| 353 | } |
| 354 | |
| 355 | return flags |
| 356 | } |
| 357 | |
| 358 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
| 359 | flags javaBuilderFlags) android.Paths { |
| 360 | |
| 361 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 362 | |
| 363 | for _, srcFile := range srcFiles { |
| 364 | switch srcFile.Ext() { |
| 365 | case ".aidl": |
| 366 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 367 | outSrcFiles = append(outSrcFiles, javaFile) |
| 368 | default: |
| 369 | outSrcFiles = append(outSrcFiles, srcFile) |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | return outSrcFiles |
| 374 | } |
| 375 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 376 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 377 | var deps deps |
| 378 | |
| 379 | sdkDep := decodeSdkDep(ctx, String(j.properties.Sdk_version)) |
| 380 | if sdkDep.invalidVersion { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 381 | ctx.AddMissingDependencies(sdkDep.modules) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 382 | } else if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 383 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | ctx.VisitDirectDeps(func(module android.Module) { |
| 387 | otherName := ctx.OtherModuleName(module) |
| 388 | tag := ctx.OtherModuleDependencyTag(module) |
| 389 | |
| 390 | switch dep := module.(type) { |
| 391 | case Dependency: |
| 392 | switch tag { |
| 393 | case bootClasspathTag: |
| 394 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
| 395 | case libTag: |
| 396 | deps.classpath = append(deps.classpath, dep.ImplementationJars()...) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 397 | if otherName == String(j.properties.Srcs_lib) { |
| 398 | srcs := dep.(SrcDependency).CompiledSrcs() |
| 399 | whitelistPathPrefixes := make(map[string]bool) |
| 400 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) |
| 401 | for _, src := range srcs { |
| 402 | if _, ok := src.(android.WritablePath); ok { // generated sources |
| 403 | deps.srcs = append(deps.srcs, src) |
| 404 | } else { // select source path for documentation based on whitelist path prefixs. |
| 405 | for k, _ := range whitelistPathPrefixes { |
| 406 | if strings.HasPrefix(src.Rel(), k) { |
| 407 | deps.srcs = append(deps.srcs, src) |
| 408 | break |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) |
| 414 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 415 | default: |
| 416 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 417 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 418 | case SdkLibraryDependency: |
| 419 | switch tag { |
| 420 | case libTag: |
| 421 | sdkVersion := String(j.properties.Sdk_version) |
| 422 | linkType := javaSdk |
| 423 | if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") { |
| 424 | linkType = javaSystem |
| 425 | } else if sdkVersion == "" { |
| 426 | linkType = javaPlatform |
| 427 | } |
| 428 | deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...) |
| 429 | default: |
| 430 | ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName) |
| 431 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 432 | case android.SourceFileProducer: |
| 433 | switch tag { |
| 434 | case libTag: |
| 435 | checkProducesJars(ctx, dep) |
| 436 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
| 437 | case android.DefaultsDepTag, android.SourceDepTag: |
| 438 | // Nothing to do |
| 439 | default: |
| 440 | ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs", otherName) |
| 441 | } |
| 442 | default: |
| 443 | switch tag { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 444 | case android.DefaultsDepTag, android.SourceDepTag, droiddocTemplateTag: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 445 | // Nothing to do |
| 446 | default: |
| 447 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 448 | } |
| 449 | } |
| 450 | }) |
| 451 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 452 | // may contain filegroup or genrule. |
| 453 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 454 | flags := j.collectBuilderFlags(ctx, deps) |
| 455 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 456 | |
| 457 | // srcs may depend on some genrule output. |
| 458 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 459 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 460 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 461 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 462 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 463 | |
| 464 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 465 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 466 | |
| 467 | if j.properties.Local_sourcepaths == nil { |
| 468 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") |
| 469 | } |
| 470 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 471 | |
| 472 | return deps |
| 473 | } |
| 474 | |
| 475 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 476 | j.addDeps(ctx) |
| 477 | } |
| 478 | |
| 479 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 480 | deps := j.collectDeps(ctx) |
| 481 | |
| 482 | var implicits android.Paths |
| 483 | implicits = append(implicits, deps.bootClasspath...) |
| 484 | implicits = append(implicits, deps.classpath...) |
| 485 | |
| 486 | var bootClasspathArgs, classpathArgs string |
| 487 | if ctx.Config().UseOpenJDK9() { |
| 488 | if len(deps.bootClasspath) > 0 { |
| 489 | // For OpenJDK 9 we use --patch-module to define the core libraries code. |
| 490 | // TODO(tobiast): Reorganize this when adding proper support for OpenJDK 9 |
| 491 | // modules. Here we treat all code in core libraries as being in java.base |
| 492 | // to work around the OpenJDK 9 module system. http://b/62049770 |
| 493 | bootClasspathArgs = "--patch-module=java.base=" + strings.Join(deps.bootClasspath.Strings(), ":") |
| 494 | } |
| 495 | } else { |
| 496 | if len(deps.bootClasspath.Strings()) > 0 { |
| 497 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
| 498 | bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 499 | } |
| 500 | } |
| 501 | if len(deps.classpath.Strings()) > 0 { |
| 502 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 503 | } |
| 504 | |
| 505 | implicits = append(implicits, j.srcJars...) |
| 506 | |
| 507 | opts := "-J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" |
| 508 | |
| 509 | ctx.Build(pctx, android.BuildParams{ |
| 510 | Rule: javadoc, |
| 511 | Description: "Javadoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 512 | Output: j.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 513 | ImplicitOutput: j.docZip, |
| 514 | Inputs: j.srcFiles, |
| 515 | Implicits: implicits, |
| 516 | Args: map[string]string{ |
| 517 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 518 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 519 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 520 | "srcJars": strings.Join(j.srcJars.Strings(), " "), |
| 521 | "opts": opts, |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 522 | "bootclasspathArgs": bootClasspathArgs, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 523 | "classpathArgs": classpathArgs, |
| 524 | "sourcepath": strings.Join(j.sourcepaths.Strings(), ":"), |
| 525 | "docZip": j.docZip.String(), |
| 526 | }, |
| 527 | }) |
| 528 | } |
| 529 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 530 | func (d *Droiddoc) checkCurrentApi() bool { |
| 531 | if String(d.properties.Check_api.Current.Api_file) != "" && |
| 532 | String(d.properties.Check_api.Current.Removed_api_file) != "" { |
| 533 | return true |
| 534 | } else if String(d.properties.Check_api.Current.Api_file) != "" { |
| 535 | panic("check_api.current.removed_api_file: has to be non empty!") |
| 536 | } else if String(d.properties.Check_api.Current.Removed_api_file) != "" { |
| 537 | panic("check_api.current.api_file: has to be non empty!") |
| 538 | } |
| 539 | |
| 540 | return false |
| 541 | } |
| 542 | |
| 543 | func (d *Droiddoc) checkLastReleasedApi() bool { |
| 544 | if String(d.properties.Check_api.Last_released.Api_file) != "" && |
| 545 | String(d.properties.Check_api.Last_released.Removed_api_file) != "" { |
| 546 | return true |
| 547 | } else if String(d.properties.Check_api.Last_released.Api_file) != "" { |
| 548 | panic("check_api.last_released.removed_api_file: has to be non empty!") |
| 549 | } else if String(d.properties.Check_api.Last_released.Removed_api_file) != "" { |
| 550 | panic("check_api.last_released.api_file: has to be non empty!") |
| 551 | } |
| 552 | |
| 553 | return false |
| 554 | } |
| 555 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 556 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 557 | d.Javadoc.addDeps(ctx) |
| 558 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 559 | if String(d.properties.Custom_template) == "" { |
| 560 | // TODO: This is almost always droiddoc-templates-sdk |
| 561 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 562 | } else { |
| 563 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 564 | } |
| 565 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 566 | // extra_arg_files may contains filegroup or genrule. |
| 567 | android.ExtractSourcesDeps(ctx, d.properties.Arg_files) |
| 568 | |
| 569 | // knowntags may contain filegroup or genrule. |
| 570 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 571 | |
| 572 | if d.checkCurrentApi() { |
| 573 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) |
| 574 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) |
| 575 | } |
| 576 | |
| 577 | if d.checkLastReleasedApi() { |
| 578 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) |
| 579 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) |
| 580 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 584 | deps := d.Javadoc.collectDeps(ctx) |
| 585 | |
| 586 | var implicits android.Paths |
| 587 | implicits = append(implicits, deps.bootClasspath...) |
| 588 | implicits = append(implicits, deps.classpath...) |
| 589 | |
| 590 | argFiles := ctx.ExpandSources(d.properties.Arg_files, nil) |
| 591 | argFilesMap := map[string]android.Path{} |
| 592 | |
| 593 | for _, f := range argFiles { |
| 594 | implicits = append(implicits, f) |
| 595 | if _, exists := argFilesMap[f.Rel()]; !exists { |
| 596 | argFilesMap[f.Rel()] = f |
| 597 | } else { |
| 598 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
| 599 | f, argFilesMap[f.Rel()], f.Rel()) |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | args, err := android.Expand(String(d.properties.Args), func(name string) (string, error) { |
| 604 | if strings.HasPrefix(name, "location ") { |
| 605 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 606 | if f, ok := argFilesMap[label]; ok { |
| 607 | return f.String(), nil |
| 608 | } else { |
| 609 | return "", fmt.Errorf("unknown location label %q", label) |
| 610 | } |
| 611 | } else if name == "genDir" { |
| 612 | return android.PathForModuleGen(ctx).String(), nil |
| 613 | } |
| 614 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 615 | }) |
| 616 | |
| 617 | if err != nil { |
| 618 | ctx.PropertyErrorf("extra_args", "%s", err.Error()) |
| 619 | return |
| 620 | } |
| 621 | |
| 622 | var bootClasspathArgs, classpathArgs string |
| 623 | if len(deps.bootClasspath.Strings()) > 0 { |
| 624 | bootClasspathArgs = "-bootclasspath " + strings.Join(deps.bootClasspath.Strings(), ":") |
| 625 | } |
| 626 | if len(deps.classpath.Strings()) > 0 { |
| 627 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 628 | } |
| 629 | |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 630 | var templateDir string |
| 631 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
| 632 | if t, ok := m.(*DroiddocTemplate); ok { |
| 633 | implicits = append(implicits, t.deps...) |
| 634 | templateDir = t.dir.String() |
| 635 | } else { |
| 636 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) |
| 637 | } |
| 638 | }) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 639 | |
| 640 | var htmlDirArgs string |
| 641 | if len(d.properties.Html_dirs) > 0 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 642 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 643 | implicits = append(implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) |
| 644 | htmlDirArgs = "-htmldir " + htmlDir.String() |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | var htmlDir2Args string |
| 648 | if len(d.properties.Html_dirs) > 1 { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 649 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 650 | implicits = append(implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) |
| 651 | htmlDir2Args = "-htmldir2 " + htmlDir2.String() |
| 652 | } |
| 653 | |
| 654 | if len(d.properties.Html_dirs) > 2 { |
| 655 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) |
| 659 | implicits = append(implicits, knownTags...) |
| 660 | |
| 661 | for _, kt := range knownTags { |
| 662 | args = args + " -knowntags " + kt.String() |
| 663 | } |
| 664 | for _, hdf := range d.properties.Hdf { |
| 665 | args = args + " -hdf " + hdf |
| 666 | } |
| 667 | |
| 668 | if String(d.properties.Proofread_file) != "" { |
| 669 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
| 670 | args = args + " -proofread " + proofreadFile.String() |
| 671 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 672 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 673 | if String(d.properties.Todo_file) != "" { |
| 674 | // tricky part: |
| 675 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 676 | // the non-standard doclet will get the full path relative to "-o". |
| 677 | args = args + " -todo " + String(d.properties.Todo_file) |
| 678 | } |
| 679 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 680 | if String(d.properties.Resourcesdir) != "" { |
| 681 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 682 | // resourcesDir is one sub dir of htmlDir |
| 683 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
| 684 | args = args + " -resourcesdir " + resourcesDir.String() |
| 685 | } |
| 686 | |
| 687 | if String(d.properties.Resourcesoutdir) != "" { |
| 688 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
| 689 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) |
| 690 | } |
| 691 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 692 | var implicitOutputs android.WritablePaths |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 693 | |
| 694 | if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Api_filename) != "" { |
| 695 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 696 | args = args + " -api " + d.apiFile.String() |
| 697 | implicitOutputs = append(implicitOutputs, d.apiFile) |
| 698 | } |
| 699 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 700 | if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" { |
| 701 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") |
| 702 | args = args + " -removedApi " + d.removedApiFile.String() |
| 703 | implicitOutputs = append(implicitOutputs, d.removedApiFile) |
| 704 | } |
| 705 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 706 | if String(d.properties.Private_api_filename) != "" { |
| 707 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) |
| 708 | args = args + " -privateApi " + d.privateApiFile.String() |
| 709 | implicitOutputs = append(implicitOutputs, d.privateApiFile) |
| 710 | } |
| 711 | |
| 712 | if String(d.properties.Private_dex_api_filename) != "" { |
| 713 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) |
| 714 | args = args + " -privateDexApi " + d.privateDexApiFile.String() |
| 715 | implicitOutputs = append(implicitOutputs, d.privateDexApiFile) |
| 716 | } |
| 717 | |
David Brazdil | aac0c3c | 2018-04-24 16:23:29 +0100 | [diff] [blame] | 718 | if String(d.properties.Removed_dex_api_filename) != "" { |
| 719 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) |
| 720 | args = args + " -removedDexApi " + d.removedDexApiFile.String() |
| 721 | implicitOutputs = append(implicitOutputs, d.removedDexApiFile) |
| 722 | } |
| 723 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 724 | if String(d.properties.Exact_api_filename) != "" { |
| 725 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) |
| 726 | args = args + " -exactApi " + d.exactApiFile.String() |
| 727 | implicitOutputs = append(implicitOutputs, d.exactApiFile) |
| 728 | } |
| 729 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 730 | implicits = append(implicits, d.Javadoc.srcJars...) |
| 731 | |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 732 | jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") |
| 733 | doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") |
| 734 | implicits = append(implicits, jsilver) |
| 735 | implicits = append(implicits, doclava) |
| 736 | |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 737 | var date string |
| 738 | if runtime.GOOS == "darwin" { |
| 739 | date = `date -r` |
| 740 | } else { |
| 741 | date = `date -d` |
| 742 | } |
| 743 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 744 | opts := "-source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 745 | "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " + |
Colin Cross | 480cd76 | 2018-02-22 14:39:17 -0800 | [diff] [blame] | 746 | "-templatedir " + templateDir + " " + htmlDirArgs + " " + htmlDir2Args + " " + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 747 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 748 | `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" ` + |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 749 | " " + args |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 750 | |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 751 | if BoolDefault(d.properties.Create_stubs, true) { |
| 752 | opts += " -stubs " + android.PathForModuleOut(ctx, "docs", "stubsDir").String() |
| 753 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 754 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 755 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) |
| 756 | for _, o := range d.properties.Out { |
| 757 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 758 | } |
| 759 | |
| 760 | ctx.Build(pctx, android.BuildParams{ |
| 761 | Rule: javadoc, |
| 762 | Description: "Droiddoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 763 | Output: d.Javadoc.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 764 | Inputs: d.Javadoc.srcFiles, |
| 765 | Implicits: implicits, |
| 766 | ImplicitOutputs: implicitOutputs, |
| 767 | Args: map[string]string{ |
| 768 | "outDir": android.PathForModuleOut(ctx, "docs", "out").String(), |
| 769 | "srcJarDir": android.PathForModuleOut(ctx, "docs", "srcjars").String(), |
| 770 | "stubsDir": android.PathForModuleOut(ctx, "docs", "stubsDir").String(), |
| 771 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 772 | "opts": opts, |
| 773 | "bootclasspathArgs": bootClasspathArgs, |
| 774 | "classpathArgs": classpathArgs, |
| 775 | "sourcepath": strings.Join(d.Javadoc.sourcepaths.Strings(), ":"), |
| 776 | "docZip": d.Javadoc.docZip.String(), |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 777 | }, |
| 778 | }) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 779 | |
| 780 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 781 | |
| 782 | checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")} |
| 783 | |
| 784 | if d.checkCurrentApi() && !ctx.Config().IsPdkBuild() { |
| 785 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") |
| 786 | |
| 787 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), |
| 788 | "check_api.current.api_file") |
| 789 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), |
| 790 | "check_api.current_removed_api_file") |
| 791 | |
| 792 | ctx.Build(pctx, android.BuildParams{ |
| 793 | Rule: apiCheck, |
| 794 | Description: "Current API check", |
| 795 | Output: d.checkCurrentApiTimestamp, |
| 796 | Inputs: nil, |
| 797 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 798 | checkApiClasspath...), |
| 799 | Args: map[string]string{ |
| 800 | "classpath": checkApiClasspath.FormJavaClassPath(""), |
| 801 | "opts": String(d.properties.Check_api.Current.Args), |
| 802 | "apiFile": apiFile.String(), |
| 803 | "apiFileToCheck": d.apiFile.String(), |
| 804 | "removedApiFile": removedApiFile.String(), |
| 805 | "removedApiFileToCheck": d.removedApiFile.String(), |
| 806 | "msg": fmt.Sprintf(`\n******************************\n`+ |
| 807 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 808 | `To make these errors go away, you have two choices:\n`+ |
| 809 | ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ |
| 810 | ` errors above.\n\n`+ |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 811 | ` 2. You can update current.txt by executing the following command:\n`+ |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 812 | ` make %s-update-current-api\n\n`+ |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 813 | ` To submit the revised current.txt to the main Android repository,\n`+ |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 814 | ` you will need approval.\n`+ |
| 815 | `******************************\n`, ctx.ModuleName()), |
| 816 | }, |
| 817 | }) |
| 818 | |
| 819 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") |
| 820 | |
| 821 | ctx.Build(pctx, android.BuildParams{ |
| 822 | Rule: updateApi, |
| 823 | Description: "update current API", |
| 824 | Output: d.updateCurrentApiTimestamp, |
| 825 | Implicits: append(android.Paths{}, apiFile, removedApiFile, d.apiFile, d.removedApiFile), |
| 826 | Args: map[string]string{ |
| 827 | "apiFile": apiFile.String(), |
| 828 | "apiFileToCheck": d.apiFile.String(), |
| 829 | "removedApiFile": removedApiFile.String(), |
| 830 | "removedApiFileToCheck": d.removedApiFile.String(), |
| 831 | }, |
| 832 | }) |
| 833 | } |
| 834 | |
| 835 | if d.checkLastReleasedApi() && !ctx.Config().IsPdkBuild() { |
| 836 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") |
| 837 | |
| 838 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), |
| 839 | "check_api.last_released.api_file") |
| 840 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), |
| 841 | "check_api.last_released.removed_api_file") |
| 842 | |
| 843 | ctx.Build(pctx, android.BuildParams{ |
| 844 | Rule: apiCheck, |
| 845 | Description: "Last Released API check", |
| 846 | Output: d.checkLastReleasedApiTimestamp, |
| 847 | Inputs: nil, |
| 848 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 849 | checkApiClasspath...), |
| 850 | Args: map[string]string{ |
| 851 | "classpath": checkApiClasspath.FormJavaClassPath(""), |
| 852 | "opts": String(d.properties.Check_api.Last_released.Args), |
| 853 | "apiFile": apiFile.String(), |
| 854 | "apiFileToCheck": d.apiFile.String(), |
| 855 | "removedApiFile": removedApiFile.String(), |
| 856 | "removedApiFileToCheck": d.removedApiFile.String(), |
| 857 | "msg": `\n******************************\n` + |
| 858 | `You have tried to change the API from what has been previously released in\n` + |
| 859 | `an SDK. Please fix the errors listed above.\n` + |
| 860 | `******************************\n`, |
| 861 | }, |
| 862 | }) |
| 863 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 864 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 865 | |
| 866 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
| 867 | |
| 868 | type DroiddocTemplateProperties struct { |
| 869 | // path to the directory containing the droiddoc templates. |
| 870 | Path *string |
| 871 | } |
| 872 | |
| 873 | type DroiddocTemplate struct { |
| 874 | android.ModuleBase |
| 875 | |
| 876 | properties DroiddocTemplateProperties |
| 877 | |
| 878 | deps android.Paths |
| 879 | dir android.Path |
| 880 | } |
| 881 | |
| 882 | func DroiddocTemplateFactory() android.Module { |
| 883 | module := &DroiddocTemplate{} |
| 884 | module.AddProperties(&module.properties) |
| 885 | android.InitAndroidModule(module) |
| 886 | return module |
| 887 | } |
| 888 | |
| 889 | func (d *DroiddocTemplate) DepsMutator(android.BottomUpMutatorContext) {} |
| 890 | |
| 891 | func (d *DroiddocTemplate) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 892 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) |
| 893 | d.dir = path |
| 894 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) |
| 895 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 896 | |
| 897 | // |
| 898 | // Defaults |
| 899 | // |
| 900 | type DocDefaults struct { |
| 901 | android.ModuleBase |
| 902 | android.DefaultsModuleBase |
| 903 | } |
| 904 | |
| 905 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 906 | } |
| 907 | |
| 908 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 909 | } |
| 910 | |
| 911 | func DocDefaultsFactory() android.Module { |
| 912 | module := &DocDefaults{} |
| 913 | |
| 914 | module.AddProperties( |
| 915 | &JavadocProperties{}, |
| 916 | &DroiddocProperties{}, |
| 917 | ) |
| 918 | |
| 919 | android.InitDefaultsModule(module) |
| 920 | |
| 921 | return module |
| 922 | } |